ReactOS 0.4.16-dev-320-g3bd9ddc
dsocket.c File Reference
#include <ws2_32.h>
Include dependency graph for dsocket.c:

Go to the source code of this file.

Functions

INT WSAAPI WsSockStartup (VOID)
 
VOID WSPAPI WsSockCleanup (VOID)
 
PWSSOCKET WSAAPI WsSockAllocate (VOID)
 
INT WSAAPI WsSockInitialize (IN PWSSOCKET Socket, IN PTCATALOG_ENTRY CatalogEntry)
 
PWSSOCKET WSAAPI WsSockGetSocketNoExport (IN SOCKET Handle)
 
PWSSOCKET WSAAPI WsSockFindIfsSocket (IN SOCKET Handle)
 
PWSSOCKET WSAAPI WsSockGetSocket (IN SOCKET Handle)
 
INT WSAAPI WsSockAddApiReference (IN SOCKET Handle)
 
BOOL WSAAPI WsSockDeleteSockets (IN LPVOID Context, IN PWAH_HANDLE Handle)
 
VOID WSAAPI WsSockDelete (IN PWSSOCKET Socket)
 
VOID WSAAPI WsSockDereference (IN PWSSOCKET Socket)
 
INT WSAAPI WsSockDisassociateHandle (IN PWSSOCKET Socket)
 
INT WSAAPI WsSockAssociateHandle (IN PWSSOCKET Socket, IN SOCKET Handle, IN BOOLEAN IsProvider)
 

Variables

PWAH_HANDLE_TABLE WsSockHandleTable
 

Function Documentation

◆ WsSockAddApiReference()

INT WSAAPI WsSockAddApiReference ( IN SOCKET  Handle)

Definition at line 159 of file dsocket.c.

160{
161 PWSSOCKET Socket;
162
163 /* Get the Socket now */
164 if ((Socket = WsSockGetSocketNoExport(Handle)))
165 {
166 /* Mark it as an API Socket */
167 if (Socket) Socket->ApiSocket = TRUE;
168
169 /* Remove a reference and return */
170 WsSockDereference(Socket);
171 return ERROR_SUCCESS;
172 }
173
174 /* Return error */
175 return WSASYSCALLFAILURE;
176}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
PWSSOCKET WSAAPI WsSockGetSocketNoExport(IN SOCKET Handle)
Definition: dsocket.c:92
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
ULONG Handle
Definition: gdb_input.c:15
BOOLEAN ApiSocket
Definition: ws2_32p.h:202
#define WSASYSCALLFAILURE
Definition: winerror.h:1994

Referenced by WSAAccept(), WSAJoinLeaf(), and WSASocketW().

◆ WsSockAllocate()

PWSSOCKET WSAAPI WsSockAllocate ( VOID  )

Definition at line 48 of file dsocket.c.

49{
50 PWSSOCKET Socket;
51
52 /* Allocate the socket object */
53 Socket = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Socket));
54 if (Socket)
55 {
56 /* Setup default non-zero values */
57 Socket->RefCount = 2;
58 Socket->Overlapped = TRUE;
59 }
60
61 /* Return it */
62 return Socket;
63}
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
LONG RefCount
Definition: ws2_32p.h:196
BOOLEAN Overlapped
Definition: ws2_32p.h:201
HANDLE WsSockHeap
Definition: dllmain.c:21

Referenced by WPUModifyIFSHandle().

◆ WsSockAssociateHandle()

INT WSAAPI WsSockAssociateHandle ( IN PWSSOCKET  Socket,
IN SOCKET  Handle,
IN BOOLEAN  IsProvider 
)

Definition at line 225 of file dsocket.c.

228{
230 PWSSOCKET OldSocket;
231
232 /* Save the socket and provider */
233 Socket->IsProvider = IsProvider;
234 Socket->Handle = (HANDLE)Handle;
235
236 /* Insert it into the handle table */
238 (PWAH_HANDLE)Socket);
239
240 /* Check if a socket already existed */
241 if (OldSocket != Socket)
242 {
243 /* We'll dereference it */
244 WsSockDereference(OldSocket);
245 }
246 else if (!OldSocket)
247 {
248 /* No memory to allocate it */
250 }
251
252 /* Return */
253 return ErrorCode;
254}
PWAH_HANDLE WINAPI WahInsertHandleContext(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
Definition: context.c:336
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
BOOLEAN IsProvider
Definition: ws2_32p.h:203
PVOID HANDLE
Definition: typedefs.h:73
int32_t INT
Definition: typedefs.h:58
#define WSAENOBUFS
Definition: winerror.h:1968
struct _WSSOCKET * PWSSOCKET

Referenced by WPUModifyIFSHandle().

◆ WsSockCleanup()

VOID WSPAPI WsSockCleanup ( VOID  )

Definition at line 36 of file dsocket.c.

37{
38 /* Check if we have a socket table */
40 {
41 /* Destroy it */
43 }
44}
DWORD WINAPI WahDestroyHandleContextTable(IN PWAH_HANDLE_TABLE Table)
Definition: context.c:246

Referenced by DllMain().

◆ WsSockDelete()

VOID WSAAPI WsSockDelete ( IN PWSSOCKET  Socket)

Definition at line 189 of file dsocket.c.

190{
191 /* Check if we have a catalog entry */
192 if (Socket->CatalogEntry)
193 {
194 /* Dereference it */
195 WsTcEntryDereference(Socket->CatalogEntry);
196 Socket->CatalogEntry = NULL;
197 }
198
199 /* Delete us */
200 HeapFree(WsSockHeap, 0, Socket);
201}
#define NULL
Definition: types.h:112
#define HeapFree(x, y, z)
Definition: compat.h:735
VOID WSAAPI WsTcEntryDereference(IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatitem.c:51

Referenced by WsSockDereference().

◆ WsSockDeleteSockets()

BOOL WSAAPI WsSockDeleteSockets ( IN LPVOID  Context,
IN PWAH_HANDLE  Handle 
)

Definition at line 180 of file dsocket.c.

182{
183 /* Call the detach routine */
185}
BOOL WSAAPI WsProcDetachSocket(IN PWSPROCESS Process, IN PWAH_HANDLE Handle)
Definition: dprocess.c:182

Referenced by WsProcDelete().

◆ WsSockDereference()

◆ WsSockDisassociateHandle()

INT WSAAPI WsSockDisassociateHandle ( IN PWSSOCKET  Socket)

Definition at line 217 of file dsocket.c.

218{
219 /* Remove it from the list */
221}
DWORD WINAPI WahRemoveHandleContext(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
Definition: context.c:564

Referenced by closesocket().

◆ WsSockFindIfsSocket()

PWSSOCKET WSAAPI WsSockFindIfsSocket ( IN SOCKET  Handle)

Definition at line 101 of file dsocket.c.

102{
104 DWORD Flags;
105 PWSSOCKET Socket = NULL;
107 PTCATALOG Catalog = NULL;
108
109 /* Validate the socket and get handle info */
110 if ((Handle != INVALID_SOCKET) &&
112 {
113 /* Get the process */
114 if ((Process = WsGetProcess()))
115 {
116 /* Get the catalog */
117 Catalog = WsProcGetTCatalog(Process);
118
119 /* Get the IFS Provider */
121
122 /* Check for success */
124 {
125 /* Get the Socket now */
127
128 /* Mark it as an API Socket */
129 if (Socket) Socket->ApiSocket = TRUE;
130 }
131 }
132 }
133
134 /* Return the socket */
135 return Socket;
136}
BOOL WINAPI GetHandleInformation(IN HANDLE hObject, OUT LPDWORD lpdwFlags)
Definition: handle.c:40
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define INVALID_SOCKET
Definition: winsock.h:332
FORCEINLINE PWSPROCESS WsGetProcess(VOID)
Definition: ws2_32p.h:885
PTCATALOG WSAAPI WsProcGetTCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:150
DWORD WSAAPI WsTcFindIfsProviderForSocket(IN PTCATALOG TCatalog, SOCKET Socket)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by WsSockGetSocket().

◆ WsSockGetSocket()

PWSSOCKET WSAAPI WsSockGetSocket ( IN SOCKET  Handle)

Definition at line 140 of file dsocket.c.

141{
142 PWSSOCKET Socket;
143
144 /* Let WAH do the translation */
145 if ((WsSockHandleTable != NULL) &&
147 {
148 return Socket;
149 }
150 else
151 {
152 /* WAH didn't find it, use IFS */
154 }
155}
PWAH_HANDLE WINAPI WahReferenceContextByHandle(IN PWAH_HANDLE_TABLE Table, IN HANDLE Handle)
Definition: context.c:524
PWSSOCKET WSAAPI WsSockFindIfsSocket(IN SOCKET Handle)
Definition: dsocket.c:101

Referenced by bind(), closesocket(), connect(), getpeername(), getsockname(), getsockopt(), listen(), recv(), recvfrom(), select(), send(), sendto(), setsockopt(), shutdown(), WSAAccept(), WSAAsyncSelect(), WSAConnect(), WSADuplicateSocketW(), WSAEnumNetworkEvents(), WSAEventSelect(), WSAGetOverlappedResult(), WSAGetQOSByName(), WSAHtonl(), WSAHtons(), WSAIoctl(), WSAJoinLeaf(), WSANtohl(), WSANtohs(), WSARecv(), WSARecvDisconnect(), WSARecvFrom(), WSASend(), WSASendDisconnect(), and WSASendTo().

◆ WsSockGetSocketNoExport()

PWSSOCKET WSAAPI WsSockGetSocketNoExport ( IN SOCKET  Handle)

Definition at line 92 of file dsocket.c.

93{
94 /* Let WAH do the translation */
96 (HANDLE)Handle);
97}

Referenced by WsSockAddApiReference(), and WsSockFindIfsSocket().

◆ WsSockInitialize()

INT WSAAPI WsSockInitialize ( IN PWSSOCKET  Socket,
IN PTCATALOG_ENTRY  CatalogEntry 
)

Definition at line 67 of file dsocket.c.

69{
70 PWSTHREAD CurrentThread;
71
72 /* Associate this catalog and reference it */
73 Socket->CatalogEntry = CatalogEntry;
74 InterlockedIncrement(&CatalogEntry->RefCount);
75
76 /* Associate the Provider and Process Objects */
77 Socket->Provider = CatalogEntry->Provider;
78
79 /* Get the current Thread Object */
80 if ((CurrentThread = TlsGetValue(TlsIndex)))
81 {
82 /* Set the overlapped mode */
83 Socket->Overlapped = (CurrentThread->OpenType == 0);
84 }
85
86 /* Return status */
87 return ERROR_SUCCESS;
88}
#define InterlockedIncrement
Definition: armddk.h:53
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240
DWORD OpenType
Definition: ws2_32p.h:190
#define TlsIndex
Definition: ws2_32p.h:277

Referenced by WPUModifyIFSHandle().

◆ WsSockStartup()

INT WSAAPI WsSockStartup ( VOID  )

Definition at line 21 of file dsocket.c.

22{
23 /* Check if we have a socket table */
25 {
26 /* Create it */
28 }
29
30 /* Nothing to do */
31 return NO_ERROR;
32}
#define NO_ERROR
Definition: dderror.h:5
DWORD WINAPI WahCreateHandleContextTable(OUT PWAH_HANDLE_TABLE *Table)
Definition: context.c:189

Referenced by WSAStartup().

Variable Documentation

◆ WsSockHandleTable