ReactOS  0.4.15-dev-1070-ge1a01de
msafd.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <ws2spi.h>
#include <ndk/exfuncs.h>
#include <ndk/iofuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/rtlfuncs.h>
#include <wsahelp.h>
#include <tdi.h>
#include <afd/shared.h>
#include <mswsock.h>
#include <wine/debug.h>
#include "include/helpers.h"
Include dependency graph for msafd.h:

Go to the source code of this file.

Classes

struct  _SOCK_SHARED_INFO
 
struct  _SOCKET_INFORMATION
 
struct  _SOCKET_CONTEXT
 
struct  _ASYNC_DATA
 
struct  _AFDAPCCONTEXT
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define NTOS_MODE_USER
 

Typedefs

typedef enum _SOCKET_STATE SOCKET_STATE
 
typedef enum _SOCKET_STATEPSOCKET_STATE
 
typedef struct _SOCK_SHARED_INFO SOCK_SHARED_INFO
 
typedef struct _SOCK_SHARED_INFOPSOCK_SHARED_INFO
 
typedef struct _SOCKET_INFORMATION SOCKET_INFORMATION
 
typedef struct _SOCKET_INFORMATIONPSOCKET_INFORMATION
 
typedef struct _SOCKET_CONTEXT SOCKET_CONTEXT
 
typedef struct _SOCKET_CONTEXTPSOCKET_CONTEXT
 
typedef struct _ASYNC_DATA ASYNC_DATA
 
typedef struct _ASYNC_DATAPASYNC_DATA
 
typedef struct _AFDAPCCONTEXT AFDAPCCONTEXT
 
typedef struct _AFDAPCCONTEXTPAFDAPCCONTEXT
 
typedef VOID(* PASYNC_COMPLETION_ROUTINE) (PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
 

Enumerations

enum  _SOCKET_STATE {
  SocketOpen, SocketBound, SocketBoundUdp, SocketConnected,
  SocketClosed, SocketStateCreated, SocketStateBound, SocketStateListening,
  SocketStateConnected, SocketUndefined = -1, SocketOpen, SocketBound,
  SocketBoundUdp, SocketConnected, SocketClosed
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msafd)
 
_Must_inspect_result_ SOCKET WSPAPI WSPAccept (_In_ SOCKET s, _Out_writes_bytes_to_opt_(*addrlen, *addrlen) struct sockaddr FAR *addr, _Inout_opt_ LPINT addrlen, _In_opt_ LPCONDITIONPROC lpfnCondition, _In_opt_ DWORD_PTR dwCallbackData, _Out_ LPINT lpErrno)
 
INT WSPAPI WSPAddressToString (IN LPSOCKADDR lpsaAddress, IN DWORD dwAddressLength, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, OUT LPWSTR lpszAddressString, IN OUT LPDWORD lpdwAddressStringLength, OUT LPINT lpErrno)
 
INT WSPAPI WSPAsyncSelect (IN SOCKET s, IN HWND hWnd, IN UINT wMsg, IN LONG lEvent, OUT LPINT lpErrno)
 
INT WSPAPI WSPBind (IN SOCKET s, IN CONST SOCKADDR *name, IN INT namelen, OUT LPINT lpErrno)
 
INT WSPAPI WSPCancelBlockingCall (OUT LPINT lpErrno)
 
INT WSPAPI WSPCleanup (OUT LPINT lpErrno)
 
INT WSPAPI WSPCloseSocket (IN SOCKET s, OUT LPINT lpErrno)
 
INT WSPAPI WSPConnect (IN SOCKET s, IN CONST SOCKADDR *name, IN INT namelen, IN LPWSABUF lpCallerData, OUT LPWSABUF lpCalleeData, IN LPQOS lpSQOS, IN LPQOS lpGQOS, OUT LPINT lpErrno)
 
INT WSPAPI WSPDuplicateSocket (IN SOCKET s, IN DWORD dwProcessId, OUT LPWSAPROTOCOL_INFOW lpProtocolInfo, OUT LPINT lpErrno)
 
INT WSPAPI WSPEnumNetworkEvents (IN SOCKET s, IN WSAEVENT hEventObject, OUT LPWSANETWORKEVENTS lpNetworkEvents, OUT LPINT lpErrno)
 
INT WSPAPI WSPEventSelect (IN SOCKET s, IN WSAEVENT hEventObject, IN LONG lNetworkEvents, OUT LPINT lpErrno)
 
BOOL WSPAPI WSPGetOverlappedResult (IN SOCKET s, IN LPWSAOVERLAPPED lpOverlapped, OUT LPDWORD lpcbTransfer, IN BOOL fWait, OUT LPDWORD lpdwFlags, OUT LPINT lpErrno)
 
INT WSPAPI WSPGetPeerName (IN SOCKET s, OUT LPSOCKADDR name, IN OUT LPINT namelen, OUT LPINT lpErrno)
 
BOOL WSPAPI WSPGetQOSByName (IN SOCKET s, IN OUT LPWSABUF lpQOSName, OUT LPQOS lpQOS, OUT LPINT lpErrno)
 
INT WSPAPI WSPGetSockName (IN SOCKET s, OUT LPSOCKADDR name, IN OUT LPINT namelen, OUT LPINT lpErrno)
 
INT WSPAPI WSPGetSockOpt (IN SOCKET s, IN INT level, IN INT optname, OUT CHAR FAR *optval, IN OUT LPINT optlen, OUT LPINT lpErrno)
 
INT WSPAPI WSPIoctl (IN SOCKET s, IN DWORD dwIoControlCode, IN LPVOID lpvInBuffer, IN DWORD cbInBuffer, OUT LPVOID lpvOutBuffer, IN DWORD cbOutBuffer, OUT LPDWORD lpcbBytesReturned, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
 
SOCKET WSPAPI WSPJoinLeaf (IN SOCKET s, IN CONST SOCKADDR *name, IN INT namelen, IN LPWSABUF lpCallerData, OUT LPWSABUF lpCalleeData, IN LPQOS lpSQOS, IN LPQOS lpGQOS, IN DWORD dwFlags, OUT LPINT lpErrno)
 
INT WSPAPI WSPListen (IN SOCKET s, IN INT backlog, OUT LPINT lpErrno)
 
INT WSPAPI WSPRecv (IN SOCKET s, IN OUT LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesRecvd, IN OUT LPDWORD lpFlags, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
 
INT WSPAPI WSPRecvDisconnect (IN SOCKET s, OUT LPWSABUF lpInboundDisconnectData, OUT LPINT lpErrno)
 
INT WSPAPI WSPRecvFrom (IN SOCKET s, IN OUT LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesRecvd, IN OUT LPDWORD lpFlags, OUT LPSOCKADDR lpFrom, IN OUT LPINT lpFromlen, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
 
INT WSPAPI WSPSelect (IN INT nfds, IN OUT fd_set *readfds, IN OUT fd_set *writefds, IN OUT fd_set *exceptfds, IN CONST struct timeval *timeout, OUT LPINT lpErrno)
 
INT WSPAPI WSPSend (IN SOCKET s, IN LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesSent, IN DWORD dwFlags, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
 
INT WSPAPI WSPSendDisconnect (IN SOCKET s, IN LPWSABUF lpOutboundDisconnectData, OUT LPINT lpErrno)
 
INT WSPAPI WSPSendTo (IN SOCKET s, IN LPWSABUF lpBuffers, IN DWORD dwBufferCount, OUT LPDWORD lpNumberOfBytesSent, IN DWORD dwFlags, IN CONST SOCKADDR *lpTo, IN INT iTolen, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine, IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
 
INT WSPAPI WSPSetSockOpt (IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen, OUT LPINT lpErrno)
 
INT WSPAPI WSPShutdown (IN SOCKET s, IN INT how, OUT LPINT lpErrno)
 
SOCKET WSPAPI WSPSocket (IN INT af, IN INT type, IN INT protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags, OUT LPINT lpErrno)
 
INT WSPAPI WSPStringToAddress (IN LPWSTR AddressString, IN INT AddressFamily, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, OUT LPSOCKADDR lpAddress, IN OUT LPINT lpAddressLength, OUT LPINT lpErrno)
 
BOOL WSPAPI WSPAcceptEx (IN SOCKET sListenSocket, IN SOCKET sAcceptSocket, OUT PVOID lpOutputBuffer, IN DWORD dwReceiveDataLength, IN DWORD dwLocalAddressLength, IN DWORD dwRemoteAddressLength, OUT LPDWORD lpdwBytesReceived, IN OUT LPOVERLAPPED lpOverlapped)
 
BOOL WSPAPI WSPConnectEx (IN SOCKET s, IN const struct sockaddr *name, IN int namelen, IN PVOID lpSendBuffer, IN DWORD dwSendDataLength, OUT LPDWORD lpdwBytesSent, IN OUT LPOVERLAPPED lpOverlapped)
 
BOOL WSPAPI WSPDisconnectEx (IN SOCKET hSocket, IN LPOVERLAPPED lpOverlapped, IN DWORD dwFlags, IN DWORD reserved)
 
VOID WSPAPI WSPGetAcceptExSockaddrs (IN PVOID lpOutputBuffer, IN DWORD dwReceiveDataLength, IN DWORD dwLocalAddressLength, IN DWORD dwRemoteAddressLength, OUT struct sockaddr **LocalSockaddr, OUT LPINT LocalSockaddrLength, OUT struct sockaddr **RemoteSockaddr, OUT LPINT RemoteSockaddrLength)
 
PSOCKET_INFORMATION GetSocketStructure (SOCKET Handle)
 
INT TranslateNtStatusError (NTSTATUS Status)
 
VOID DeleteSocketStructure (SOCKET Handle)
 
int GetSocketInformation (PSOCKET_INFORMATION Socket, ULONG AfdInformationClass, PBOOLEAN Boolean OPTIONAL, PULONG Ulong OPTIONAL, PLARGE_INTEGER LargeInteger OPTIONAL, LPWSAOVERLAPPED Overlapped OPTIONAL, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL)
 
int SetSocketInformation (PSOCKET_INFORMATION Socket, ULONG AfdInformationClass, PBOOLEAN Boolean OPTIONAL, PULONG Ulong OPTIONAL, PLARGE_INTEGER LargeInteger OPTIONAL, LPWSAOVERLAPPED Overlapped OPTIONAL, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL)
 
int CreateContext (PSOCKET_INFORMATION Socket)
 
ULONG NTAPI SockAsyncThread (PVOID ThreadParam)
 
VOID SockProcessAsyncSelect (PSOCKET_INFORMATION Socket, PASYNC_DATA AsyncData)
 
VOID SockAsyncSelectCompletionRoutine (PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
 
BOOLEAN SockCreateOrReferenceAsyncThread (VOID)
 
BOOLEAN SockGetAsyncSelectHelperAfdHandle (VOID)
 
VOID SockProcessQueuedAsyncSelect (PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
 
VOID SockReenableAsyncSelectEvent (IN PSOCKET_INFORMATION Socket, IN ULONG Event)
 
FORCEINLINE DWORD MsafdReturnWithErrno (NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
 

Variables

HANDLE GlobalHeap
 
WSPUPCALLTABLE Upcalls
 
LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest
 
LIST_ENTRY SockHelpersListHead
 
HANDLE SockEvent
 
HANDLE SockAsyncCompletionPort
 
BOOLEAN SockAsyncSelectCalled
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 14 of file msafd.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 15 of file msafd.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 20 of file msafd.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 13 of file msafd.h.

Typedef Documentation

◆ AFDAPCCONTEXT

◆ ASYNC_DATA

◆ PAFDAPCCONTEXT

◆ PASYNC_COMPLETION_ROUTINE

typedef VOID(* PASYNC_COMPLETION_ROUTINE) (PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)

Definition at line 542 of file msafd.h.

◆ PASYNC_DATA

◆ PSOCK_SHARED_INFO

◆ PSOCKET_CONTEXT

◆ PSOCKET_INFORMATION

◆ PSOCKET_STATE

◆ SOCK_SHARED_INFO

◆ SOCKET_CONTEXT

◆ SOCKET_INFORMATION

◆ SOCKET_STATE

Enumeration Type Documentation

◆ _SOCKET_STATE

Enumerator
SocketOpen 
SocketBound 
SocketBoundUdp 
SocketConnected 
SocketClosed 
SocketStateCreated 
SocketStateBound 
SocketStateListening 
SocketStateConnected 
SocketUndefined 
SocketOpen 
SocketBound 
SocketBoundUdp 
SocketConnected 
SocketClosed 

Definition at line 45 of file msafd.h.

45  {
46  SocketOpen,
enum _SOCKET_STATE SOCKET_STATE
enum _SOCKET_STATE * PSOCKET_STATE

Function Documentation

◆ CreateContext()

int CreateContext ( PSOCKET_INFORMATION  Socket)

Definition at line 3534 of file dllmain.c.

3535 {
3536  IO_STATUS_BLOCK IOSB;
3537  SOCKET_CONTEXT ContextData;
3538  NTSTATUS Status;
3539  HANDLE SockEvent;
3540 
3543  NULL,
3545  FALSE);
3546 
3547  if( !NT_SUCCESS(Status) )
3548  return SOCKET_ERROR;
3549 
3550  /* Create Context */
3551  ContextData.SharedData = *Socket->SharedData;
3552  ContextData.SizeOfHelperData = 0;
3553  RtlCopyMemory (&ContextData.LocalAddress,
3554  Socket->LocalAddress,
3555  Socket->SharedData->SizeOfLocalAddress);
3556  RtlCopyMemory (&ContextData.RemoteAddress,
3557  Socket->RemoteAddress,
3558  Socket->SharedData->SizeOfRemoteAddress);
3559 
3560  /* Send IOCTL */
3562  SockEvent,
3563  NULL,
3564  NULL,
3565  &IOSB,
3567  &ContextData,
3568  sizeof(ContextData),
3569  NULL,
3570  0);
3571 
3572  /* Wait for Completion */
3573  if (Status == STATUS_PENDING)
3574  {
3576  Status = IOSB.Status;
3577  }
3578 
3579  NtClose( SockEvent );
3580 
3582 }
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE SockEvent
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define NO_ERROR
Definition: dderror.h:5
ULONG SizeOfHelperData
Definition: msafd.h:122
PSOCKADDR RemoteAddress
Definition: msafd.h:106
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
INT SizeOfRemoteAddress
Definition: msafd.h:60
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
INT SizeOfLocalAddress
Definition: msafd.h:59
SOCKADDR RemoteAddress
Definition: msafd.h:125
PSOCKADDR LocalAddress
Definition: msafd.h:105
SOCK_SHARED_INFO SharedData
Definition: msafd.h:121
SOCKADDR LocalAddress
Definition: msafd.h:124
#define INFINITE
Definition: serial.h:102
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IOCTL_AFD_SET_CONTEXT
Definition: shared.h:301

Referenced by WSPSocket().

◆ DeleteSocketStructure()

VOID DeleteSocketStructure ( SOCKET  Handle)

◆ GetSocketInformation()

int GetSocketInformation ( PSOCKET_INFORMATION  Socket,
ULONG  AfdInformationClass,
PBOOLEAN Boolean  OPTIONAL,
PULONG Ulong  OPTIONAL,
PLARGE_INTEGER LargeInteger  OPTIONAL,
LPWSAOVERLAPPED Overlapped  OPTIONAL,
LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine  OPTIONAL 
)

Definition at line 3261 of file dllmain.c.

3268 {
3269  PIO_STATUS_BLOCK IOSB;
3270  IO_STATUS_BLOCK DummyIOSB;
3271  AFD_INFO InfoData;
3272  NTSTATUS Status;
3273  PAFDAPCCONTEXT APCContext;
3274  PIO_APC_ROUTINE APCFunction;
3275  HANDLE Event = NULL;
3276  HANDLE SockEvent;
3277 
3280  NULL,
3282  FALSE);
3283 
3284  if( !NT_SUCCESS(Status) )
3285  return SOCKET_ERROR;
3286 
3287  /* Set Info Class */
3288  InfoData.InformationClass = AfdInformationClass;
3289 
3290  /* Verify if we should use APC */
3291  if (Overlapped == NULL)
3292  {
3293  /* Not using Overlapped structure, so use normal blocking on event */
3294  APCContext = NULL;
3295  APCFunction = NULL;
3296  Event = SockEvent;
3297  IOSB = &DummyIOSB;
3298  }
3299  else
3300  {
3301  /* Overlapped request for non overlapped opened socket */
3302  if ((Socket->SharedData->CreateFlags & SO_SYNCHRONOUS_NONALERT) != 0)
3303  {
3304  TRACE("Opened without flag WSA_FLAG_OVERLAPPED. Do nothing.\n");
3305  NtClose( SockEvent );
3306  return 0;
3307  }
3308  if (CompletionRoutine == NULL)
3309  {
3310  /* Using Overlapped Structure, but no Completition Routine, so no need for APC */
3311  APCContext = (PAFDAPCCONTEXT)Overlapped;
3312  APCFunction = NULL;
3313  Event = Overlapped->hEvent;
3314  }
3315  else
3316  {
3317  /* Using Overlapped Structure and a Completition Routine, so use an APC */
3318  APCFunction = &AfdInfoAPC; // should be a private io completition function inside us
3319  APCContext = HeapAlloc(GlobalHeap, 0, sizeof(AFDAPCCONTEXT));
3320  if (!APCContext)
3321  {
3322  ERR("Not enough memory for APC Context\n");
3323  NtClose( SockEvent );
3324  return WSAEFAULT;
3325  }
3326  APCContext->lpCompletionRoutine = CompletionRoutine;
3327  APCContext->lpOverlapped = Overlapped;
3328  APCContext->lpSocket = Socket;
3329  }
3330 
3331  IOSB = (PIO_STATUS_BLOCK)&Overlapped->Internal;
3332  }
3333 
3334  IOSB->Status = STATUS_PENDING;
3335 
3336  /* Send IOCTL */
3338  Event,
3339  APCFunction,
3340  APCContext,
3341  IOSB,
3343  &InfoData,
3344  sizeof(InfoData),
3345  &InfoData,
3346  sizeof(InfoData));
3347 
3348  /* Wait for return */
3349  if (Status == STATUS_PENDING && Overlapped == NULL)
3350  {
3352  Status = IOSB->Status;
3353  }
3354 
3355  NtClose( SockEvent );
3356 
3357  TRACE("Status %x Information %d\n", Status, IOSB->Information);
3358 
3359  if (Status == STATUS_PENDING)
3360  {
3361  TRACE("Leaving (Pending)\n");
3362  return WSA_IO_PENDING;
3363  }
3364 
3365  if (Status != STATUS_SUCCESS)
3366  return SOCKET_ERROR;
3367 
3368  /* Return Information */
3369  if (Ulong != NULL)
3370  {
3371  *Ulong = InfoData.Information.Ulong;
3372  }
3373  if (LargeInteger != NULL)
3374  {
3375  *LargeInteger = InfoData.Information.LargeInteger;
3376  }
3377  if (Boolean != NULL)
3378  {
3379  *Boolean = InfoData.Information.Boolean;
3380  }
3381 
3382  return NO_ERROR;
3383 
3384 }
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE SockEvent
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
Definition: nt_native.h:877
#define WSAEFAULT
Definition: winerror.h:1945
BOOLEAN Boolean
Definition: shared.h:33
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
struct _AFDAPCCONTEXT * PAFDAPCCONTEXT
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define NO_ERROR
Definition: dderror.h:5
DWORD CreateFlags
Definition: msafd.h:81
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LARGE_INTEGER LargeInteger
Definition: shared.h:32
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
smooth NULL
Definition: ftsmooth.c:416
#define WSA_IO_PENDING
Definition: winsock2.h:589
union _AFD_INFO::@3340 Information
#define TRACE(s)
Definition: solgame.cpp:4
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
ULONG InformationClass
Definition: shared.h:29
LPWSAOVERLAPPED lpOverlapped
Definition: msafd.h:138
struct _IO_STATUS_BLOCK * PIO_STATUS_BLOCK
Definition: change.c:34
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
HANDLE GlobalHeap
Definition: dllmain.c:19
#define SO_SYNCHRONOUS_NONALERT
Definition: ws2_32.h:41
#define ERR(fmt,...)
Definition: debug.h:110
#define IOCTL_AFD_GET_INFO
Definition: shared.h:327
VOID NTAPI AfdInfoAPC(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved)
Definition: dllmain.c:3250
PSOCKET_INFORMATION lpSocket
Definition: msafd.h:140
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
Definition: msafd.h:139
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
#define INFINITE
Definition: serial.h:102
unsigned long Ulong
Definition: utypes.h:42
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG Ulong
Definition: shared.h:31

Referenced by WSPCloseSocket(), WSPIoctl(), WSPSetSockOpt(), and WSPSocket().

◆ GetSocketStructure()

PSOCKET_INFORMATION GetSocketStructure ( SOCKET  Handle)

Definition at line 3511 of file dllmain.c.

3512 {
3513  PSOCKET_INFORMATION CurrentSocket;
3514 
3516 
3517  CurrentSocket = SocketListHead;
3518  while (CurrentSocket)
3519  {
3520  if (CurrentSocket->Handle == Handle)
3521  {
3523  return CurrentSocket;
3524  }
3525 
3526  CurrentSocket = CurrentSocket->NextSocket;
3527  }
3528 
3530 
3531  return NULL;
3532 }
SOCKET Handle
Definition: msafd.h:99
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct _SOCKET_INFORMATION * NextSocket
Definition: msafd.h:116
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
CRITICAL_SECTION SocketListLock
Definition: dllmain.c:24
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
PSOCKET_INFORMATION SocketListHead
Definition: dllmain.c:23

Referenced by WSPAccept(), WSPAsyncSelect(), WSPBind(), WSPCloseSocket(), WSPConnect(), WSPDuplicateSocket(), WSPEnumNetworkEvents(), WSPEventSelect(), WSPGetOverlappedResult(), WSPGetPeerName(), WSPGetSockName(), WSPGetSockOpt(), WSPIoctl(), WSPListen(), WSPRecv(), WSPRecvFrom(), WSPSelect(), WSPSend(), WSPSendTo(), WSPSetSockOpt(), and WSPShutdown().

◆ MsafdReturnWithErrno()

FORCEINLINE DWORD MsafdReturnWithErrno ( NTSTATUS  Status,
LPINT  Errno,
DWORD  Received,
LPDWORD  ReturnedBytes 
)

Definition at line 546 of file msafd.h.

550 {
551  if (Errno)
552  {
553  *Errno = TranslateNtStatusError(Status);
554 
555  if (ReturnedBytes)
556  *ReturnedBytes = (*Errno == 0) ? Received : 0;
557 
558  return (*Errno == 0) ? 0 : SOCKET_ERROR;
559  }
560  else
561  {
562  DbgPrint("%s: Received invalid lpErrno pointer!\n", __FUNCTION__);
563 
564  if (ReturnedBytes)
565  *ReturnedBytes = (Status == STATUS_SUCCESS) ? Received : 0;
566 
567  return (Status == STATUS_SUCCESS) ? 0 : SOCKET_ERROR;
568  }
569 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define DbgPrint
Definition: loader.c:25
Status
Definition: gdiplustypes.h:24
INT TranslateNtStatusError(NTSTATUS Status)
Definition: dllmain.c:537
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define __FUNCTION__
Definition: types.h:112
UINT Received
Definition: arping.c:40

Referenced by WSPAccept(), WSPAsyncSelect(), WSPBind(), WSPCloseSocket(), WSPConnect(), WSPDuplicateSocket(), WSPEnumNetworkEvents(), WSPEventSelect(), WSPGetPeerName(), WSPGetSockName(), WSPListen(), WSPRecv(), WSPRecvFrom(), WSPSend(), WSPSendTo(), and WSPShutdown().

◆ SetSocketInformation()

int SetSocketInformation ( PSOCKET_INFORMATION  Socket,
ULONG  AfdInformationClass,
PBOOLEAN Boolean  OPTIONAL,
PULONG Ulong  OPTIONAL,
PLARGE_INTEGER LargeInteger  OPTIONAL,
LPWSAOVERLAPPED Overlapped  OPTIONAL,
LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine  OPTIONAL 
)

Definition at line 3388 of file dllmain.c.

3395 {
3396  PIO_STATUS_BLOCK IOSB;
3397  IO_STATUS_BLOCK DummyIOSB;
3398  AFD_INFO InfoData;
3399  NTSTATUS Status;
3400  PAFDAPCCONTEXT APCContext;
3401  PIO_APC_ROUTINE APCFunction;
3402  HANDLE Event = NULL;
3403  HANDLE SockEvent;
3404 
3407  NULL,
3409  FALSE);
3410 
3411  if( !NT_SUCCESS(Status) )
3412  return SOCKET_ERROR;
3413 
3414  /* Set Info Class */
3415  InfoData.InformationClass = AfdInformationClass;
3416 
3417  /* Set Information */
3418  if (Ulong != NULL)
3419  {
3420  InfoData.Information.Ulong = *Ulong;
3421  }
3422  if (LargeInteger != NULL)
3423  {
3424  InfoData.Information.LargeInteger = *LargeInteger;
3425  }
3426  if (Boolean != NULL)
3427  {
3428  InfoData.Information.Boolean = *Boolean;
3429  }
3430 
3431  /* Verify if we should use APC */
3432  if (Overlapped == NULL)
3433  {
3434  /* Not using Overlapped structure, so use normal blocking on event */
3435  APCContext = NULL;
3436  APCFunction = NULL;
3437  Event = SockEvent;
3438  IOSB = &DummyIOSB;
3439  }
3440  else
3441  {
3442  /* Overlapped request for non overlapped opened socket */
3443  if ((Socket->SharedData->CreateFlags & SO_SYNCHRONOUS_NONALERT) != 0)
3444  {
3445  TRACE("Opened without flag WSA_FLAG_OVERLAPPED. Do nothing.\n");
3446  NtClose( SockEvent );
3447  return 0;
3448  }
3449  if (CompletionRoutine == NULL)
3450  {
3451  /* Using Overlapped Structure, but no Completition Routine, so no need for APC */
3452  APCContext = (PAFDAPCCONTEXT)Overlapped;
3453  APCFunction = NULL;
3454  Event = Overlapped->hEvent;
3455  }
3456  else
3457  {
3458  /* Using Overlapped Structure and a Completition Routine, so use an APC */
3459  APCFunction = &AfdInfoAPC; // should be a private io completition function inside us
3460  APCContext = HeapAlloc(GlobalHeap, 0, sizeof(AFDAPCCONTEXT));
3461  if (!APCContext)
3462  {
3463  ERR("Not enough memory for APC Context\n");
3464  NtClose( SockEvent );
3465  return WSAEFAULT;
3466  }
3467  APCContext->lpCompletionRoutine = CompletionRoutine;
3468  APCContext->lpOverlapped = Overlapped;
3469  APCContext->lpSocket = Socket;
3470  }
3471 
3472  IOSB = (PIO_STATUS_BLOCK)&Overlapped->Internal;
3473  }
3474 
3475  IOSB->Status = STATUS_PENDING;
3476 
3477  /* Send IOCTL */
3479  Event,
3480  APCFunction,
3481  APCContext,
3482  IOSB,
3484  &InfoData,
3485  sizeof(InfoData),
3486  NULL,
3487  0);
3488 
3489  /* Wait for return */
3490  if (Status == STATUS_PENDING && Overlapped == NULL)
3491  {
3493  Status = IOSB->Status;
3494  }
3495 
3496  NtClose( SockEvent );
3497 
3498  TRACE("Status %x Information %d\n", Status, IOSB->Information);
3499 
3500  if (Status == STATUS_PENDING)
3501  {
3502  TRACE("Leaving (Pending)\n");
3503  return WSA_IO_PENDING;
3504  }
3505 
3507 
3508 }
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE SockEvent
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
Definition: nt_native.h:877
#define WSAEFAULT
Definition: winerror.h:1945
BOOLEAN Boolean
Definition: shared.h:33
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
struct _AFDAPCCONTEXT * PAFDAPCCONTEXT
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define NO_ERROR
Definition: dderror.h:5
DWORD CreateFlags
Definition: msafd.h:81
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LARGE_INTEGER LargeInteger
Definition: shared.h:32
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
smooth NULL
Definition: ftsmooth.c:416
#define WSA_IO_PENDING
Definition: winsock2.h:589
union _AFD_INFO::@3340 Information
#define IOCTL_AFD_SET_INFO
Definition: shared.h:295
#define TRACE(s)
Definition: solgame.cpp:4
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
ULONG InformationClass
Definition: shared.h:29
LPWSAOVERLAPPED lpOverlapped
Definition: msafd.h:138
struct _IO_STATUS_BLOCK * PIO_STATUS_BLOCK
Definition: change.c:34
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
HANDLE GlobalHeap
Definition: dllmain.c:19
#define SO_SYNCHRONOUS_NONALERT
Definition: ws2_32.h:41
#define ERR(fmt,...)
Definition: debug.h:110
VOID NTAPI AfdInfoAPC(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved)
Definition: dllmain.c:3250
PSOCKET_INFORMATION lpSocket
Definition: msafd.h:140
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
Definition: msafd.h:139
_In_ PIRP _In_opt_ PVOID _In_opt_ POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine
Definition: fsrtlfuncs.h:673
#define INFINITE
Definition: serial.h:102
unsigned long Ulong
Definition: utypes.h:42
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG Ulong
Definition: shared.h:31

Referenced by WSPAsyncSelect(), WSPEventSelect(), WSPIoctl(), and WSPSetSockOpt().

◆ SockAsyncSelectCompletionRoutine()

VOID SockAsyncSelectCompletionRoutine ( PVOID  Context,
PIO_STATUS_BLOCK  IoStatusBlock 
)

Definition at line 3741 of file dllmain.c.

3742 {
3743 
3744  PASYNC_DATA AsyncData = Context;
3745  PSOCKET_INFORMATION Socket;
3746  ULONG x;
3747 
3748  /* Get the Socket */
3749  Socket = AsyncData->ParentSocket;
3750 
3751  /* Check if the Sequence Number Changed behind our back */
3752  if (AsyncData->SequenceNumber != Socket->SharedData->SequenceNumber )
3753  {
3754  return;
3755  }
3756 
3757  /* Check we were manually called b/c of a failure */
3759  {
3760  /* FIXME: Perform Upcall */
3761  return;
3762  }
3763 
3764  for (x = 1; x; x<<=1)
3765  {
3766  switch (AsyncData->AsyncSelectInfo.Handles[0].Events & x)
3767  {
3768  case AFD_EVENT_RECEIVE:
3769  if (0 != (Socket->SharedData->AsyncEvents & FD_READ) &&
3770  0 == (Socket->SharedData->AsyncDisabledEvents & FD_READ))
3771  {
3772  /* Make the Notification */
3774  Socket->SharedData->wMsg,
3775  Socket->Handle,
3777  /* Disable this event until the next read(); */
3779  }
3780  break;
3781 
3782  case AFD_EVENT_OOB_RECEIVE:
3783  if (0 != (Socket->SharedData->AsyncEvents & FD_OOB) &&
3784  0 == (Socket->SharedData->AsyncDisabledEvents & FD_OOB))
3785  {
3786  /* Make the Notification */
3788  Socket->SharedData->wMsg,
3789  Socket->Handle,
3791  /* Disable this event until the next read(); */
3793  }
3794  break;
3795 
3796  case AFD_EVENT_SEND:
3797  if (0 != (Socket->SharedData->AsyncEvents & FD_WRITE) &&
3798  0 == (Socket->SharedData->AsyncDisabledEvents & FD_WRITE))
3799  {
3800  /* Make the Notification */
3802  Socket->SharedData->wMsg,
3803  Socket->Handle,
3805  /* Disable this event until the next write(); */
3807  }
3808  break;
3809 
3810  /* FIXME: THIS IS NOT RIGHT!!! HACK HACK HACK! */
3811  case AFD_EVENT_CONNECT:
3813  if (0 != (Socket->SharedData->AsyncEvents & FD_CONNECT) &&
3814  0 == (Socket->SharedData->AsyncDisabledEvents & FD_CONNECT))
3815  {
3816  /* Make the Notification */
3818  Socket->SharedData->wMsg,
3819  Socket->Handle,
3821  /* Disable this event forever; */
3823  }
3824  break;
3825 
3826  case AFD_EVENT_ACCEPT:
3827  if (0 != (Socket->SharedData->AsyncEvents & FD_ACCEPT) &&
3828  0 == (Socket->SharedData->AsyncDisabledEvents & FD_ACCEPT))
3829  {
3830  /* Make the Notification */
3832  Socket->SharedData->wMsg,
3833  Socket->Handle,
3835  /* Disable this event until the next accept(); */
3837  }
3838  break;
3839 
3840  case AFD_EVENT_DISCONNECT:
3841  case AFD_EVENT_ABORT:
3842  case AFD_EVENT_CLOSE:
3843  if (0 != (Socket->SharedData->AsyncEvents & FD_CLOSE) &&
3844  0 == (Socket->SharedData->AsyncDisabledEvents & FD_CLOSE))
3845  {
3846  /* Make the Notification */
3848  Socket->SharedData->wMsg,
3849  Socket->Handle,
3851  /* Disable this event forever; */
3853  }
3854  break;
3855  /* FIXME: Support QOS */
3856  }
3857  }
3858 
3859  /* Check if there are any events left for us to check */
3860  if ((Socket->SharedData->AsyncEvents & (~Socket->SharedData->AsyncDisabledEvents)) == 0 )
3861  {
3862  return;
3863  }
3864 
3865  /* Keep Polling */
3866  SockProcessAsyncSelect(Socket, AsyncData);
3867  return;
3868 }
DWORD SequenceNumber
Definition: msafd.h:131
VOID SockProcessAsyncSelect(PSOCKET_INFORMATION Socket, PASYNC_DATA AsyncData)
Definition: dllmain.c:3870
#define AFD_EVENT_CONNECT_FAIL
Definition: shared.h:211
#define FD_ACCEPT
Definition: winsock.h:408
#define FD_CONNECT
Definition: winsock.h:409
#define AFD_EVENT_DISCONNECT
Definition: shared.h:206
SOCKET Handle
Definition: msafd.h:99
#define AFD_EVENT_ABORT
Definition: shared.h:207
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
DWORD SequenceNumber
Definition: msafd.h:90
#define FD_READ
Definition: winsock.h:405
#define FD_OOB
Definition: winsock.h:407
#define FD_WRITE
Definition: winsock.h:406
#define AFD_EVENT_CLOSE
Definition: shared.h:208
#define WSAMAKESELECTREPLY(e, error)
Definition: winsock.h:478
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
ULONG Events
Definition: shared.h:51
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
#define AFD_EVENT_CONNECT
Definition: shared.h:209
AFD_POLL_INFO AsyncSelectInfo
Definition: msafd.h:133
#define AFD_EVENT_SEND
Definition: shared.h:205
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define FD_CLOSE
Definition: winsock.h:410
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PSOCKET_INFORMATION ParentSocket
Definition: msafd.h:130
#define AFD_EVENT_OOB_RECEIVE
Definition: shared.h:204
LONG AsyncDisabledEvents
Definition: msafd.h:93
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
AFD_HANDLE Handles[1]
Definition: shared.h:59
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
WSPUPCALLTABLE Upcalls
Definition: dllmain.c:20
LPWPUPOSTMESSAGE lpWPUPostMessage
Definition: ws2spi.h:609
LONG AsyncEvents
Definition: msafd.h:92

Referenced by SockGetAsyncSelectHelperAfdHandle(), and SockProcessAsyncSelect().

◆ SockAsyncThread()

ULONG NTAPI SockAsyncThread ( PVOID  ThreadParam)

Definition at line 3645 of file dllmain.c.

3646 {
3647  PVOID AsyncContext;
3648  PASYNC_COMPLETION_ROUTINE AsyncCompletionRoutine;
3649  IO_STATUS_BLOCK IOSB;
3650  NTSTATUS Status;
3651 
3652  /* Make the Thread Higher Priority */
3654 
3655  /* Do a KQUEUE/WorkItem Style Loop, thanks to IoCompletion Ports */
3656  do
3657  {
3659  (PVOID*)&AsyncCompletionRoutine,
3660  &AsyncContext,
3661  &IOSB,
3662  NULL);
3663  /* Call the Async Function */
3664  if (NT_SUCCESS(Status))
3665  {
3666  (*AsyncCompletionRoutine)(AsyncContext, &IOSB);
3667  }
3668  else
3669  {
3670  /* It Failed, sleep for a second */
3671  Sleep(1000);
3672  }
3673  } while ((Status != STATUS_TIMEOUT));
3674 
3675  /* The Thread has Ended */
3676  return 0;
3677 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
LONG NTSTATUS
Definition: precomp.h:26
HANDLE SockAsyncCompletionPort
Definition: dllmain.c:28
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define THREAD_PRIORITY_ABOVE_NORMAL
Definition: winbase.h:272
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1148
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI SetThreadPriority(IN HANDLE hThread, IN int nPriority)
Definition: thread.c:699
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID(* PASYNC_COMPLETION_ROUTINE)(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
Definition: msafd.h:542
NTSTATUS NTAPI NtRemoveIoCompletion(IN HANDLE IoCompletionHandle, OUT PVOID *KeyContext, OUT PVOID *ApcContext, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: iocomp.c:444

◆ SockCreateOrReferenceAsyncThread()

BOOLEAN SockCreateOrReferenceAsyncThread ( VOID  )

Definition at line 3584 of file dllmain.c.

3585 {
3586  HANDLE hAsyncThread;
3587  DWORD AsyncThreadId;
3588  HANDLE AsyncEvent;
3590  NTSTATUS Status;
3591 
3592  /* Check if the Thread Already Exists */
3594  {
3596  return TRUE;
3597  }
3598 
3599  /* Create the Completion Port */
3601  {
3604  NULL,
3605  2); // Allow 2 threads only
3606  if (!NT_SUCCESS(Status))
3607  {
3608  ERR("Failed to create completion port: 0x%08x\n", Status);
3609  return FALSE;
3610  }
3611  /* Protect Handle */
3612  HandleFlags.ProtectFromClose = TRUE;
3613  HandleFlags.Inherit = FALSE;
3615  ObjectHandleFlagInformation,
3616  &HandleFlags,
3617  sizeof(HandleFlags));
3618  }
3619 
3620  /* Create the Async Event */
3621  Status = NtCreateEvent(&AsyncEvent,
3623  NULL,
3625  FALSE);
3626 
3627  /* Create the Async Thread */
3628  hAsyncThread = CreateThread(NULL,
3629  0,
3631  NULL,
3632  0,
3633  &AsyncThreadId);
3634 
3635  /* Close the Handle */
3636  NtClose(hAsyncThread);
3637 
3638  /* Increase the Reference Count */
3640  return TRUE;
3641 }
#define IO_COMPLETION_ALL_ACCESS
Definition: file.c:72
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
HANDLE SockAsyncCompletionPort
Definition: dllmain.c:28
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:110
ULONG SockAsyncThreadRefCount
Definition: dllmain.c:26
NTSTATUS NTAPI NtCreateIoCompletion(OUT PHANDLE IoCompletionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG NumberOfConcurrentThreads)
Definition: iocomp.c:253
ULONG NTAPI SockAsyncThread(PVOID ThreadParam)
Definition: dllmain.c:3645

Referenced by SockReenableAsyncSelectEvent(), and WSPAsyncSelect().

◆ SockGetAsyncSelectHelperAfdHandle()

BOOLEAN SockGetAsyncSelectHelperAfdHandle ( VOID  )

Definition at line 3679 of file dllmain.c.

3680 {
3681  UNICODE_STRING AfdHelper;
3683  IO_STATUS_BLOCK IoSb;
3684  FILE_COMPLETION_INFORMATION CompletionInfo;
3686 
3687  /* First, make sure we're not already initialized */
3689  {
3690  return TRUE;
3691  }
3692 
3693  /* Set up Handle Name and Object */
3694  RtlInitUnicodeString(&AfdHelper, L"\\Device\\Afd\\AsyncSelectHlp" );
3696  &AfdHelper,
3698  NULL,
3699  NULL);
3700 
3701  /* Open the Handle to AFD */
3705  &IoSb,
3706  NULL,
3707  0,
3709  FILE_OPEN_IF,
3710  0,
3711  NULL,
3712  0);
3713 
3714  /*
3715  * Now Set up the Completion Port Information
3716  * This means that whenever a Poll is finished, the routine will be executed
3717  */
3718  CompletionInfo.Port = SockAsyncCompletionPort;
3719  CompletionInfo.Key = SockAsyncSelectCompletionRoutine;
3721  &IoSb,
3722  &CompletionInfo,
3723  sizeof(CompletionInfo),
3725 
3726 
3727  /* Protect the Handle */
3728  HandleFlags.ProtectFromClose = TRUE;
3729  HandleFlags.Inherit = FALSE;
3731  ObjectHandleFlagInformation,
3732  &HandleFlags,
3733  sizeof(HandleFlags));
3734 
3735 
3736  /* Set this variable to true so that Send/Recv/Accept will know wether to renable disabled events */
3738  return TRUE;
3739 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define FILE_OPEN_IF
Definition: from_kernel.h:56
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define TRUE
Definition: types.h:120
HANDLE SockAsyncCompletionPort
Definition: dllmain.c:28
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
#define FALSE
Definition: types.h:117
#define GENERIC_WRITE
Definition: nt_native.h:90
NTSTATUS NTAPI NtSetInformationObject(IN HANDLE ObjectHandle, IN OBJECT_INFORMATION_CLASS ObjectInformationClass, IN PVOID ObjectInformation, IN ULONG Length)
Definition: oblife.c:1735
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
#define OBJ_INHERIT
Definition: winternl.h:225
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:135
#define SYNCHRONIZE
Definition: nt_native.h:61
BOOLEAN SockAsyncSelectCalled
Definition: dllmain.c:29
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
VOID SockAsyncSelectCompletionRoutine(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
Definition: dllmain.c:3741
HANDLE SockAsyncHelperAfdHandle
Definition: dllmain.c:27

Referenced by WSPAsyncSelect().

◆ SockProcessAsyncSelect()

VOID SockProcessAsyncSelect ( PSOCKET_INFORMATION  Socket,
PASYNC_DATA  AsyncData 
)

Definition at line 3870 of file dllmain.c.

3871 {
3872 
3873  ULONG lNetworkEvents;
3874  NTSTATUS Status;
3875 
3876  /* Set up the Async Data Event Info */
3877  AsyncData->AsyncSelectInfo.Timeout.HighPart = 0x7FFFFFFF;
3878  AsyncData->AsyncSelectInfo.Timeout.LowPart = 0xFFFFFFFF;
3879  AsyncData->AsyncSelectInfo.HandleCount = 1;
3880  AsyncData->AsyncSelectInfo.Exclusive = TRUE;
3881  AsyncData->AsyncSelectInfo.Handles[0].Handle = Socket->Handle;
3882  AsyncData->AsyncSelectInfo.Handles[0].Events = 0;
3883 
3884  /* Remove unwanted events */
3885  lNetworkEvents = Socket->SharedData->AsyncEvents & (~Socket->SharedData->AsyncDisabledEvents);
3886 
3887  /* Set Events to wait for */
3888  if (lNetworkEvents & FD_READ)
3889  {
3891  }
3892 
3893  if (lNetworkEvents & FD_WRITE)
3894  {
3895  AsyncData->AsyncSelectInfo.Handles[0].Events |= AFD_EVENT_SEND;
3896  }
3897 
3898  if (lNetworkEvents & FD_OOB)
3899  {
3901  }
3902 
3903  if (lNetworkEvents & FD_ACCEPT)
3904  {
3906  }
3907 
3908  /* FIXME: THIS IS NOT RIGHT!!! HACK HACK HACK! */
3909  if (lNetworkEvents & FD_CONNECT)
3910  {
3912  }
3913 
3914  if (lNetworkEvents & FD_CLOSE)
3915  {
3917  }
3918 
3919  if (lNetworkEvents & FD_QOS)
3920  {
3921  AsyncData->AsyncSelectInfo.Handles[0].Events |= AFD_EVENT_QOS;
3922  }
3923 
3924  if (lNetworkEvents & FD_GROUP_QOS)
3925  {
3927  }
3928 
3929  /* Send IOCTL */
3931  NULL,
3932  NULL,
3933  AsyncData,
3934  &AsyncData->IoStatusBlock,
3936  &AsyncData->AsyncSelectInfo,
3937  sizeof(AsyncData->AsyncSelectInfo),
3938  &AsyncData->AsyncSelectInfo,
3939  sizeof(AsyncData->AsyncSelectInfo));
3940 
3941  /* I/O Manager Won't call the completion routine, let's do it manually */
3942  if (NT_SUCCESS(Status))
3943  {
3944  return;
3945  }
3946  else
3947  {
3948  AsyncData->IoStatusBlock.Status = Status;
3949  SockAsyncSelectCompletionRoutine(AsyncData, &AsyncData->IoStatusBlock);
3950  }
3951 }
#define AFD_EVENT_CONNECT_FAIL
Definition: shared.h:211
#define FD_ACCEPT
Definition: winsock.h:408
#define FD_CONNECT
Definition: winsock.h:409
#define TRUE
Definition: types.h:120
#define AFD_EVENT_DISCONNECT
Definition: shared.h:206
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
#define AFD_EVENT_ABORT
Definition: shared.h:207
#define FD_READ
Definition: winsock.h:405
LARGE_INTEGER Timeout
Definition: shared.h:56
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FD_OOB
Definition: winsock.h:407
#define FD_WRITE
Definition: winsock.h:406
#define AFD_EVENT_CLOSE
Definition: shared.h:208
#define FD_GROUP_QOS
Definition: winsock2.h:308
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
ULONG Events
Definition: shared.h:51
#define IOCTL_AFD_SELECT
Definition: shared.h:285
smooth NULL
Definition: ftsmooth.c:416
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
#define AFD_EVENT_CONNECT
Definition: shared.h:209
AFD_POLL_INFO AsyncSelectInfo
Definition: msafd.h:133
#define AFD_EVENT_SEND
Definition: shared.h:205
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define FD_CLOSE
Definition: winsock.h:410
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
ULONG LowPart
Definition: typedefs.h:106
ULONG_PTR Exclusive
Definition: shared.h:58
#define AFD_EVENT_OOB_RECEIVE
Definition: shared.h:204
IO_STATUS_BLOCK IoStatusBlock
Definition: msafd.h:132
#define AFD_EVENT_QOS
Definition: shared.h:212
LONG AsyncDisabledEvents
Definition: msafd.h:93
ULONG HandleCount
Definition: shared.h:57
AFD_HANDLE Handles[1]
Definition: shared.h:59
unsigned int ULONG
Definition: retypes.h:1
SOCKET Handle
Definition: shared.h:50
VOID SockAsyncSelectCompletionRoutine(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
Definition: dllmain.c:3741
HANDLE SockAsyncHelperAfdHandle
Definition: dllmain.c:27
LONG AsyncEvents
Definition: msafd.h:92
#define AFD_EVENT_GROUP_QOS
Definition: shared.h:213
#define FD_QOS
Definition: winsock2.h:306

◆ SockProcessQueuedAsyncSelect()

VOID SockProcessQueuedAsyncSelect ( PVOID  Context,
PIO_STATUS_BLOCK  IoStatusBlock 
)

Definition at line 3953 of file dllmain.c.

3954 {
3955  PASYNC_DATA AsyncData = Context;
3956  BOOL FreeContext = TRUE;
3957  PSOCKET_INFORMATION Socket;
3958 
3959  /* Get the Socket */
3960  Socket = AsyncData->ParentSocket;
3961 
3962  /* If someone closed it, stop the function */
3963  if (Socket->SharedData->State != SocketClosed)
3964  {
3965  /* Check if the Sequence Number changed by now, in which case quit */
3966  if (AsyncData->SequenceNumber == Socket->SharedData->SequenceNumber)
3967  {
3968  /* Do the actual select, if needed */
3969  if ((Socket->SharedData->AsyncEvents & (~Socket->SharedData->AsyncDisabledEvents)))
3970  {
3971  SockProcessAsyncSelect(Socket, AsyncData);
3972  FreeContext = FALSE;
3973  }
3974  }
3975  }
3976 
3977  /* Free the Context */
3978  if (FreeContext)
3979  {
3980  HeapFree(GetProcessHeap(), 0, AsyncData);
3981  }
3982 
3983  return;
3984 }
DWORD SequenceNumber
Definition: msafd.h:131
VOID SockProcessAsyncSelect(PSOCKET_INFORMATION Socket, PASYNC_DATA AsyncData)
Definition: dllmain.c:3870
#define TRUE
Definition: types.h:120
DWORD SequenceNumber
Definition: msafd.h:90
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
#define GetProcessHeap()
Definition: compat.h:484
PSOCKET_INFORMATION ParentSocket
Definition: msafd.h:130
LONG AsyncDisabledEvents
Definition: msafd.h:93
SOCKET_STATE State
Definition: msafd.h:54
struct tagContext Context
Definition: acpixf.h:1034
LONG AsyncEvents
Definition: msafd.h:92
#define HeapFree(x, y, z)
Definition: compat.h:483

◆ SockReenableAsyncSelectEvent()

VOID SockReenableAsyncSelectEvent ( IN PSOCKET_INFORMATION  Socket,
IN ULONG  Event 
)

Definition at line 3987 of file dllmain.c.

3989 {
3990  PASYNC_DATA AsyncData;
3991 
3992  /* Make sure the event is actually disabled */
3993  if (!(Socket->SharedData->AsyncDisabledEvents & Event))
3994  {
3995  return;
3996  }
3997 
3998  /* Re-enable it */
3999  Socket->SharedData->AsyncDisabledEvents &= ~Event;
4000 
4001  /* Return if no more events are being polled */
4002  if ((Socket->SharedData->AsyncEvents & (~Socket->SharedData->AsyncDisabledEvents)) == 0 )
4003  {
4004  return;
4005  }
4006 
4007  /* Wait on new events */
4008  AsyncData = HeapAlloc(GetProcessHeap(), 0, sizeof(ASYNC_DATA));
4009  if (!AsyncData) return;
4010 
4011  /* Create the Asynch Thread if Needed */
4013 
4014  /* Increase the sequence number to stop anything else */
4015  Socket->SharedData->SequenceNumber++;
4016 
4017  /* Set up the Async Data */
4018  AsyncData->ParentSocket = Socket;
4019  AsyncData->SequenceNumber = Socket->SharedData->SequenceNumber;
4020 
4021  /* Begin Async Select by using I/O Completion */
4024  AsyncData,
4025  0,
4026  0);
4027 
4028  /* All done */
4029  return;
4030 }
DWORD SequenceNumber
Definition: msafd.h:131
HANDLE SockAsyncCompletionPort
Definition: dllmain.c:28
BOOLEAN SockCreateOrReferenceAsyncThread(VOID)
Definition: dllmain.c:3584
VOID SockProcessQueuedAsyncSelect(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
Definition: dllmain.c:3953
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
NTSTATUS NTAPI NtSetIoCompletion(IN HANDLE IoCompletionPortHandle, IN PVOID CompletionKey, IN PVOID CompletionContext, IN NTSTATUS CompletionStatus, IN ULONG CompletionInformation)
Definition: iocomp.c:568
PSOCKET_INFORMATION ParentSocket
Definition: msafd.h:130

◆ TranslateNtStatusError()

INT TranslateNtStatusError ( NTSTATUS  Status)

Definition at line 537 of file dllmain.c.

538 {
539  switch (Status)
540  {
541  case STATUS_CANT_WAIT:
542  return WSAEWOULDBLOCK;
543 
544  case STATUS_TIMEOUT:
545  return WSAETIMEDOUT;
546 
547  case STATUS_SUCCESS:
548  return NO_ERROR;
549 
550  case STATUS_FILE_CLOSED:
551  return WSAECONNRESET;
552 
553  case STATUS_END_OF_FILE:
554  return WSAESHUTDOWN;
555 
556  case STATUS_PENDING:
557  return WSA_IO_PENDING;
558 
561  return WSAEMSGSIZE;
562 
563  case STATUS_NO_MEMORY:
565  return WSAENOBUFS;
566 
568  return WSAENOTCONN;
569 
571  return WSAEAFNOSUPPORT;
572 
574  return WSAEADDRNOTAVAIL;
575 
578  return WSAECONNREFUSED;
579 
581  return WSAENETUNREACH;
582 
584  return WSAEHOSTUNREACH;
585 
587  return WSAEINVAL;
588 
589  case STATUS_CANCELLED:
590  return WSA_OPERATION_ABORTED;
591 
593  return WSAEADDRINUSE;
594 
596  return WSAECONNABORTED;
597 
599  return WSAEFAULT;
600 
602  return WSAEACCES;
603 
605  return WSAEOPNOTSUPP;
606 
607  default:
608  ERR("MSAFD: Unhandled NTSTATUS value: 0x%x\n", Status);
609  return WSAENETDOWN;
610  }
611 }
#define STATUS_INVALID_CONNECTION
Definition: ntstatus.h:556
#define STATUS_PROTOCOL_NOT_SUPPORTED
Definition: ntstatus.h:1177
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define WSAEFAULT
Definition: winerror.h:1945
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define WSA_OPERATION_ABORTED
Definition: winsock2.h:594
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WSAEINVAL
Definition: winerror.h:1946
#define WSAEAFNOSUPPORT
Definition: winerror.h:1960
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
#define WSAEACCES
Definition: winerror.h:1944
#define NO_ERROR
Definition: dderror.h:5
#define STATUS_HOST_UNREACHABLE
Definition: ntstatus.h:705
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: ntstatus.h:654
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define WSAEOPNOTSUPP
Definition: winerror.h:1958
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_REMOTE_DISCONNECT
Definition: ntstatus.h:552
#define WSA_IO_PENDING
Definition: winsock2.h:589
#define WSAETIMEDOUT
Definition: winerror.h:1973
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define WSAEHOSTUNREACH
Definition: winerror.h:1978
#define WSAENETDOWN
Definition: winerror.h:1963
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define WSAEMSGSIZE
Definition: winerror.h:1953
Status
Definition: gdiplustypes.h:24
#define WSAENETUNREACH
Definition: winerror.h:1964
#define WSAENOTCONN
Definition: winerror.h:1970
#define WSAEADDRNOTAVAIL
Definition: winerror.h:1962
#define ERR(fmt,...)
Definition: debug.h:110
#define WSAECONNABORTED
Definition: winerror.h:1966
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_INVALID_ADDRESS
Definition: ntstatus.h:557
#define WSAESHUTDOWN
Definition: winerror.h:1971
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define WSAECONNRESET
Definition: winerror.h:1967
#define STATUS_REMOTE_NOT_LISTENING
Definition: ntstatus.h:424
#define STATUS_LOCAL_DISCONNECT
Definition: ntstatus.h:551
#define WSAECONNREFUSED
Definition: winerror.h:1974
#define WSAEADDRINUSE
Definition: winerror.h:1961
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define STATUS_NETWORK_UNREACHABLE
Definition: ntstatus.h:704
#define WSAENOBUFS
Definition: winerror.h:1968
#define STATUS_CANT_WAIT
Definition: ntstatus.h:452
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:532

Referenced by MsafdReturnWithErrno(), WSPAccept(), WSPBind(), WSPConnect(), WSPEnumNetworkEvents(), WSPListen(), WSPShutdown(), and WSPSocket().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msafd  )

◆ WSPAccept()

_Must_inspect_result_ SOCKET WSPAPI WSPAccept ( _In_ SOCKET  s,
_Out_writes_bytes_to_opt_ *, *addrlen struct sockaddr FAR addr,
_Inout_opt_ LPINT  addrlen,
_In_opt_ LPCONDITIONPROC  lpfnCondition,
_In_opt_ DWORD_PTR  dwCallbackData,
_Out_ LPINT  lpErrno 
)

Definition at line 1434 of file dllmain.c.

1441 {
1442  IO_STATUS_BLOCK IOSB;
1443  PAFD_RECEIVED_ACCEPT_DATA ListenReceiveData;
1444  AFD_ACCEPT_DATA AcceptData;
1445  AFD_DEFER_ACCEPT_DATA DeferData;
1446  AFD_PENDING_ACCEPT_DATA PendingAcceptData;
1447  PSOCKET_INFORMATION Socket = NULL;
1448  NTSTATUS Status;
1449  struct fd_set ReadSet;
1450  struct timeval Timeout;
1451  PVOID PendingData = NULL;
1452  ULONG PendingDataLength = 0;
1453  PVOID CalleeDataBuffer;
1454  WSABUF CallerData, CalleeID, CallerID, CalleeData;
1456  GROUP GroupID = 0;
1457  ULONG CallBack;
1459  PSOCKET_INFORMATION AcceptSocketInfo;
1460  UCHAR ReceiveBuffer[0x1A];
1461  HANDLE SockEvent;
1462 
1463  /* Get the Socket Structure associate to this Socket*/
1464  Socket = GetSocketStructure(Handle);
1465  if (!Socket)
1466  {
1467  if (lpErrno) *lpErrno = WSAENOTSOCK;
1468  return SOCKET_ERROR;
1469  }
1470  if (!Socket->SharedData->Listening)
1471  {
1472  if (lpErrno) *lpErrno = WSAEINVAL;
1473  return SOCKET_ERROR;
1474  }
1475  if ((SocketAddress && !SocketAddressLength) ||
1476  (SocketAddressLength && !SocketAddress) ||
1477  (SocketAddressLength && *SocketAddressLength < sizeof(SOCKADDR)))
1478  {
1479  if (lpErrno) *lpErrno = WSAEFAULT;
1480  return INVALID_SOCKET;
1481  }
1482 
1485  NULL,
1487  FALSE);
1488 
1489  if( !NT_SUCCESS(Status) )
1490  {
1491  return SOCKET_ERROR;
1492  }
1493 
1494  /* Dynamic Structure...ugh */
1495  ListenReceiveData = (PAFD_RECEIVED_ACCEPT_DATA)ReceiveBuffer;
1496 
1497  /* If this is non-blocking, make sure there's something for us to accept */
1498  FD_ZERO(&ReadSet);
1499  FD_SET(Socket->Handle, &ReadSet);
1500  Timeout.tv_sec=0;
1501  Timeout.tv_usec=0;
1502 
1503  if (WSPSelect(0, &ReadSet, NULL, NULL, &Timeout, lpErrno) == SOCKET_ERROR)
1504  {
1505  NtClose(SockEvent);
1506  return SOCKET_ERROR;
1507  }
1508 
1509  if (ReadSet.fd_array[0] != Socket->Handle)
1510  {
1511  NtClose(SockEvent);
1512  if (lpErrno) *lpErrno = WSAEWOULDBLOCK;
1513  return SOCKET_ERROR;
1514  }
1515 
1516  /* Send IOCTL */
1518  SockEvent,
1519  NULL,
1520  NULL,
1521  &IOSB,
1523  NULL,
1524  0,
1525  ListenReceiveData,
1526  0xA + sizeof(*ListenReceiveData));
1527 
1528  /* Wait for return */
1529  if (Status == STATUS_PENDING)
1530  {
1532  Status = IOSB.Status;
1533  }
1534 
1535  if (!NT_SUCCESS(Status))
1536  {
1537  NtClose( SockEvent );
1538  return MsafdReturnWithErrno( Status, lpErrno, 0, NULL );
1539  }
1540 
1541  if (lpfnCondition != NULL)
1542  {
1543  if ((Socket->SharedData->ServiceFlags1 & XP1_CONNECT_DATA) != 0)
1544  {
1545  /* Find out how much data is pending */
1546  PendingAcceptData.SequenceNumber = ListenReceiveData->SequenceNumber;
1547  PendingAcceptData.ReturnSize = TRUE;
1548 
1549  /* Send IOCTL */
1551  SockEvent,
1552  NULL,
1553  NULL,
1554  &IOSB,
1556  &PendingAcceptData,
1557  sizeof(PendingAcceptData),
1558  &PendingAcceptData,
1559  sizeof(PendingAcceptData));
1560 
1561  /* Wait for return */
1562  if (Status == STATUS_PENDING)
1563  {
1565  Status = IOSB.Status;
1566  }
1567 
1568  if (!NT_SUCCESS(Status))
1569  {
1570  NtClose( SockEvent );
1571  return MsafdReturnWithErrno( Status, lpErrno, 0, NULL );
1572  }
1573 
1574  /* How much data to allocate */
1575  PendingDataLength = IOSB.Information;
1576 
1577  if (PendingDataLength)
1578  {
1579  /* Allocate needed space */
1580  PendingData = HeapAlloc(GlobalHeap, 0, PendingDataLength);
1581  if (!PendingData)
1582  {
1584  }
1585 
1586  /* We want the data now */
1587  PendingAcceptData.ReturnSize = FALSE;
1588 
1589  /* Send IOCTL */
1591  SockEvent,
1592  NULL,
1593  NULL,
1594  &IOSB,
1596  &PendingAcceptData,
1597  sizeof(PendingAcceptData),
1598  PendingData,
1599  PendingDataLength);
1600 
1601  /* Wait for return */
1602  if (Status == STATUS_PENDING)
1603  {
1605  Status = IOSB.Status;
1606  }
1607 
1608  if (!NT_SUCCESS(Status))
1609  {
1610  NtClose( SockEvent );
1611  return MsafdReturnWithErrno( Status, lpErrno, 0, NULL );
1612  }
1613  }
1614  }
1615 
1616  if ((Socket->SharedData->ServiceFlags1 & XP1_QOS_SUPPORTED) != 0)
1617  {
1618  /* I don't support this yet */
1619  }
1620 
1621  /* Build Callee ID */
1622  CalleeID.buf = (PVOID)Socket->LocalAddress;
1623  CalleeID.len = Socket->SharedData->SizeOfLocalAddress;
1624 
1626  if (!RemoteAddress)
1627  {
1629  }
1630 
1631  /* Set up Address in SOCKADDR Format */
1633  &ListenReceiveData->Address.Address[0].AddressType,
1634  sizeof(*RemoteAddress));
1635 
1636  /* Build Caller ID */
1637  CallerID.buf = (PVOID)RemoteAddress;
1638  CallerID.len = sizeof(*RemoteAddress);
1639 
1640  /* Build Caller Data */
1641  CallerData.buf = PendingData;
1642  CallerData.len = PendingDataLength;
1643 
1644  /* Check if socket supports Conditional Accept */
1645  if (Socket->SharedData->UseDelayedAcceptance != 0)
1646  {
1647  /* Allocate Buffer for Callee Data */
1648  CalleeDataBuffer = HeapAlloc(GlobalHeap, 0, 4096);
1649  if (!CalleeDataBuffer) {
1651  }
1652  CalleeData.buf = CalleeDataBuffer;
1653  CalleeData.len = 4096;
1654  }
1655  else
1656  {
1657  /* Nothing */
1658  CalleeData.buf = 0;
1659  CalleeData.len = 0;
1660  }
1661 
1662  /* Call the Condition Function */
1663  CallBack = (lpfnCondition)(&CallerID,
1664  CallerData.buf == NULL ? NULL : &CallerData,
1665  NULL,
1666  NULL,
1667  &CalleeID,
1668  CalleeData.buf == NULL ? NULL : &CalleeData,
1669  &GroupID,
1670  dwCallbackData);
1671 
1672  if (((CallBack == CF_ACCEPT) && GroupID) != 0)
1673  {
1674  /* TBD: Check for Validity */
1675  }
1676 
1677  if (CallBack == CF_ACCEPT)
1678  {
1679  if ((Socket->SharedData->ServiceFlags1 & XP1_QOS_SUPPORTED) != 0)
1680  {
1681  /* I don't support this yet */
1682  }
1683  if (CalleeData.buf)
1684  {
1685  // SockSetConnectData Sockets(SocketID), IOCTL_AFD_SET_CONNECT_DATA, CalleeData.Buffer, CalleeData.BuffSize, 0
1686  }
1687  }
1688  else
1689  {
1690  /* Callback rejected. Build Defer Structure */
1691  DeferData.SequenceNumber = ListenReceiveData->SequenceNumber;
1692  DeferData.RejectConnection = (CallBack == CF_REJECT);
1693 
1694  /* Send IOCTL */
1696  SockEvent,
1697  NULL,
1698  NULL,
1699  &IOSB,
1701  &DeferData,
1702  sizeof(DeferData),
1703  NULL,
1704  0);
1705 
1706  /* Wait for return */
1707  if (Status == STATUS_PENDING)
1708  {
1710  Status = IOSB.Status;
1711  }
1712 
1713  NtClose( SockEvent );
1714 
1715  if (!NT_SUCCESS(Status))
1716  {
1717  return MsafdReturnWithErrno( Status, lpErrno, 0, NULL );
1718  }
1719 
1720  if (CallBack == CF_REJECT )
1721  {
1722  if (lpErrno) *lpErrno = WSAECONNREFUSED;
1723  return SOCKET_ERROR;
1724  }
1725  else
1726  {
1727  if (lpErrno) *lpErrno = WSAECONNREFUSED;
1728  return SOCKET_ERROR;
1729  }
1730  }
1731  }
1732 
1733  /* Create a new Socket */
1735  Socket->SharedData->SocketType,
1736  Socket->SharedData->Protocol,
1737  &Socket->ProtocolInfo,
1738  GroupID,
1739  Socket->SharedData->CreateFlags,
1740  lpErrno);
1742  return SOCKET_ERROR;
1743 
1744  /* Set up the Accept Structure */
1745  AcceptData.ListenHandle = (HANDLE)AcceptSocket;
1746  AcceptData.SequenceNumber = ListenReceiveData->SequenceNumber;
1747 
1748  /* Send IOCTL to Accept */
1750  SockEvent,
1751  NULL,
1752  NULL,
1753  &IOSB,
1755  &AcceptData,
1756  sizeof(AcceptData),
1757  NULL,
1758  0);
1759 
1760  /* Wait for return */
1761  if (Status == STATUS_PENDING)
1762  {
1764  Status = IOSB.Status;
1765  }
1766 
1768  if (!NT_SUCCESS(Status))
1769  {
1770  NtClose(SockEvent);
1771  WSPCloseSocket( AcceptSocket, lpErrno );
1772  return MsafdReturnWithErrno( Status, lpErrno, 0, NULL );
1773  }
1774 
1775  AcceptSocketInfo = GetSocketStructure(AcceptSocket);
1776  if (!AcceptSocketInfo)
1777  {
1778  NtClose(SockEvent);
1779  WSPCloseSocket( AcceptSocket, lpErrno );
1781  }
1782 
1783  AcceptSocketInfo->SharedData->State = SocketConnected;
1784  AcceptSocketInfo->SharedData->ConnectTime = GetCurrentTimeInSeconds();
1785 
1786  /* Return Address in SOCKADDR FORMAT */
1787  if( SocketAddress )
1788  {
1789  RtlCopyMemory (SocketAddress,
1790  &ListenReceiveData->Address.Address[0].AddressType,
1791  sizeof(*RemoteAddress));
1792  if( SocketAddressLength )
1793  *SocketAddressLength = sizeof(*RemoteAddress);
1794  }
1795 
1796  NtClose( SockEvent );
1797 
1798  /* Re-enable Async Event */
1800 
1801  TRACE("Socket %x\n", AcceptSocket);
1802 
1803  if (Status == STATUS_SUCCESS && (Socket->HelperEvents & WSH_NOTIFY_ACCEPT))
1804  {
1805  Status = Socket->HelperData->WSHNotify(Socket->HelperContext,
1806  Socket->Handle,
1807  Socket->TdiAddressHandle,
1808  Socket->TdiConnectionHandle,
1810 
1811  if (Status)
1812  {
1813  if (lpErrno) *lpErrno = Status;
1814  return SOCKET_ERROR;
1815  }
1816  }
1817 
1818  if (lpErrno) *lpErrno = NO_ERROR;
1819 
1820  /* Return Socket */
1821  return AcceptSocket;
1822 }
Definition: winsock.h:66
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
INT WSPAPI WSPCloseSocket(IN SOCKET Handle, OUT LPINT lpErrno)
Definition: dllmain.c:623
#define STATUS_PROTOCOL_NOT_SUPPORTED
Definition: ntstatus.h:1177
INT AddressFamily
Definition: msafd.h:56
HANDLE SockEvent
TRANSPORT_ADDRESS Address
Definition: shared.h:70
BOOLEAN Listening
Definition: msafd.h:68
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
BOOLEAN RejectConnection
Definition: shared.h:81
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define WSAEFAULT
Definition: winerror.h:1945
#define FD_ACCEPT
Definition: winsock.h:408
VOID SockReenableAsyncSelectEvent(IN PSOCKET_INFORMATION Socket, IN ULONG Event)
Definition: dllmain.c:3987
#define TRUE
Definition: types.h:120
#define WSAEINVAL
Definition: winerror.h:1946
ULONG ConnectTime
Definition: msafd.h:66
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
struct _AFD_RECEIVED_ACCEPT_DATA * PAFD_RECEIVED_ACCEPT_DATA
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
#define CF_REJECT
Definition: winsock2.h:414
#define XP1_QOS_SUPPORTED
Definition: winsock2.h:449
BOOLEAN UseDelayedAcceptance
Definition: msafd.h:78
#define WSH_NOTIFY_ACCEPT
Definition: wsahelp.h:13
#define IOCTL_AFD_GET_PENDING_CONNECT_DATA
Definition: shared.h:333
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89
#define IOCTL_AFD_WAIT_FOR_LISTEN
Definition: shared.h:273
#define NO_ERROR
Definition: dderror.h:5
DWORD GetCurrentTimeInSeconds(VOID)
Definition: dllmain.c:1417
WSAPROTOCOL_INFOW ProtocolInfo
Definition: msafd.h:115
DWORD CreateFlags
Definition: msafd.h:81
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
ULONG SequenceNumber
Definition: shared.h:64
smooth NULL
Definition: ftsmooth.c:416
PHELPER_DATA HelperData
Definition: msafd.h:103
#define CF_ACCEPT
Definition: winsock2.h:413
void * PVOID
Definition: retypes.h:9
_In_ HANDLE Handle
Definition: extypes.h:390
DWORD ServiceFlags1
Definition: msafd.h:82
#define TRACE(s)
Definition: solgame.cpp:4
DWORD HelperEvents
Definition: msafd.h:102
#define IOCTL_AFD_DEFER_ACCEPT
Definition: shared.h:331
INT SocketType
Definition: msafd.h:57
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define INVALID_SOCKET
Definition: winsock.h:332
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
SOCKET WSPAPI WSPSocket(int AddressFamily, int SocketType, int Protocol, LPWSAPROTOCOL_INFOW lpProtocolInfo, GROUP g, DWORD dwFlags, LPINT lpErrno)
Definition: dllmain.c:48
ULONG len
Definition: ws2def.h:519
unsigned int GROUP
Definition: winsock2.h:640
PWSH_NOTIFY WSHNotify
Definition: helpers.h:25
PVOID HANDLE
Definition: typedefs.h:73
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define IOCTL_AFD_ACCEPT
Definition: shared.h:275
INT SizeOfLocalAddress
Definition: msafd.h:59
#define XP1_CONNECT_DATA
Definition: winsock2.h:443
USHORT AddressType
Definition: tdi.h:339
HANDLE TdiConnectionHandle
Definition: msafd.h:108
HANDLE TdiAddressHandle
Definition: msafd.h:107
HANDLE GlobalHeap
Definition: dllmain.c:19
CHAR FAR * buf
Definition: ws2def.h:520
TA_ADDRESS Address[1]
Definition: tdi.h:377
int WSPAPI WSPSelect(IN int nfds, IN OUT fd_set *readfds OPTIONAL, IN OUT fd_set *writefds OPTIONAL, IN OUT fd_set *exceptfds OPTIONAL, IN const struct timeval *timeout OPTIONAL, OUT LPINT lpErrno)
Definition: dllmain.c:1065
static ULONG Timeout
Definition: ping.c:61
PSOCKADDR LocalAddress
Definition: msafd.h:105
INT TranslateNtStatusError(NTSTATUS Status)
Definition: dllmain.c:537
INT SocketLastError
Definition: msafd.h:87
HANDLE ListenHandle
Definition: shared.h:65
SOCKET_STATE State
Definition: msafd.h:54
#define WSAECONNREFUSED
Definition: winerror.h:1974
unsigned int ULONG
Definition: retypes.h:1
UINT_PTR SOCKET
Definition: winsock.h:47
PVOID HelperContext
Definition: msafd.h:104
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _In_opt_ PWSK_SOCKET AcceptSocket
Definition: wsk.h:170
#define INFINITE
Definition: serial.h:102
return STATUS_SUCCESS
Definition: btrfs.c:3014
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR RemoteAddress
Definition: wsk.h:170

Referenced by WSPStartup().

◆ WSPAcceptEx()

BOOL WSPAPI WSPAcceptEx ( IN SOCKET  sListenSocket,
IN SOCKET  sAcceptSocket,
OUT PVOID  lpOutputBuffer,
IN DWORD  dwReceiveDataLength,
IN DWORD  dwLocalAddressLength,
IN DWORD  dwRemoteAddressLength,
OUT LPDWORD  lpdwBytesReceived,
IN OUT LPOVERLAPPED  lpOverlapped 
)

Definition at line 58 of file stubs.c.

67 {
69 
70  return FALSE;
71 }
#define UNIMPLEMENTED
Definition: stubs.c:20
#define FALSE
Definition: types.h:117

Referenced by WSPIoctl().

◆ WSPAddressToString()

INT WSPAPI WSPAddressToString ( IN LPSOCKADDR  lpsaAddress,
IN DWORD  dwAddressLength,
IN LPWSAPROTOCOL_INFOW  lpProtocolInfo,
OUT LPWSTR  lpszAddressString,
IN OUT LPDWORD  lpdwAddressStringLength,
OUT LPINT  lpErrno 
)

Definition at line 3054 of file dllmain.c.

3060 {
3061  SIZE_T size;
3062  WCHAR buffer[54]; /* 32 digits + 7':' + '[' + '%" + 5 digits + ']:' + 5 digits + '\0' */
3063  WCHAR *p;
3064 
3065  if (!lpsaAddress || !lpszAddressString || !lpdwAddressStringLength)
3066  {
3067  if (lpErrno) *lpErrno = WSAEFAULT;
3068  return SOCKET_ERROR;
3069  }
3070 
3071  switch (lpsaAddress->sa_family)
3072  {
3073  case AF_INET:
3074  if (dwAddressLength < sizeof(SOCKADDR_IN))
3075  {
3076  if (lpErrno) *lpErrno = WSAEINVAL;
3077  return SOCKET_ERROR;
3078  }
3079  swprintf(buffer,
3080  L"%u.%u.%u.%u:%u",
3081  (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) >> 24 & 0xff),
3082  (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) >> 16 & 0xff),
3083  (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) >> 8 & 0xff),
3084  (unsigned int)(ntohl(((SOCKADDR_IN *)lpsaAddress)->sin_addr.s_addr) & 0xff),
3085  ntohs(((SOCKADDR_IN *)lpsaAddress)->sin_port));
3086 
3087  p = wcschr(buffer, L':');
3088  if (!((SOCKADDR_IN *)lpsaAddress)->sin_port)
3089  {
3090  *p = 0;
3091  }
3092  break;
3093  default:
3094  if (lpErrno) *lpErrno = WSAEINVAL;
3095  return SOCKET_ERROR;
3096  }
3097 
3098  size = wcslen(buffer) + 1;
3099 
3100  if (*lpdwAddressStringLength < size)
3101  {
3102  *lpdwAddressStringLength = size;
3103  if (lpErrno) *lpErrno = WSAEFAULT;
3104  return SOCKET_ERROR;
3105  }
3106 
3107  *lpdwAddressStringLength = size;
3108  wcscpy(lpszAddressString, buffer);
3109  return 0;
3110 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define WSAEFAULT
Definition: winerror.h:1945
#define WSAEINVAL
Definition: winerror.h:1946
GLuint buffer
Definition: glext.h:5915
#define ntohs(x)
Definition: module.h:208
GLsizeiptr size
Definition: glext.h:5919
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define AF_INET
Definition: tcpip.h:117
GLfloat GLfloat p
Definition: glext.h:8902
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ntohl(x)
Definition: module.h:203

◆ WSPAsyncSelect()

INT WSPAPI WSPAsyncSelect ( IN SOCKET  s,
IN HWND  hWnd,
IN UINT  wMsg,
IN LONG  lEvent,
OUT LPINT  lpErrno 
)

Definition at line 17 of file sndrcv.c.

22 {
23  PSOCKET_INFORMATION Socket = NULL;
24  PASYNC_DATA AsyncData;
25  BOOLEAN BlockMode;
26 
27  /* Get the Socket Structure associated to this Socket */
28  Socket = GetSocketStructure(Handle);
29  if (!Socket)
30  {
31  *lpErrno = WSAENOTSOCK;
32  return SOCKET_ERROR;
33  }
34 
35  /* Allocate the Async Data Structure to pass on to the Thread later */
36  AsyncData = HeapAlloc(GetProcessHeap(), 0, sizeof(*AsyncData));
37  if (!AsyncData)
38  {
40  return INVALID_SOCKET;
41  }
42 
43  /* Change the Socket to Non Blocking */
44  BlockMode = TRUE;
46  Socket->SharedData->NonBlocking = TRUE;
47 
48  /* Deactivate WSPEventSelect */
49  if (Socket->SharedData->AsyncEvents)
50  {
51  if (WSPEventSelect(Handle, NULL, 0, lpErrno) == SOCKET_ERROR)
52  {
53  HeapFree(GetProcessHeap(), 0, AsyncData);
54  return SOCKET_ERROR;
55  }
56  }
57 
58  /* Create the Asynch Thread if Needed */
60 
61  /* Open a Handle to AFD's Async Helper */
63 
64  /* Store Socket Data */
65  Socket->SharedData->hWnd = hWnd;
66  Socket->SharedData->wMsg = wMsg;
67  Socket->SharedData->AsyncEvents = lEvent;
68  Socket->SharedData->AsyncDisabledEvents = 0;
69  Socket->SharedData->SequenceNumber++;
70 
71  /* Return if there are no more Events */
72  if ((Socket->SharedData->AsyncEvents & (~Socket->SharedData->AsyncDisabledEvents)) == 0)
73  {
74  HeapFree(GetProcessHeap(), 0, AsyncData);
75  return 0;
76  }
77 
78  /* Set up the Async Data */
79  AsyncData->ParentSocket = Socket;
80  AsyncData->SequenceNumber = Socket->SharedData->SequenceNumber;
81 
82  /* Begin Async Select by using I/O Completion */
85  AsyncData,
86  0,
87  0);
88 
89  /* Return */
90  return ERROR_SUCCESS;
91 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
DWORD SequenceNumber
Definition: msafd.h:131
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOLEAN SockGetAsyncSelectHelperAfdHandle(VOID)
Definition: dllmain.c:3679
#define TRUE
Definition: types.h:120
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
HANDLE SockAsyncCompletionPort
Definition: dllmain.c:28
HWND hWnd
Definition: settings.c:17
DWORD SequenceNumber
Definition: msafd.h:90
BOOLEAN SockCreateOrReferenceAsyncThread(VOID)
Definition: dllmain.c:3584
VOID SockProcessQueuedAsyncSelect(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock)
Definition: dllmain.c:3953
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
BOOLEAN NonBlocking
Definition: msafd.h:74
_In_ HANDLE Handle
Definition: extypes.h:390
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define INVALID_SOCKET
Definition: winsock.h:332
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtSetIoCompletion(IN HANDLE IoCompletionPortHandle, IN PVOID CompletionKey, IN PVOID CompletionContext, IN NTSTATUS CompletionStatus, IN ULONG CompletionInformation)
Definition: iocomp.c:568
PSOCKET_INFORMATION ParentSocket
Definition: msafd.h:130
int WSPAPI WSPEventSelect(IN SOCKET Handle, IN WSAEVENT hEventObject, IN long lNetworkEvents, OUT LPINT lpErrno)
Definition: event.c:17
HANDLE lEvent
Definition: tftpd.cpp:56
int SetSocketInformation(PSOCKET_INFORMATION Socket, ULONG AfdInformationClass, PBOOLEAN Boolean OPTIONAL, PULONG Ulong OPTIONAL, PLARGE_INTEGER LargeInteger OPTIONAL, LPWSAOVERLAPPED Overlapped OPTIONAL, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL)
Definition: dllmain.c:3388
LONG AsyncDisabledEvents
Definition: msafd.h:93
LONG AsyncEvents
Definition: msafd.h:92
#define HeapFree(x, y, z)
Definition: compat.h:483

◆ WSPBind()

INT WSPAPI WSPBind ( IN SOCKET  s,
IN CONST SOCKADDR name,
IN INT  namelen,
OUT LPINT  lpErrno 
)

◆ WSPCancelBlockingCall()

INT WSPAPI WSPCancelBlockingCall ( OUT LPINT  lpErrno)

Definition at line 15 of file stubs.c.

17 {
19 
20  return 0;
21 }
#define UNIMPLEMENTED
Definition: stubs.c:20

◆ WSPCleanup()

INT WSPAPI WSPCleanup ( OUT LPINT  lpErrno)

Definition at line 3238 of file dllmain.c.

3240 {
3241  TRACE("Leaving.\n");
3242 
3243  if (lpErrno) *lpErrno = NO_ERROR;
3244 
3245  return 0;
3246 }
#define NO_ERROR
Definition: dderror.h:5
#define TRACE(s)
Definition: solgame.cpp:4

◆ WSPCloseSocket()

INT WSPAPI WSPCloseSocket ( IN SOCKET  s,
OUT LPINT  lpErrno 
)

Definition at line 623 of file dllmain.c.

625 {
627  PSOCKET_INFORMATION Socket = NULL, CurrentSocket;
630  AFD_DISCONNECT_INFO DisconnectInfo;
631  SOCKET_STATE OldState;
632  LONG LingerWait = -1;
633  DWORD References;
634 
635  /* Get the Socket Structure associate to this Socket*/
636  Socket = GetSocketStructure(Handle);
637  if (!Socket)
638  {
639  if (lpErrno) *lpErrno = WSAENOTSOCK;
640  return SOCKET_ERROR;
641  }
642 
643  /* Create the Wait Event */
646  NULL,
648  FALSE);
649 
650  if(!NT_SUCCESS(Status))
651  {
652  ERR("NtCreateEvent failed: 0x%08x", Status);
653  return SOCKET_ERROR;
654  }
655 
656  if (Socket->HelperEvents & WSH_NOTIFY_CLOSE)
657  {
658  Status = Socket->HelperData->WSHNotify(Socket->HelperContext,
659  Socket->Handle,
660  Socket->TdiAddressHandle,
661  Socket->TdiConnectionHandle,
663 
664  if (Status)
665  {
666  if (lpErrno) *lpErrno = Status;
667  ERR("WSHNotify failed. Error 0x%#x", Status);
669  return SOCKET_ERROR;
670  }
671  }
672 
673  /* If a Close is already in Process, give up */
674  if (Socket->SharedData->State == SocketClosed)
675  {
676  WARN("Socket is closing.\n");
678  if (lpErrno) *lpErrno = WSAENOTSOCK;
679  return SOCKET_ERROR;
680  }
681 
682  /* Decrement reference count on SharedData */
683  References = InterlockedDecrement(&Socket->SharedData->RefCount);
684  if (References)
685  goto ok;
686 
687  /* Set the state to close */
688  OldState = Socket->SharedData->State;
689  Socket->SharedData->State = SocketClosed;
690 
691  /* If SO_LINGER is ON and the Socket is connected, we need to disconnect */
692  /* FIXME: Should we do this on Datagram Sockets too? */
693  if ((OldState == SocketConnected) && (Socket->SharedData->LingerData.l_onoff))
694  {
695  ULONG SendsInProgress;
696  ULONG SleepWait;
697 
698  /* We need to respect the timeout */
699  SleepWait = 100;
700  LingerWait = Socket->SharedData->LingerData.l_linger * 1000;
701 
702  /* Loop until no more sends are pending, within the timeout */
703  while (LingerWait)
704  {
705  /* Find out how many Sends are in Progress */
706  if (GetSocketInformation(Socket,
708  NULL,
709  &SendsInProgress,
710  NULL,
711  NULL,
712  NULL))
713  {
714  /* Bail out if anything but NO_ERROR */
715  LingerWait = 0;
716  break;
717  }
718 
719  /* Bail out if no more sends are pending */
720  if (!SendsInProgress)
721  {
722  LingerWait = -1;
723  break;
724  }
725 
726  /*
727  * We have to execute a sleep, so it's kind of like
728  * a block. If the socket is Nonblock, we cannot
729  * go on since asynchronous operation is expected
730  * and we cannot offer it
731  */
732  if (Socket->SharedData->NonBlocking)
733  {
734  WARN("Would block!\n");
736  Socket->SharedData->State = OldState;
737  if (lpErrno) *lpErrno = WSAEWOULDBLOCK;
738  return SOCKET_ERROR;
739  }
740 
741  /* Now we can sleep, and decrement the linger wait */
742  /*
743  * FIXME: It seems Windows does some funky acceleration
744  * since the waiting seems to be longer and longer. I
745  * don't think this improves performance so much, so we
746  * wait a fixed time instead.
747  */
748  Sleep(SleepWait);
749  LingerWait -= SleepWait;
750  }
751  }
752 
753  if (OldState == SocketConnected)
754  {
755  if (LingerWait <= 0)
756  {
757  DisconnectInfo.Timeout = RtlConvertLongToLargeInteger(0);
758  DisconnectInfo.DisconnectType = LingerWait < 0 ? AFD_DISCONNECT_SEND : AFD_DISCONNECT_ABORT;
759 
760  if (((DisconnectInfo.DisconnectType & AFD_DISCONNECT_SEND) && (!Socket->SharedData->SendShutdown)) ||
761  ((DisconnectInfo.DisconnectType & AFD_DISCONNECT_ABORT) && (!Socket->SharedData->ReceiveShutdown)))
762  {
763  /* Send IOCTL */
765  SockEvent,
766  NULL,
767  NULL,
768  &IoStatusBlock,
770  &DisconnectInfo,
771  sizeof(DisconnectInfo),
772  NULL,
773  0);
774 
775  /* Wait for return */
776  if (Status == STATUS_PENDING)
777  {
780  }
781  }
782  }
783  }
784 
785  /* Cleanup Time! */
786  Socket->HelperContext = NULL;
787  Socket->SharedData->AsyncDisabledEvents = -1;
788  NtClose(Socket->TdiAddressHandle);
789  Socket->TdiAddressHandle = NULL;
790  NtClose(Socket->TdiConnectionHandle);
791  Socket->TdiConnectionHandle = NULL;
792 ok:
794  if (SocketListHead == Socket)
795  {
797  }
798  else
799  {
800  CurrentSocket = SocketListHead;
801  while (CurrentSocket->NextSocket)
802  {
803  if (CurrentSocket->NextSocket == Socket)
804  {
805  CurrentSocket->NextSocket = CurrentSocket->NextSocket->NextSocket;
806  break;
807  }
808 
809  CurrentSocket = CurrentSocket->NextSocket;
810  }
811  }
813 
814  /* Close the handle */
817 
818  if( Socket->SharedDataHandle != INVALID_HANDLE_VALUE )
819  {
820  /* It is a duplicated socket, so unmap the memory */
821  UnmapViewOfFile(Socket->SharedData);
822  NtClose(Socket->SharedDataHandle);
823  Socket->SharedData = NULL;
824  }
825  if( !References && Socket->SharedData )
826  {
827  HeapFree(GlobalHeap, 0, Socket->SharedData);
828  }
829  HeapFree(GlobalHeap, 0, Socket);
830  return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
831 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
NTSYSAPI LONGLONG WINAPI RtlConvertLongToLargeInteger(LONG)
Definition: largeint.c:31
HANDLE SockEvent
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
#define WARN(fmt,...)
Definition: debug.h:112
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
#define WSAEWOULDBLOCK
Definition: winerror.h:1948
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
BOOLEAN SendShutdown
Definition: msafd.h:77
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
int GetSocketInformation(PSOCKET_INFORMATION Socket, ULONG AfdInformationClass, PBOOLEAN Boolean OPTIONAL, PULONG Ulong OPTIONAL, PLARGE_INTEGER LargeInteger OPTIONAL, LPWSAOVERLAPPED Overlapped OPTIONAL, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL)
Definition: dllmain.c:3261
struct _SOCKET_INFORMATION * NextSocket
Definition: msafd.h:116
#define IOCTL_AFD_DISCONNECT
Definition: shared.h:287
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
enum _SOCKET_STATE SOCKET_STATE
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER Timeout
Definition: shared.h:137
PHELPER_DATA HelperData
Definition: msafd.h:103
#define AFD_DISCONNECT_SEND
Definition: shared.h:197
BOOLEAN ReceiveShutdown
Definition: msafd.h:76
LONG RefCount
Definition: msafd.h:55
BOOLEAN NonBlocking
Definition: msafd.h:74
_In_ HANDLE Handle
Definition: extypes.h:390
DWORD HelperEvents
Definition: msafd.h:102
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
PWSH_NOTIFY WSHNotify
Definition: helpers.h:25
unsigned long DWORD
Definition: ntddk_ex.h:95
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define AFD_DISCONNECT_ABORT
Definition: shared.h:199
Status
Definition: gdiplustypes.h:24
#define InterlockedDecrement
Definition: armddk.h:52
HANDLE TdiConnectionHandle
Definition: msafd.h:108
HANDLE TdiAddressHandle
Definition: msafd.h:107
HANDLE GlobalHeap
Definition: dllmain.c:19
#define ERR(fmt,...)
Definition: debug.h:110
#define AFD_INFO_SENDS_IN_PROGRESS
Definition: shared.h:184
struct linger LingerData
Definition: msafd.h:61
LONG AsyncDisabledEvents
Definition: msafd.h:93
#define ok(value,...)
Definition: atltest.h:57
#define WSH_NOTIFY_CLOSE
Definition: wsahelp.h:17
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
ULONG DisconnectType
Definition: shared.h:136
SOCKET_STATE State
Definition: msafd.h:54
CRITICAL_SECTION SocketListLock
Definition: dllmain.c:24
unsigned int ULONG
Definition: retypes.h:1
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
PVOID HelperContext
Definition: msafd.h:104
#define INFINITE
Definition: serial.h:102
#define UnmapViewOfFile
Definition: compat.h:494
PSOCKET_INFORMATION SocketListHead
Definition: dllmain.c:23
HANDLE SharedDataHandle
Definition: msafd.h:101
#define HeapFree(x, y, z)
Definition: compat.h:483

◆ WSPConnect()

INT WSPAPI WSPConnect ( IN SOCKET  s,
IN CONST SOCKADDR name,
IN INT  namelen,
IN LPWSABUF  lpCallerData,
OUT LPWSABUF  lpCalleeData,
IN LPQOS  lpSQOS,
IN LPQOS  lpGQOS,
OUT LPINT  lpErrno 
)

◆ WSPConnectEx()

BOOL WSPAPI WSPConnectEx ( IN SOCKET  s,
IN const struct sockaddr name,
IN int  namelen,
IN PVOID  lpSendBuffer,
IN DWORD  dwSendDataLength,
OUT LPDWORD  lpdwBytesSent,
IN OUT LPOVERLAPPED  lpOverlapped 
)

Definition at line 75 of file stubs.c.

83 {
85 
86  return FALSE;
87 }
#define UNIMPLEMENTED
Definition: stubs.c:20
#define FALSE
Definition: types.h:117

Referenced by WSPIoctl().

◆ WSPDisconnectEx()

BOOL WSPAPI WSPDisconnectEx ( IN SOCKET  hSocket,
IN LPOVERLAPPED  lpOverlapped,
IN DWORD  dwFlags,
IN DWORD  reserved 
)

Definition at line 91 of file stubs.c.

96 {
98 
99  return FALSE;
100 }
#define UNIMPLEMENTED
Definition: stubs.c:20
#define FALSE
Definition: types.h:117

Referenced by WSPIoctl().

◆ WSPDuplicateSocket()

INT WSPAPI WSPDuplicateSocket ( IN SOCKET  s,
IN DWORD  dwProcessId,
OUT LPWSAPROTOCOL_INFOW  lpProtocolInfo,
OUT LPINT  lpErrno 
)

Definition at line 449 of file dllmain.c.

454 {
455  HANDLE hProcess, hDuplicatedSharedData, hDuplicatedHandle;
456  PSOCKET_INFORMATION Socket;
457  PSOCK_SHARED_INFO pSharedData, pOldSharedData;
458  BOOL bDuplicated;
459 
460  if (Handle == INVALID_SOCKET)
462  Socket = GetSocketStructure(Handle);
463  if( !Socket )
464  {
465  if( lpErrno )
466  *lpErrno = WSAENOTSOCK;
467  return SOCKET_ERROR;
468  }
469  if ( !(hProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, dwProcessId)) )
471 
472  /* It is a not yet duplicated socket, so map the memory, copy the SharedData and free heap */
473  if( Socket->SharedDataHandle == INVALID_HANDLE_VALUE )
474  {
476  NULL,
478  0,
479  (sizeof(SOCK_SHARED_INFO) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1),
480  NULL);
481  if( Socket->SharedDataHandle == INVALID_HANDLE_VALUE )
483  pSharedData = MapViewOfFile(Socket->SharedDataHandle,
485  0,
486  0,
487  sizeof(SOCK_SHARED_INFO));
488 
489  RtlCopyMemory(pSharedData, Socket->SharedData, sizeof(SOCK_SHARED_INFO));
490  pOldSharedData = Socket->SharedData;
491  Socket->SharedData = pSharedData;
492  HeapFree(GlobalHeap, 0, pOldSharedData);
493  }
494  /* Duplicate the handles for the new process */
495  bDuplicated = DuplicateHandle(GetCurrentProcess(),
496  Socket->SharedDataHandle,
497  hProcess,
498  (LPHANDLE)&hDuplicatedSharedData,
499  0,
500  FALSE,
502  if (!bDuplicated)
503  {
504  NtClose(hProcess);
505  return MsafdReturnWithErrno(STATUS_ACCESS_DENIED, lpErrno, 0, NULL);
506  }
507  bDuplicated = DuplicateHandle(GetCurrentProcess(),
508  (HANDLE)Socket->Handle,
509  hProcess,
510  (LPHANDLE)&hDuplicatedHandle,
511  0,
512  FALSE,
514  NtClose(hProcess);
515  if( !bDuplicated )
516  return MsafdReturnWithErrno(STATUS_ACCESS_DENIED, lpErrno, 0, NULL);
517 
518 
519  if (!lpProtocolInfo)
521 
522  RtlCopyMemory(lpProtocolInfo, &Socket->ProtocolInfo, sizeof(*lpProtocolInfo));
523 
524  lpProtocolInfo->iAddressFamily = Socket->SharedData->AddressFamily;
525  lpProtocolInfo->iProtocol = Socket->SharedData->Protocol;
526  lpProtocolInfo->iSocketType = Socket->SharedData->SocketType;
527  lpProtocolInfo->dwServiceFlags3 = HandleToUlong(hDuplicatedSharedData);
528  lpProtocolInfo->dwServiceFlags4 = HandleToUlong(hDuplicatedHandle);
529 
530  if( lpErrno )
531  *lpErrno = NO_ERROR;
532 
533  return NO_ERROR;
534 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
INT AddressFamily
Definition: msafd.h:56
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define MapViewOfFile
Definition: compat.h:493
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
SOCKET Handle
Definition: msafd.h:99
#define HandleToUlong(h)
Definition: basetsd.h:79
#define CreateFileMapping
Definition: winbase.h:3590
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define NO_ERROR
Definition: dderror.h:5
WSAPROTOCOL_INFOW ProtocolInfo
Definition: msafd.h:115
#define DUPLICATE_SAME_ACCESS
#define SEC_COMMIT
Definition: mmtypes.h:99
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
#define PROCESS_DUP_HANDLE
smooth NULL
Definition: ftsmooth.c:416
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
_In_ HANDLE Handle
Definition: extypes.h:390
INT SocketType
Definition: msafd.h:57
#define INVALID_SOCKET
Definition: winsock.h:332
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define GetCurrentProcess()
Definition: compat.h:507
#define PAGE_SIZE
Definition: env_spec_w32.h:49
HANDLE GlobalHeap
Definition: dllmain.c:19
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
HANDLE SharedDataHandle
Definition: msafd.h:101
#define HeapFree(x, y, z)
Definition: compat.h:483
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
#define PAGE_READWRITE
Definition: nt_native.h:1304

◆ WSPEnumNetworkEvents()

INT WSPAPI WSPEnumNetworkEvents ( IN SOCKET  s,
IN WSAEVENT  hEventObject,
OUT LPWSANETWORKEVENTS  lpNetworkEvents,
OUT LPINT  lpErrno 
)

Definition at line 133 of file event.c.

138 {
140  IO_STATUS_BLOCK IOSB;
141  PSOCKET_INFORMATION Socket = NULL;
144 
145  TRACE("Called (lpNetworkEvents %x)\n", lpNetworkEvents);
146 
147  /* Get the Socket Structure associate to this Socket*/
148  Socket = GetSocketStructure(Handle);
149  if (!Socket)
150  {
151  if (lpErrno) *lpErrno = WSAENOTSOCK;
152  return SOCKET_ERROR;
153  }
154  if (!lpNetworkEvents)
155  {
156  if (lpErrno) *lpErrno = WSAEFAULT;
157  return SOCKET_ERROR;
158  }
159 
162 
163  if( !NT_SUCCESS(Status) ) {
164  ERR("Could not make an event %x\n", Status);
165  return SOCKET_ERROR;
166  }
167 
168  EnumReq.Event = hEventObject;
169 
170  /* Send IOCTL */
172  SockEvent,
173  NULL,
174  NULL,
175  &IOSB,
177  &EnumReq,
178  sizeof(EnumReq),
179  NULL,
180  0);
181 
182  /* Wait for return */
183  if (Status == STATUS_PENDING) {
185  Status = IOSB.Status;
186  }
187 
188  NtClose (SockEvent);
189 
190  if (Status != STATUS_SUCCESS)
191  {
192  ERR("Status 0x%08x", Status);
193  return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
194  }
195 
196  lpNetworkEvents->lNetworkEvents = 0;
197 
198  /* Set Events to wait for */
199  if (EnumReq.PollEvents & AFD_EVENT_RECEIVE) {
200  lpNetworkEvents->lNetworkEvents |= FD_READ;
201  lpNetworkEvents->iErrorCode[FD_READ_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_READ_BIT]);
202  }
203 
204  if (EnumReq.PollEvents & AFD_EVENT_SEND) {
205  lpNetworkEvents->lNetworkEvents |= FD_WRITE;
206  lpNetworkEvents->iErrorCode[FD_WRITE_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_WRITE_BIT]);
207  }
208 
209  if (EnumReq.PollEvents & AFD_EVENT_OOB_RECEIVE) {
210  lpNetworkEvents->lNetworkEvents |= FD_OOB;
211  lpNetworkEvents->iErrorCode[FD_OOB_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_OOB_BIT]);
212  }
213 
214  if (EnumReq.PollEvents & AFD_EVENT_ACCEPT) {
215  lpNetworkEvents->lNetworkEvents |= FD_ACCEPT;
216  lpNetworkEvents->iErrorCode[FD_ACCEPT_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_ACCEPT_BIT]);
217  }
218 
219  if (EnumReq.PollEvents &
221  lpNetworkEvents->lNetworkEvents |= FD_CONNECT;
222  lpNetworkEvents->iErrorCode[FD_CONNECT_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_CONNECT_BIT]);
223  }
224 
225  if (EnumReq.PollEvents &
227  lpNetworkEvents->lNetworkEvents |= FD_CLOSE;
228  lpNetworkEvents->iErrorCode[FD_CLOSE_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_CLOSE_BIT]);
229  }
230 
231  if (EnumReq.PollEvents & AFD_EVENT_QOS) {
232  lpNetworkEvents->lNetworkEvents |= FD_QOS;
233  lpNetworkEvents->iErrorCode[FD_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_QOS_BIT]);
234  }
235 
236  if (EnumReq.PollEvents & AFD_EVENT_GROUP_QOS) {
237  lpNetworkEvents->lNetworkEvents |= FD_GROUP_QOS;
238  lpNetworkEvents->iErrorCode[FD_GROUP_QOS_BIT] = TranslateNtStatusError(EnumReq.EventStatus[FD_GROUP_QOS_BIT]);
239  }
240 
241  TRACE("Leaving\n");
242 
243  return MsafdReturnWithErrno(STATUS_SUCCESS, lpErrno, 0, NULL);
244 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE SockEvent
#define WSAEFAULT
Definition: winerror.h:1945
#define AFD_EVENT_CONNECT_FAIL
Definition: shared.h:211
#define FD_ACCEPT
Definition: winsock.h:408
#define FD_CONNECT
Definition: winsock.h:409
#define AFD_EVENT_DISCONNECT
Definition: shared.h:206
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
LONG NTSTATUS
Definition: precomp.h:26
#define AFD_EVENT_ABORT
Definition: shared.h:207
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
#define FD_QOS_BIT
Definition: winsock2.h:305
#define FD_CONNECT_BIT
Definition: winsock2.h:301
#define FD_READ
Definition: winsock.h:405
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FD_OOB_BIT
Definition: winsock2.h:297
#define FD_OOB
Definition: winsock.h:407
#define FD_WRITE
Definition: winsock.h:406
#define AFD_EVENT_CLOSE
Definition: shared.h:208
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FD_GROUP_QOS
Definition: winsock2.h:308
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
smooth NULL
Definition: ftsmooth.c:416
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
#define FD_GROUP_QOS_BIT
Definition: winsock2.h:307
#define AFD_EVENT_CONNECT
Definition: shared.h:209
#define FD_READ_BIT
Definition: winsock2.h:293
#define IOCTL_AFD_ENUM_NETWORK_EVENTS
Definition: shared.h:335
#define AFD_EVENT_SEND
Definition: shared.h:205
_In_ HANDLE Handle
Definition: extypes.h:390
#define FD_CLOSE_BIT
Definition: winsock2.h:303
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define TRACE(s)
Definition: solgame.cpp:4
#define FD_CLOSE
Definition: winsock.h:410
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
#define AFD_EVENT_OOB_RECEIVE
Definition: shared.h:204
#define ERR(fmt,...)
Definition: debug.h:110
#define FD_ACCEPT_BIT
Definition: winsock2.h:299
#define AFD_EVENT_QOS
Definition: shared.h:212
INT TranslateNtStatusError(NTSTATUS Status)
Definition: dllmain.c:537
#define INFINITE
Definition: serial.h:102
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define FD_WRITE_BIT
Definition: winsock2.h:295
NTSTATUS EventStatus[AFD_MAX_EVENTS]
Definition: shared.h:132
#define AFD_EVENT_GROUP_QOS
Definition: shared.h:213
#define FD_QOS
Definition: winsock2.h:306

◆ WSPEventSelect()

INT WSPAPI WSPEventSelect ( IN SOCKET  s,
IN WSAEVENT  hEventObject,
IN LONG  lNetworkEvents,
OUT LPINT  lpErrno 
)

Definition at line 17 of file event.c.

22 {
23  IO_STATUS_BLOCK IOSB;
24  AFD_EVENT_SELECT_INFO EventSelectInfo;
25  PSOCKET_INFORMATION Socket = NULL;
27  BOOLEAN BlockMode;
29 
30  TRACE("WSPEventSelect (%lx) %lx %lx\n", Handle, hEventObject, lNetworkEvents);
31 
32  /* Get the Socket Structure associate to this Socket*/
33  Socket = GetSocketStructure(Handle);
34  if (!Socket)
35  {
36  if (lpErrno) *lpErrno = WSAENOTSOCK;
37  return SOCKET_ERROR;
38  }
39 
42 
43  if (!NT_SUCCESS(Status)) return SOCKET_ERROR;
44 
45  /* Set Socket to Non-Blocking */
46  BlockMode = TRUE;
48  Socket->SharedData->NonBlocking = TRUE;
49 
50  /* Deactivate Async Select if there is one */
51  if (Socket->EventObject) {
52  Socket->SharedData->hWnd = NULL;
53  Socket->SharedData->wMsg = 0;
54  Socket->SharedData->AsyncEvents = 0;
55  Socket->SharedData->SequenceNumber++; // This will kill Async Select after the next completion
56  }
57 
58  /* Set Structure Info */
59  EventSelectInfo.EventObject = hEventObject;
60  EventSelectInfo.Events = 0;
61 
62  /* Set Events to wait for */
63  if (lNetworkEvents & FD_READ) {
64  EventSelectInfo.Events |= AFD_EVENT_RECEIVE;
65  }
66 
67  if (lNetworkEvents & FD_WRITE) {
68  EventSelectInfo.Events |= AFD_EVENT_SEND;
69  }
70 
71  if (lNetworkEvents & FD_OOB) {
72  EventSelectInfo.Events |= AFD_EVENT_OOB_RECEIVE;
73  }
74 
75  if (lNetworkEvents & FD_ACCEPT) {
76  EventSelectInfo.Events |= AFD_EVENT_ACCEPT;
77  }
78 
79  if (lNetworkEvents & FD_CONNECT) {
80  EventSelectInfo.Events |= AFD_EVENT_CONNECT | AFD_EVENT_CONNECT_FAIL;
81  }
82 
83  if (lNetworkEvents & FD_CLOSE) {
85  }
86 
87  if (lNetworkEvents & FD_QOS) {
88  EventSelectInfo.Events |= AFD_EVENT_QOS;
89  }
90 
91  if (lNetworkEvents & FD_GROUP_QOS) {
92  EventSelectInfo.Events |= AFD_EVENT_GROUP_QOS;
93  }
94 
95  /* Send IOCTL */
97  SockEvent,
98  NULL,
99  NULL,
100  &IOSB,
102  &EventSelectInfo,
103  sizeof(EventSelectInfo),
104  NULL,
105  0);
106 
107  /* Wait for return */
108  if (Status == STATUS_PENDING) {
110  Status = IOSB.Status;
111  }
112 
113  NtClose (SockEvent);
114 
115  if (Status != STATUS_SUCCESS)
116  {
117  ERR("Got status 0x%08x.\n", Status);
118  return MsafdReturnWithErrno(Status, lpErrno, 0, NULL);
119  }
120 
121  /* Set Socket Data*/
122  Socket->EventObject = hEventObject;
123  Socket->NetworkEvents = lNetworkEvents;
124 
125  TRACE("Leaving\n");
126 
127  return 0;
128 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE EventObject
Definition: msafd.h:110
HANDLE SockEvent
#define AFD_EVENT_CONNECT_FAIL
Definition: shared.h:211
#define FD_ACCEPT
Definition: winsock.h:408
#define FD_CONNECT
Definition: winsock.h:409
#define TRUE
Definition: types.h:120
#define AFD_EVENT_DISCONNECT
Definition: shared.h:206
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
LONG NTSTATUS
Definition: precomp.h:26
#define AFD_EVENT_ABORT
Definition: shared.h:207
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
DWORD SequenceNumber
Definition: msafd.h:90
#define FD_READ
Definition: winsock.h:405
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FD_OOB
Definition: winsock.h:407
#define FD_WRITE
Definition: winsock.h:406
#define AFD_EVENT_CLOSE
Definition: shared.h:208
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FD_GROUP_QOS
Definition: winsock2.h:308
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define AFD_EVENT_RECEIVE
Definition: shared.h:203
#define AFD_EVENT_CONNECT
Definition: shared.h:209
#define AFD_INFO_BLOCKING_MODE
Definition: shared.h:183
#define AFD_EVENT_SEND
Definition: shared.h:205
BOOLEAN NonBlocking
Definition: msafd.h:74
_In_ HANDLE Handle
Definition: extypes.h:390
#define AFD_EVENT_ACCEPT
Definition: shared.h:210
#define TRACE(s)
Definition: solgame.cpp:4
#define FD_CLOSE
Definition: winsock.h:410
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
#define AFD_EVENT_OOB_RECEIVE
Definition: shared.h:204
#define ERR(fmt,...)
Definition: debug.h:110
int SetSocketInformation(PSOCKET_INFORMATION Socket, ULONG AfdInformationClass, PBOOLEAN Boolean OPTIONAL, PULONG Ulong OPTIONAL, PLARGE_INTEGER LargeInteger OPTIONAL, LPWSAOVERLAPPED Overlapped OPTIONAL, LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL)
Definition: dllmain.c:3388
#define AFD_EVENT_QOS
Definition: shared.h:212
#define IOCTL_AFD_EVENT_SELECT
Definition: shared.h:329
LONG NetworkEvents
Definition: msafd.h:111
#define INFINITE
Definition: serial.h:102
return STATUS_SUCCESS
Definition: btrfs.c:3014
LONG AsyncEvents
Definition: msafd.h:92
#define AFD_EVENT_GROUP_QOS
Definition: shared.h:213
#define FD_QOS
Definition: winsock2.h:306

◆ WSPGetAcceptExSockaddrs()

VOID WSPAPI WSPGetAcceptExSockaddrs ( IN PVOID  lpOutputBuffer,
IN DWORD  dwReceiveDataLength,
IN DWORD  dwLocalAddressLength,
IN DWORD  dwRemoteAddressLength,
OUT struct sockaddr **  LocalSockaddr,
OUT LPINT  LocalSockaddrLength,
OUT struct sockaddr **  RemoteSockaddr,
OUT LPINT  RemoteSockaddrLength 
)

Definition at line 104 of file stubs.c.

113 {
115 }
#define UNIMPLEMENTED
Definition: stubs.c:20

Referenced by WSPIoctl().

◆ WSPGetOverlappedResult()

BOOL WSPAPI WSPGetOverlappedResult ( IN SOCKET  s,
IN LPWSAOVERLAPPED  lpOverlapped,
OUT LPDWORD  lpcbTransfer,
IN BOOL  fWait,
OUT LPDWORD  lpdwFlags,
OUT LPINT  lpErrno 
)

Definition at line 96 of file sndrcv.c.

103 {
104  PSOCKET_INFORMATION Socket;
105  BOOL Ret;
106 
107  TRACE("Called (%x)\n", Handle);
108 
109  /* Get the Socket Structure associate to this Socket*/
110  Socket = GetSocketStructure(Handle);
111  if (!Socket)
112  {
113  if(lpErrno)
114  *lpErrno = WSAENOTSOCK;
115  return FALSE;
116  }
117  if (!lpOverlapped || !lpdwBytes || !lpdwFlags)
118  {
119  if (lpErrno)
120  *lpErrno = WSAEFAULT;
121  return FALSE;
122  }
123  Ret = GetOverlappedResult((HANDLE)Handle, lpOverlapped, lpdwBytes, fWait);
124 
125  if (Ret)
126  {
127  *lpdwFlags = 0;
128 
129  /* Re-enable Async Event */
133  }
134 
135  return Ret;
136 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define WSAEFAULT
Definition: winerror.h:1945
VOID SockReenableAsyncSelectEvent(IN PSOCKET_INFORMATION Socket, IN ULONG Event)
Definition: dllmain.c:3987
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
#define FD_READ
Definition: winsock.h:405
#define FD_OOB
Definition: winsock.h:407
#define FD_WRITE
Definition: winsock.h:406
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ HANDLE Handle
Definition: extypes.h:390
#define TRACE(s)
Definition: solgame.cpp:4
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90

◆ WSPGetPeerName()

INT WSPAPI WSPGetPeerName ( IN SOCKET  s,
OUT LPSOCKADDR  name,
IN OUT LPINT  namelen,
OUT LPINT  lpErrno 
)

Definition at line 2254 of file dllmain.c.

2258 {
2259  IO_STATUS_BLOCK IOSB;
2260  ULONG TdiAddressSize;
2261  PTRANSPORT_ADDRESS SocketAddress;
2262  PSOCKET_INFORMATION Socket = NULL;
2263  NTSTATUS Status;
2264  HANDLE SockEvent;
2265 
2266  /* Get the Socket Structure associate to this Socket*/
2267  Socket = GetSocketStructure(s);
2268  if (!Socket)
2269  {
2270  if (lpErrno) *lpErrno = WSAENOTSOCK;
2271  return SOCKET_ERROR;
2272  }
2273 
2274  if (Socket->SharedData->State != SocketConnected)
2275  {
2276  if (lpErrno) *lpErrno = WSAENOTCONN;
2277  return SOCKET_ERROR;
2278  }
2279 
2280  if (!Name || !NameLength)
2281  {
2282  if (lpErrno) *lpErrno = WSAEFAULT;
2283  return SOCKET_ERROR;
2284  }
2285 
2288  NULL,
2290  FALSE);
2291 
2292  if( !NT_SUCCESS(Status) )
2293  return SOCKET_ERROR;
2294 
2295  /* Allocate a buffer for the address */
2296  TdiAddressSize = sizeof(TRANSPORT_ADDRESS) + Socket->SharedData->SizeOfRemoteAddress;
2297  SocketAddress = HeapAlloc(GlobalHeap, 0, TdiAddressSize);
2298 
2299  if ( SocketAddress == NULL )
2300  {
2301  NtClose( SockEvent );
2302  if (lpErrno) *lpErrno = WSAENOBUFS;
2303  return SOCKET_ERROR;
2304  }
2305 
2306  /* Send IOCTL */
2308  SockEvent,
2309  NULL,
2310  NULL,
2311  &IOSB,
2313  NULL,
2314  0,
2315  SocketAddress,
2316  TdiAddressSize);
2317 
2318  /* Wait for return */
2319  if (Status == STATUS_PENDING)
2320  {
2322  Status = IOSB.Status;
2323  }
2324 
2325  NtClose( SockEvent );
2326 
2327  if (NT_SUCCESS(Status))
2328  {
2329  if (*NameLength >= Socket->SharedData->SizeOfRemoteAddress)
2330  {
2331  Name->sa_family = SocketAddress->Address[0].AddressType;
2332  RtlCopyMemory (Name->sa_data,
2333  SocketAddress->Address[0].Address,
2334  SocketAddress->Address[0].AddressLength);
2335  *NameLength = Socket->SharedData->SizeOfRemoteAddress;
2336  TRACE("NameLength %d Address: %x Port %x\n",
2337  *NameLength, ((struct sockaddr_in *)Name)->sin_addr.s_addr,
2338  ((struct sockaddr_in *)Name)->sin_port);
2339  HeapFree(GlobalHeap, 0, SocketAddress);
2340  return 0;
2341  }
2342  else
2343  {
2344  HeapFree(GlobalHeap, 0, SocketAddress);
2345  if (lpErrno) *lpErrno = WSAEFAULT;
2346  return SOCKET_ERROR;
2347  }
2348  }
2349 
2350  HeapFree(GlobalHeap, 0, SocketAddress);
2351 
2352  return MsafdReturnWithErrno ( Status, lpErrno, 0, NULL );
2353 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE SockEvent
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define WSAEFAULT
Definition: winerror.h:1945
UCHAR Address[1]
Definition: tdi.h:340
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
struct _TRANSPORT_ADDRESS TRANSPORT_ADDRESS
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOCTL_AFD_GET_PEER_NAME
Definition: shared.h:291
INT SizeOfRemoteAddress
Definition: msafd.h:60
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
GLdouble s
Definition: gl.h:2039
USHORT AddressType
Definition: tdi.h:339
#define WSAENOTCONN
Definition: winerror.h:1970
HANDLE GlobalHeap
Definition: dllmain.c:19
TA_ADDRESS Address[1]
Definition: tdi.h:377
USHORT AddressLength
Definition: tdi.h:338
SOCKET_STATE State
Definition: msafd.h:54
unsigned int ULONG
Definition: retypes.h:1
#define INFINITE
Definition: serial.h:102
#define WSAENOBUFS
Definition: winerror.h:1968
#define HeapFree(x, y, z)
Definition: compat.h:483

◆ WSPGetQOSByName()

BOOL WSPAPI WSPGetQOSByName ( IN SOCKET  s,
IN OUT LPWSABUF  lpQOSName,
OUT LPQOS  lpQOS,
OUT LPINT  lpErrno 
)

Definition at line 26 of file stubs.c.

31 {
33 
34  return FALSE;
35 }
#define UNIMPLEMENTED
Definition: stubs.c:20
#define FALSE
Definition: types.h:117

◆ WSPGetSockName()

INT WSPAPI WSPGetSockName ( IN SOCKET  s,
OUT LPSOCKADDR  name,
IN OUT LPINT  namelen,
OUT LPINT  lpErrno 
)

Definition at line 2152 of file dllmain.c.

2156 {
2157  IO_STATUS_BLOCK IOSB;
2158  ULONG TdiAddressSize;
2159  PTDI_ADDRESS_INFO TdiAddress;
2160  PTRANSPORT_ADDRESS SocketAddress;
2161  PSOCKET_INFORMATION Socket = NULL;
2162  NTSTATUS Status;
2163  HANDLE SockEvent;
2164 
2165  /* Get the Socket Structure associate to this Socket*/
2166  Socket = GetSocketStructure(Handle);
2167  if (!Socket)
2168  {
2169  if (lpErrno) *lpErrno = WSAENOTSOCK;
2170  return SOCKET_ERROR;
2171  }
2172 
2173  if (!Name || !NameLength)
2174  {
2175  if (lpErrno) *lpErrno = WSAEFAULT;
2176  return SOCKET_ERROR;
2177  }
2178 
2181  NULL,
2183  FALSE);
2184 
2185  if( !NT_SUCCESS(Status) )
2186  return SOCKET_ERROR;
2187 
2188  /* Allocate a buffer for the address */
2189  TdiAddressSize =
2190  sizeof(TRANSPORT_ADDRESS) + Socket->SharedData->SizeOfLocalAddress;
2191  TdiAddress = HeapAlloc(GlobalHeap, 0, TdiAddressSize);
2192 
2193  if ( TdiAddress == NULL )
2194  {
2195  NtClose( SockEvent );
2196  if (lpErrno) *lpErrno = WSAENOBUFS;
2197  return SOCKET_ERROR;
2198  }
2199 
2200  SocketAddress = &TdiAddress->Address;
2201 
2202  /* Send IOCTL */
2204  SockEvent,
2205  NULL,
2206  NULL,
2207  &IOSB,
2209  NULL,
2210  0,
2211  TdiAddress,
2212  TdiAddressSize);
2213 
2214  /* Wait for return */
2215  if (Status == STATUS_PENDING)
2216  {
2218  Status = IOSB.Status;
2219  }
2220 
2221  NtClose( SockEvent );
2222 
2223  if (NT_SUCCESS(Status))
2224  {
2225  if (*NameLength >= Socket->SharedData->SizeOfLocalAddress)
2226  {
2227  Name->sa_family = SocketAddress->Address[0].AddressType;
2228  RtlCopyMemory (Name->sa_data,
2229  SocketAddress->Address[0].Address,
2230  SocketAddress->Address[0].AddressLength);
2231  *NameLength = Socket->SharedData->SizeOfLocalAddress;
2232  TRACE("NameLength %d Address: %x Port %x\n",
2233  *NameLength, ((struct sockaddr_in *)Name)->sin_addr.s_addr,
2234  ((struct sockaddr_in *)Name)->sin_port);
2235  HeapFree(GlobalHeap, 0, TdiAddress);
2236  return 0;
2237  }
2238  else
2239  {
2240  HeapFree(GlobalHeap, 0, TdiAddress);
2241  if (lpErrno) *lpErrno = WSAEFAULT;
2242  return SOCKET_ERROR;
2243  }
2244  }
2245 
2246  HeapFree(GlobalHeap, 0, TdiAddress);
2247 
2248  return MsafdReturnWithErrno ( Status, lpErrno, 0, NULL );
2249 }
#define WSAENOTSOCK
Definition: winerror.h:1951
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE SockEvent
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define WSAEFAULT
Definition: winerror.h:1945
UCHAR Address[1]
Definition: tdi.h:340
PSOCKET_INFORMATION GetSocketStructure(SOCKET Handle)
Definition: dllmain.c:3511
SOCKET Handle
Definition: msafd.h:99
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtCreateEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN EVENT_TYPE EventType, IN BOOLEAN InitialState)
Definition: event.c:100
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
PSOCK_SHARED_INFO SharedData
Definition: msafd.h:100
smooth NULL
Definition: ftsmooth.c:416
_In_ HANDLE Handle
Definition: extypes.h:390
#define TRACE(s)
Definition: solgame.cpp:4
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
struct _TRANSPORT_ADDRESS TRANSPORT_ADDRESS
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOCTL_AFD_GET_SOCK_NAME
Definition: shared.h:289
FORCEINLINE DWORD MsafdReturnWithErrno(NTSTATUS Status, LPINT Errno, DWORD Received, LPDWORD ReturnedBytes)
Definition: msafd.h:546
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
TRANSPORT_ADDRESS Address
Definition: tdi.h:388
INT SizeOfLocalAddress
Definition: msafd.h:59
USHORT AddressType
Definition: tdi.h:339
HANDLE GlobalHeap
Definition: dllmain.c:19
TA_ADDRESS Address[1]
Definition: tdi.h:377
USHORT AddressLength
Definition: tdi.h:338
unsigned int ULONG
Definition: retypes.h:1
#define INFINITE
Definition: serial.h:102
#define WSAENOBUFS
Definition: winerror.h:1968
#define HeapFree(x, y, z)
Definition: compat.h:483

◆ WSPGetSockOpt()

INT WSPAPI WSPGetSockOpt ( IN SOCKET  s,
IN INT  level,
IN INT  optname,
OUT CHAR FAR optval,
IN OUT LPINT  optlen,
OUT LPINT  lpErrno 
)

Definition at line 2600 of file dllmain.c.

2606 {
2607  PSOCKET_INFORMATION Socket = NULL;
2608  PVOID Buffer;
2609  INT BufferSize;
2610  BOOL BoolBuffer;
2611  DWORD DwordBuffer;
2612  INT Errno;
2613 
2614  TRACE("Called\n");
2615 
2616  /* Get the Socket Structure associate to this Socket*/
2617  Socket = GetSocketStructure(Handle);
2618  if (Socket == NULL)
2619  {
2620  if (lpErrno) *lpErrno = WSAENOTSOCK;
2621  return SOCKET_ERROR;
2622  }
2623  if (!OptionLength || !OptionValue)
2624  {
2625  if (lpErrno) *lpErrno = WSAEFAULT;
2626  return SOCKET_ERROR;
2627  }
2628 
2629  switch (Level)
2630  {
2631  case SOL_SOCKET:
2632  switch (OptionName)
2633  {
2634  case SO_TYPE:
2635  Buffer = &Socket->SharedData->SocketType;
2636  BufferSize = sizeof(INT);
2637  break;
2638 
2639  case SO_RCVBUF:
2640  Buffer = &Socket->SharedData->SizeOfRecvBuffer;
2641  BufferSize = sizeof(ULONG);
2642  break;
2643 
2644  case SO_SNDBUF:
2645  Buffer = &Socket->SharedData->SizeOfSendBuffer;
2646  BufferSize = sizeof(ULONG);
2647  break;
2648 
2649  case SO_ACCEPTCONN:
2650  BoolBuffer = Socket->SharedData->Listening;
2651  Buffer = &BoolBuffer;
2652  BufferSize = sizeof(BOOL);
2653  break;
2654 
2655  case SO_BROADCAST:
2656  BoolBuffer = Socket->SharedData->Broadcast;
2657  Buffer = &BoolBuffer;
2658  BufferSize = sizeof(BOOL);
2659  break;
2660 
2661  case SO_DEBUG:
2662  BoolBuffer = Socket->SharedData->Debug;
2663  Buffer = &BoolBuffer;
2664  BufferSize = sizeof(BOOL);
2665  break;
2666 
2667  case SO_DONTLINGER:
2668  BoolBuffer = (Socket->SharedData->LingerData.l_onoff == 0);
2669  Buffer = &BoolBuffer;
2670  BufferSize = sizeof(BOOL);
2671  break;
2672 
2673  case SO_LINGER:
2674  if (Socket->SharedData->SocketType == SOCK_DGRAM)
2675  {
2676  if (lpErrno) *lpErrno = WSAENOPROTOOPT;
2677  return SOCKET_ERROR;
2678  }
2679  Buffer = &Socket->SharedData->LingerData;
2680  BufferSize = sizeof(struct linger);
2681  break;
2682 
2683  case SO_OOBINLINE:
2684  BoolBuffer = (Socket->SharedData->OobInline != 0);
2685  Buffer = &BoolBuffer;
2686  BufferSize = sizeof(BOOL);
2687  break;
2688 
2689  case SO_KEEPALIVE:
2690  case SO_DONTROUTE:
2691  /* These guys go directly to the helper */
2692  goto SendToHelper;
2693 
2694  case SO_CONDITIONAL_ACCEPT:
2695  BoolBuffer = (Socket->SharedData->UseDelayedAcceptance != 0);
2696  Buffer = &BoolBuffer;
2697  BufferSize = sizeof(BOOL);
2698  break;
2699 
2700  case SO_REUSEADDR:
2701  BoolBuffer = (Socket->SharedData->ReuseAddresses != 0);
2702  Buffer = &BoolBuffer;
2703  BufferSize = sizeof(BOOL);
2704  break;
2705 
2706  case SO_EXCLUSIVEADDRUSE:
2707  BoolBuffer = (Socket->SharedData->ExclusiveAddressUse != 0);
2708  Buffer = &BoolBuffer;
2709  BufferSize = sizeof(BOOL);
2710  break;
2711 
2712  case SO_ERROR:
2713  Buffer = &Socket->SharedData->SocketLastError;
2714  BufferSize = sizeof(INT);
2715  break;
2716 
2717  case SO_CONNECT_TIME:
2718  DwordBuffer = GetCurrentTimeInSeconds() - Socket->SharedData->ConnectTime;
2719  Buffer = &DwordBuffer;
2720  BufferSize = sizeof(DWORD);
2721  break;
2722 
2723  case SO_SNDTIMEO:
2724  Buffer = &Socket->SharedData->SendTimeout;
2725  BufferSize = sizeof(DWORD);
2726  break;
2727  case SO_RCVTIMEO:
2728  Buffer = &Socket->SharedData->RecvTimeout;
2729  BufferSize = sizeof(DWORD);
2730  break;
2731  case SO_PROTOCOL_INFOW:
2732  Buffer = &Socket->ProtocolInfo;
2733  BufferSize = sizeof(Socket->ProtocolInfo);
2734  break;
2735 
2736  case SO_GROUP_ID:
2737  case SO_GROUP_PRIORITY:
2738  case SO_MAX_MSG_SIZE:
2739 
2740  default:
2741  DbgPrint("MSAFD: Get unknown optname %x\n", OptionName);
2742  if (lpErrno) *lpErrno = WSAENOPROTOOPT;
2743  return SOCKET_ERROR;
2744  }
2745 
2746  if (*OptionLength < BufferSize)
2747  {
2748  if (lpErrno) *lpErrno = WSAEFAULT;
2749  *OptionLength = BufferSize;
2750  return SOCKET_ERROR;
2751  }
2752  RtlCopyMemory(OptionValue, Buffer, BufferSize);
2753 
2754  return 0;
2755 
2756  default:
2757  if (lpErrno) *lpErrno = WSAEINVAL;
2758  return SOCKET_ERROR;
2759