Author: phater
Date: Mon Nov 7 08:50:31 2016
New Revision: 73165
URL:
http://svn.reactos.org/svn/reactos?rev=73165&view=rev
Log:
[MSAFD] Implement SOL_SOCKET/SO_ERROR. CORE-12104
Modified:
trunk/reactos/dll/win32/msafd/misc/dllmain.c
Modified: trunk/reactos/dll/win32/msafd/misc/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/misc/dllma…
==============================================================================
--- trunk/reactos/dll/win32/msafd/misc/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msafd/misc/dllmain.c [iso-8859-1] Mon Nov 7 08:50:31 2016
@@ -914,6 +914,7 @@
NtClose( SockEvent );
HeapFree(GlobalHeap, 0, BindData);
+ Socket->SharedData->SocketLastError = TranslateNtStatusError(Status);
if (Status != STATUS_SUCCESS)
return MsafdReturnWithErrno ( Status, lpErrno, 0, NULL );
@@ -997,6 +998,7 @@
NtClose( SockEvent );
+ Socket->SharedData->SocketLastError = TranslateNtStatusError(Status);
if (Status != STATUS_SUCCESS)
return MsafdReturnWithErrno ( Status, lpErrno, 0, NULL );
@@ -1250,6 +1252,10 @@
TRACE("Event %x on handle %x\n",
Events,
Handle);
+ if ((Events & x) == AFD_EVENT_DISCONNECT || (Events & x) ==
AFD_EVENT_CLOSE)
+ Socket->SharedData->SocketLastError = WSAECONNRESET;
+ if ((Events & x) == AFD_EVENT_ABORT)
+ Socket->SharedData->SocketLastError = WSAECONNABORTED;
if( readfds )
FD_SET(Handle, readfds);
break;
@@ -1643,6 +1649,7 @@
Status = IOSB.Status;
}
+ Socket->SharedData->SocketLastError = TranslateNtStatusError(Status);
if (!NT_SUCCESS(Status))
{
NtClose(SockEvent);
@@ -1871,6 +1878,7 @@
Status = IOSB.Status;
}
+ Socket->SharedData->SocketLastError = TranslateNtStatusError(Status);
if (Status != STATUS_SUCCESS)
goto notify;
@@ -2017,6 +2025,7 @@
NtClose( SockEvent );
+ Socket->SharedData->SocketLastError = TranslateNtStatusError(Status);
return MsafdReturnWithErrno( Status, lpErrno, 0, NULL );
}
@@ -2428,8 +2437,9 @@
PVOID Buffer;
INT BufferSize;
BOOL BoolBuffer;
- INT IntBuffer;
INT Errno;
+
+ TRACE("Called\n");
/* Get the Socket Structure associate to this Socket*/
Socket = GetSocketStructure(Handle);
@@ -2438,8 +2448,11 @@
if (lpErrno) *lpErrno = WSAENOTSOCK;
return SOCKET_ERROR;
}
-
- TRACE("Called\n");
+ if (!OptionLength || !OptionValue)
+ {
+ if (lpErrno) *lpErrno = WSAEFAULT;
+ return SOCKET_ERROR;
+ }
switch (Level)
{
@@ -2525,13 +2538,10 @@
break;
case SO_ERROR:
- /* HACK: This needs to be properly tracked */
- IntBuffer = 0;
- DbgPrint("MSAFD: Hacked SO_ERROR returning error %d\n",
IntBuffer);
-
- Buffer = &IntBuffer;
+ Buffer = &Socket->SharedData->SocketLastError;
BufferSize = sizeof(INT);
break;
+
case SO_SNDTIMEO:
Buffer = &Socket->SharedData->SendTimeout;
BufferSize = sizeof(DWORD);
@@ -2603,6 +2613,11 @@
if (lpErrno) *lpErrno = WSAENOTSOCK;
return SOCKET_ERROR;
}
+ if (!optval)
+ {
+ if (lpErrno) *lpErrno = WSAEFAULT;
+ return SOCKET_ERROR;
+ }
/* FIXME: We should handle some more cases here */
@@ -2675,6 +2690,18 @@
/* TODO: The total per-socket buffer space reserved for sends */
ERR("Setting send buf to %x is not implemented yet\n", optval);
+ return NO_ERROR;
+
+ case SO_ERROR:
+ if (optlen < sizeof(INT))
+ {
+ if (lpErrno) *lpErrno = WSAEFAULT;
+ return SOCKET_ERROR;
+ }
+
+ RtlCopyMemory(&Socket->SharedData->SocketLastError,
+ optval,
+ sizeof(INT));
return NO_ERROR;
case SO_SNDTIMEO: