[MSAFD] Implement SO_CONNECT_TIME. CORE-12104
authorPeter Hater <7element@mail.bg>
Thu, 10 Nov 2016 17:55:00 +0000 (17:55 +0000)
committerPeter Hater <7element@mail.bg>
Thu, 10 Nov 2016 17:55:00 +0000 (17:55 +0000)
svn path=/trunk/; revision=73197

reactos/dll/win32/msafd/misc/dllmain.c
reactos/dll/win32/msafd/msafd.h

index cb80cab..00190a8 100644 (file)
@@ -1320,6 +1320,21 @@ WSPSelect(IN int nfds,
     return HandleCount;
 }
 
+DWORD
+GetCurrentTimeInSeconds()
+{
+    FILETIME Time;
+    FILETIME Adjustment;
+    ULARGE_INTEGER lTime, lAdj;
+    SYSTEMTIME st = { 1970,1,0,1,0,0,0 };
+    SystemTimeToFileTime(&st, &Adjustment);
+    memcpy(&lAdj, &Adjustment, sizeof(lAdj));
+    GetSystemTimeAsFileTime(&Time);
+    memcpy(&lTime, &Time, sizeof(lTime));
+    lTime.QuadPart -= lAdj.QuadPart;
+    return (DWORD)(lTime.QuadPart / 10000000LLU);
+}
+
 SOCKET
 WSPAPI
 WSPAccept(SOCKET Handle,
@@ -1666,6 +1681,7 @@ WSPAccept(SOCKET Handle,
     }
 
     AcceptSocketInfo->SharedData->State = SocketConnected;
+    AcceptSocketInfo->SharedData->ConnectTime = GetCurrentTimeInSeconds();
 
     /* Return Address in SOCKADDR FORMAT */
     if( SocketAddress )
@@ -1884,6 +1900,7 @@ WSPConnect(SOCKET Handle,
 
     Socket->SharedData->State = SocketConnected;
     Socket->TdiConnectionHandle = (HANDLE)IOSB.Information;
+    Socket->SharedData->ConnectTime = GetCurrentTimeInSeconds();
 
     /* Get any pending connect data */
     if (lpCalleeData != NULL)
@@ -2437,6 +2454,7 @@ WSPGetSockOpt(IN SOCKET Handle,
     PVOID Buffer;
     INT BufferSize;
     BOOL BoolBuffer;
+    DWORD DwordBuffer;
     INT Errno;
 
     TRACE("Called\n");
@@ -2542,6 +2560,12 @@ WSPGetSockOpt(IN SOCKET Handle,
                     BufferSize = sizeof(INT);
                     break;
 
+                case SO_CONNECT_TIME:
+                    DwordBuffer = GetCurrentTimeInSeconds() - Socket->SharedData->ConnectTime;
+                    Buffer = &DwordBuffer;
+                    BufferSize = sizeof(DWORD);
+                    break;
+
                 case SO_SNDTIMEO:
                     Buffer = &Socket->SharedData->SendTimeout;
                     BufferSize = sizeof(DWORD);
index fcf7006..fa3396e 100644 (file)
@@ -59,6 +59,7 @@ typedef struct _SOCK_SHARED_INFO {
     ULONG                                              RecvTimeout;
     ULONG                                              SizeOfRecvBuffer;
     ULONG                                              SizeOfSendBuffer;
+    ULONG                                              ConnectTime;
     struct {
         BOOLEAN                                        Listening:1;
         BOOLEAN                                        Broadcast:1;