ReactOS 0.4.15-dev-5667-ged97270
startup.c File Reference
#include <ws2_32.h>
#include <debug.h>
Include dependency graph for startup.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define WsStartupLock()   EnterCriticalSection(&WsStartupLock)
 
#define WsStartupUnlock()   LeaveCriticalSection(&WsStartupLock)
 

Functions

VOID WSAAPI WsCreateStartupSynchronization (VOID)
 
VOID WSAAPI WsDestroyStartupSynchronization (VOID)
 
BOOL WSAAPI WSApSetPostRoutine (PVOID Routine)
 
INT WSAAPI WSACleanup (VOID)
 
INT WINAPI WSAStartup (IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
 

Variables

PWS_SOCK_POST_ROUTINE WsSockPostRoutine = NULL
 
CRITICAL_SECTION WsStartupLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file startup.c.

◆ WsStartupLock

#define WsStartupLock ( )    EnterCriticalSection(&WsStartupLock)

Definition at line 21 of file startup.c.

◆ WsStartupUnlock

#define WsStartupUnlock ( )    LeaveCriticalSection(&WsStartupLock)

Definition at line 22 of file startup.c.

Function Documentation

◆ WSACleanup()

INT WSAAPI WSACleanup ( VOID  )

Definition at line 60 of file startup.c.

61{
65 LONG RefCount;
66 DPRINT("WSACleanup\n");
67
68 /* Enter startup lock */
70
71 /* Enter prolog */
73 {
74 /* Decrement process reference count and check if it's zero */
75 if (!(RefCount = InterlockedDecrement(&Process->RefCount)))
76 {
77 /* It's zero, destroy the process structure */
79 }
80 else if (RefCount == 1 && WsAsyncThreadInitialized)
81 {
82 /* Kill async thread */
84 }
85
86 DPRINT("WSACleanup RefCount = %ld\n", RefCount);
87 /* Return success */
89
90 /* Clear last error */
92 }
93 else
94 {
95 DPRINT("WSACleanup uninitialized\n");
96 /* Weren't initialized */
99 }
100
101 /* Release startup lock */
103
104 /* Done */
105 return ErrorCode;
106}
#define InterlockedDecrement
Definition: armddk.h:52
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SetLastError(x)
Definition: compat.h:752
#define WsStartupLock()
Definition: startup.c:21
#define WsStartupUnlock()
Definition: startup.c:22
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
long LONG
Definition: pedump.c:60
#define DPRINT
Definition: sndvol32.h:71
int32_t INT
Definition: typedefs.h:58
#define SOCKET_ERROR
Definition: winsock.h:333
VOID WSAAPI WsAsyncTerminateThread(VOID)
Definition: async.c:899
VOID WSAAPI WsProcDelete(IN PWSPROCESS Process)
Definition: dprocess.c:247
BOOLEAN WsAsyncThreadInitialized
Definition: async.c:15
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91

Referenced by AdapterStop(), adns_finish(), Cleanup(), cleanup(), close_http(), closelog(), CreateServers(), CreateSocket(), DeinitWinsock(), DestroyConnection(), ErrorExit(), Exit(), inet_ntoa(), init_abort(), init_begin(), init_finish(), InitWinsock(), InternetTransport_UnregisterClass(), kickoff_telnetd(), main(), NETCON_unload(), netconn_unload(), open_http(), openlog(), read_line(), runProg(), service_main(), ServiceMain(), SocketTest(), START_TEST(), Test_ioctlsocket(), Test_recv(), test_WithWSAStartup(), Test_WSAIoctl_GetInterfaceList(), Test_WSARecv(), tirpc_exit(), userlist(), winsock_fini(), winsock_init(), wmain(), WsAsyncCheckAndInitThread(), WsAsyncThread(), wWinMain(), and Telnet::~Telnet().

◆ WSApSetPostRoutine()

BOOL WSAAPI WSApSetPostRoutine ( PVOID  Routine)

Definition at line 47 of file startup.c.

48{
49 /* Set the post routine */
50 DPRINT("WSApSetPostRoutine: %p\n", Routine);
52 return ERROR_SUCCESS;
53}
PWS_SOCK_POST_ROUTINE WsSockPostRoutine
Definition: startup.c:18
BOOL(WINAPI * PWS_SOCK_POST_ROUTINE)(IN HWND hWnd, IN UINT wMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: ws2_32p.h:265

◆ WSAStartup()

INT WINAPI WSAStartup ( IN WORD  wVersionRequested,
OUT LPWSADATA  lpWSAData 
)

Definition at line 113 of file startup.c.

115{
116 WORD VersionReturned = 0;
118 PWSPROCESS CurrentProcess;
119 DPRINT("WSAStartup: %wx %d.%d\n", wVersionRequested, LOBYTE(wVersionRequested), HIBYTE(wVersionRequested));
120
121 /* Make sure that we went through DLL Init */
122 if (!WsDllHandle) return WSASYSNOTREADY;
123
124 /* Check which version is being requested */
125 switch (LOBYTE(wVersionRequested))
126 {
127 case 0:
128
129 /* We don't support this unknown version */
131 VersionReturned = MAKEWORD(2, 2);
132 break;
133
134 case 1:
135 /* We support only 1.0 and 1.1 */
136 if (HIBYTE(wVersionRequested) <= 1)
137 {
138 /* Caller wants 1.0, return it */
139 VersionReturned = MAKEWORD(1, HIBYTE(wVersionRequested));
140 }
141 else
142 {
143 /* The only other version we support is 1.1 */
144 VersionReturned = MAKEWORD(1, 1);
145 }
146 break;
147
148 case 2:
149 /* We support only 2.0, 2.1 and 2.2 */
150 if (HIBYTE(wVersionRequested) <= 2)
151 {
152 /* Caller wants 2.0-2.2, return it */
153 VersionReturned = MAKEWORD(2, HIBYTE(wVersionRequested));
154 }
155 else
156 {
157 /* The highest version we support is 2.2 */
158 VersionReturned = MAKEWORD(2, 2);
159 }
160 break;
161
162 default:
163
164 /* Return 2.2 */
165 VersionReturned = MAKEWORD(2, 2);
166 break;
167 }
168
169 if (lpWSAData == NULL)
170 {
173 }
174
175 /* Return the Version Requested, unless error */
176 lpWSAData->wVersion = VersionReturned;
177
178 /* We support Winsock 2.2 */
179 lpWSAData->wHighVersion = MAKEWORD(2,2);
180 lstrcpy(lpWSAData->szDescription, "WinSock 2.0");
181 lstrcpy(lpWSAData->szSystemStatus, "Running");
182
183 /*
184 * On Winsock 1, the following values are returned.
185 * Taken straight from a Winsock Test app on Windows.
186 */
187 if (LOBYTE(wVersionRequested) == 1)
188 {
189 lpWSAData->iMaxSockets = 32767;
190 lpWSAData->iMaxUdpDg = 65467;
191 }
192 else
193 {
194 lpWSAData->iMaxSockets = 0;
195 lpWSAData->iMaxUdpDg = 0;
196 }
197
198 /* Requested invalid version (0) */
200 {
202 return ErrorCode;
203 }
204
205 /* Enter the startup synchronization lock */
207
208 /* Now setup all our objects */
209 while (TRUE)
210 {
211 /* Make sure we don't already have a process */
212 CurrentProcess = WsGetProcess();
213 if (CurrentProcess) break;
214
215 /* Setup the process object support */
217 if (ErrorCode != ERROR_SUCCESS) break;
218
219 /* Setup the process object support */
221 if (ErrorCode != ERROR_SUCCESS) break;
222
223 /* Setup the process object support */
225 if (ErrorCode != ERROR_SUCCESS) break;
226
227 /* Try getting the process now */
228 CurrentProcess = WsGetProcess();
229 if (!CurrentProcess)
230 {
231 /* Something is weird... */
233 break;
234 }
235 }
236
237 /* Check if all worked */
239 {
240 /* Set the requested version */
241 WsProcSetVersion(CurrentProcess, wVersionRequested);
242
243 /* Increase the reference count */
244 InterlockedIncrement(&CurrentProcess->RefCount);
245 DPRINT("WSAStartup RefCount = %ld\n", CurrentProcess->RefCount);
246
247 /* Clear last error */
249 }
250 else
251 {
253 }
254
255 /* Leave the startup lock */
257
258 /* Return any Error */
259 return ErrorCode;
260}
#define InterlockedIncrement
Definition: armddk.h:53
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
LONG RefCount
Definition: ws2_32p.h:162
#define MAKEWORD(a, b)
Definition: typedefs.h:248
#define lstrcpy
Definition: winbase.h:3745
#define WSANOTINITIALISED
Definition: winerror.h:1987
#define WSASYSNOTREADY
Definition: winerror.h:1985
#define WSAVERNOTSUPPORTED
Definition: winerror.h:1986
#define WSAEFAULT
Definition: winerror.h:1945
INT WSAAPI WsSockStartup(VOID)
Definition: dsocket.c:21
DWORD WSAAPI WsThreadStartup(VOID)
Definition: dthread.c:153
FORCEINLINE PWSPROCESS WsGetProcess(VOID)
Definition: ws2_32p.h:885
INT WSAAPI WsProcStartup(VOID)
Definition: dprocess.c:126
HINSTANCE WsDllHandle
Definition: dllmain.c:22
VOID WSAAPI WsProcSetVersion(IN PWSPROCESS Process, IN WORD VersionRequested)
Definition: dprocess.c:312

Referenced by AcceptProc(), AdapterInit(), CreateServers(), Telnet::DoInit(), inet_ntoa(), init(), Init(), init_begin(), InitConnection(), InitWinsock(), InternetTransport_RegisterClass(), main(), open_http(), openlog(), PreInit(), rpcrt4_ip_tcp_get_top_of_tower(), rpcrt4_protseq_sock_alloc(), rpcrt4_sock_wait_init(), server_thread(), service_main(), Setup(), SocketTest(), START_TEST(), StartSocketInterface(), test_communication(), Test_ioctlsocket(), Test_recv(), test_WithWSAStartup(), Test_WSAIoctl_GetInterfaceList(), Test_WSARecv(), userlist(), winsock_init(), winsock_startup(), wmain(), WsAsyncCheckAndInitThread(), and wWinMain().

◆ WsCreateStartupSynchronization()

VOID WSAAPI WsCreateStartupSynchronization ( VOID  )

Definition at line 28 of file startup.c.

29{
30 /* Initialize the startup lock */
32}
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

Referenced by DllMain().

◆ WsDestroyStartupSynchronization()

VOID WSAAPI WsDestroyStartupSynchronization ( VOID  )

Definition at line 36 of file startup.c.

37{
38 /* Destroy the startup lock */
40}
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by DllMain().

Variable Documentation

◆ WsSockPostRoutine

PWS_SOCK_POST_ROUTINE WsSockPostRoutine = NULL

Definition at line 18 of file startup.c.

Referenced by WPUPostMessage(), and WSApSetPostRoutine().

◆ WsStartupLock

CRITICAL_SECTION WsStartupLock

Definition at line 19 of file startup.c.