Index: dll/win32/msafd/misc/dllmain.c =================================================================== --- dll/win32/msafd/misc/dllmain.c (revision 73123) +++ dll/win32/msafd/misc/dllmain.c (working copy) @@ -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,9 +2437,10 @@ PVOID Buffer; INT BufferSize; BOOL BoolBuffer; - INT IntBuffer; INT Errno; + TRACE("Called\n"); + /* Get the Socket Structure associate to this Socket*/ Socket = GetSocketStructure(Handle); if (Socket == NULL) @@ -2438,9 +2448,12 @@ if (lpErrno) *lpErrno = WSAENOTSOCK; return SOCKET_ERROR; } + if (!OptionLength || !OptionValue) + { + if (lpErrno) *lpErrno = WSAEFAULT; + return SOCKET_ERROR; + } - TRACE("Called\n"); - switch (Level) { case SOL_SOCKET: @@ -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 */ @@ -2677,6 +2692,18 @@ 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: if (optlen < sizeof(DWORD)) {