ReactOS  0.4.14-dev-317-g96040ec
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 TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOLEAN ApiSocket
Definition: ws2_32p.h:202
_In_ HANDLE Handle
Definition: extypes.h:390
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
PWSSOCKET WSAAPI WsSockGetSocketNoExport(IN SOCKET Handle)
Definition: dsocket.c:92

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 TRUE
Definition: types.h:120
BOOLEAN Overlapped
Definition: ws2_32p.h:201
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG RefCount
Definition: ws2_32p.h:196
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
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 }
BOOLEAN IsProvider
Definition: ws2_32p.h:203
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
int32_t INT
Definition: typedefs.h:56
PWAH_HANDLE WINAPI WahInsertHandleContext(IN PWAH_HANDLE_TABLE Table, IN PWAH_HANDLE Handle)
Definition: context.c:336
_In_ HANDLE Handle
Definition: extypes.h:390
PVOID HANDLE
Definition: typedefs.h:71
VOID WSAAPI WsSockDereference(IN PWSSOCKET Socket)
Definition: dsocket.c:205
struct _WSSOCKET * PWSSOCKET
#define WSAENOBUFS
Definition: winerror.h:1968

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 }
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
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 }
smooth NULL
Definition: ftsmooth.c:416
VOID WSAAPI WsTcEntryDereference(IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatitem.c:51
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:394

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
_In_ HANDLE Handle
Definition: extypes.h:390

Referenced by WsProcDelete().

◆ WsSockDereference()

VOID WSAAPI WsSockDereference ( IN PWSSOCKET  Socket)

◆ WsSockDisassociateHandle()

INT WSAAPI WsSockDisassociateHandle ( IN PWSSOCKET  Socket)

Definition at line 217 of file dsocket.c.

218 {
219  /* Remove it from the list */
221 }
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
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 {
103  INT ErrorCode;
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 */
123  if (ErrorCode == ERROR_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 }
#define TRUE
Definition: types.h:120
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOLEAN ApiSocket
Definition: ws2_32p.h:202
DWORD WSAAPI WsTcFindIfsProviderForSocket(IN PTCATALOG TCatalog, SOCKET Socket)
int32_t INT
Definition: typedefs.h:56
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PWSPROCESS WsGetProcess(VOID)
Definition: ws2_32p.h:885
_In_ HANDLE Handle
Definition: extypes.h:390
#define INVALID_SOCKET
Definition: winsock.h:332
unsigned long DWORD
Definition: ntddk_ex.h:95
PWSSOCKET WSAAPI WsSockGetSocketNoExport(IN SOCKET Handle)
Definition: dsocket.c:92
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
BOOL WINAPI GetHandleInformation(IN HANDLE hObject, OUT LPDWORD lpdwFlags)
Definition: handle.c:40
PTCATALOG WSAAPI WsProcGetTCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:150

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 */
146  (HANDLE)Handle)))
147  {
148  return Socket;
149  }
150  else
151  {
152  /* WAH didn't find it, use IFS */
153  return WsSockFindIfsSocket(Handle);
154  }
155 }
PWSSOCKET WSAAPI WsSockFindIfsSocket(IN SOCKET Handle)
Definition: dsocket.c:101
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
_In_ HANDLE Handle
Definition: extypes.h:390
PWAH_HANDLE WINAPI WahReferenceContextByHandle(IN PWAH_HANDLE_TABLE Table, IN HANDLE Handle)
Definition: context.c:524

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 }
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
_In_ HANDLE Handle
Definition: extypes.h:390
PWAH_HANDLE WINAPI WahReferenceContextByHandle(IN PWAH_HANDLE_TABLE Table, IN HANDLE Handle)
Definition: context.c:524

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 ERROR_SUCCESS
Definition: deptool.c:10
DWORD OpenType
Definition: ws2_32p.h:190
#define TlsIndex
Definition: ws2_32p.h:277
#define InterlockedIncrement
Definition: armddk.h:53
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1228

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 */
24  if (!WsSockHandleTable)
25  {
26  /* Create it */
28  }
29 
30  /* Nothing to do */
31  return NO_ERROR;
32 }
PWAH_HANDLE_TABLE WsSockHandleTable
Definition: dsocket.c:15
#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