Changeset 108818 in vbox
- Timestamp:
- Apr 1, 2025 9:09:35 PM (2 weeks ago)
- svn:sync-xref-src-repo-rev:
- 168264
- Location:
- trunk/src/libs/libslirp-4.8.0/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/libslirp-4.8.0/src/nathandletable.c
r108816 r108818 1 /* $Id$ */ 1 2 /** @file 2 * libslirp: NAT Han lde Table Wrapper3 * libslirp: NAT Handle Table Wrapper 3 4 */ 4 5 … … 38 39 #include "nathandletable.h" 39 40 40 PRTHANDLETABLE pNATHandleTable = NULL;41 RTHANDLETABLE g_hNATHandleTable = NIL_RTHANDLETABLE; 41 42 43 /** 44 * Returns the windows SOCKET for file descriptor @a fd (aka handle). 45 * 46 * @returns Windows socket handle. NULL if @a fd is invalid. 47 */ 42 48 SOCKET libslirp_wrap_RTHandleTableLookup(int fd) 43 49 { 44 if (pNATHandleTable == NULL) 50 RTHANDLETABLE const hHandleTable = g_hNATHandleTable; 51 SOCKET hSock = (SOCKET)RTHandleTableLookup(hHandleTable, fd); 52 Log6Func(("Looked up %d in %p and returned %d\n", fd, hHandleTable, hSock)); 53 return hSock; 54 } 55 56 /** 57 * Allocates a file descriptor (handle) for windows SOCKET @a hSock. 58 * @returns IPRT status code. 59 */ 60 int libslirp_wrap_RTHandleTableAlloc(SOCKET hSock, uint32_t *pHandle) 61 { 62 /* Lazy create the handle table (leaked): */ 63 RTHANDLETABLE hHandleTable = g_hNATHandleTable; 64 if (RT_LIKELY(hHandleTable != NIL_RTHANDLETABLE)) 65 { /* likely*/ } 66 else 45 67 { 46 pNATHandleTable = RTMemAlloc(sizeof(RTHANDLETABLE)); 47 int rc = RTHandleTableCreate(pNATHandleTable); 48 AssertRC(rc); 68 int rc = RTHandleTableCreate(&hHandleTable); 69 AssertLogRelRCReturn(rc, -1); 70 /** @todo potential race here? iff so, use cmpxchg from asm.h */ 71 g_hNATHandleTable = hHandleTable; 49 72 } 50 73 51 SOCKET s = (SOCKET)RTHandleTableLookup(*pNATHandleTable, fd);52 Log6Func((" Looked up %d on %p and returned %d\n", fd, (void *)pNATHandleTable, s));53 return s;74 int rc = RTHandleTableAlloc(hHandleTable, (void *)hSock, pHandle); 75 Log6Func(("Creating sock %p in %p with handle %d\n", hSock, hHandleTable, *pHandle)); 76 return rc; 54 77 } 55 78 56 int libslirp_wrap_RTHandleTableAlloc(SOCKET uSocket, uint32_t *pHandle) 57 { 58 if (pNATHandleTable == NULL) 59 { 60 pNATHandleTable = RTMemAlloc(sizeof(RTHANDLETABLE)); 61 int rc = RTHandleTableCreate(pNATHandleTable); 62 AssertRC(rc); 63 } 64 65 int ret = RTHandleTableAlloc(*pNATHandleTable, (void *)uSocket, pHandle); 66 Log6Func(("Creating sock %llu on %p with handle %d\n", uSocket, (void *)pNATHandleTable, *pHandle)); 67 return ret; 68 } 69 79 /** 80 * Frees file descriptor (handle) @a fd after the associated socket has been 81 * closed. 82 * 83 * @returns IPRT status code. (Shouldn't fail unless there are multiple 84 * concurrent closesocket calls.) 85 */ 70 86 int libslirp_wrap_RTHandleTableFree(int fd) 71 87 { 72 if (pNATHandleTable == NULL)73 return VERR_INVALID_PARAMETER;88 RTHANDLETABLE const hHandleTable = g_hNATHandleTable; 89 AssertReturn(hHandleTable != NIL_RTHANDLETABLE, VERR_INVALID_PARAMETER); 74 90 75 void * ret = RTHandleTableFree(*pNATHandleTable, fd);76 Log6Func(("Free ing sock %d on %p\n", fd, (void *)pNATHandleTable));77 if ( ret)91 void * const pvObsoleteSocket = RTHandleTableFree(hHandleTable, fd); 92 Log6Func(("Freed handle %d (sock %p) from %p\n", fd, pvObsoleteSocket, hHandleTable)); 93 if (pvObsoleteSocket) 78 94 return VINF_SUCCESS; 79 95 -
trunk/src/libs/libslirp-4.8.0/src/nathandletable.h
r108816 r108818 1 /* $Id$ */ 1 2 /** @file 2 * libslirp: NAT Han lde Table Singleton Wrapper3 * libslirp: NAT Handle Table Singleton Wrapper 3 4 */ 4 5 … … 34 35 */ 35 36 36 #ifdef _WIN3237 37 #ifndef INCLUDED_nathandletable_h 38 #define INCLUDED_nathandletable_h 38 39 #ifndef RT_WITHOUT_PRAGMA_ONCE 39 40 # pragma once 40 41 #endif 41 42 42 #include <iprt/assert.h> 43 #include <iprt/err.h> 44 #include <iprt/handletable.h> 45 #include <iprt/mem.h> 43 #ifdef _WIN32 44 # include <iprt/assert.h> 45 # include <iprt/err.h> 46 # include <iprt/handletable.h> 47 # include <iprt/mem.h> 46 48 47 49 # ifndef LOG_GROUP … … 50 52 # endif 51 53 52 # include <winsock2.h>54 # include <winsock2.h> 53 55 54 #ifdef __cplusplus 55 extern "C" 56 { 57 #endif 56 RT_C_DECLS_BEGIN 58 57 59 extern PRTHANDLETABLE pNATHandleTable;58 extern RTHANDLETABLE g_hNATHandleTable; 60 59 61 60 /** … … 85 84 int libslirp_wrap_RTHandleTableFree(int fd); 86 85 87 #ifdef __cplusplus 88 } 89 # endif86 RT_C_DECLS_END 87 88 # endif /* _WIN32*/ 90 89 91 90 #endif 92 #endif
Note:
See TracChangeset
for help on using the changeset viewer.