Bug 1358466 - Define pt_sendto only on Linux and fix comments. r=mcmanus
authorDragana Damjanovic <dd.mozilla@gmail.com>
Tue, 09 May 2017 13:38:45 +0200
changeset 4726 4341e6258d2c4a3e8421618a6f41f09f554c78d9
parent 4725 f39f28732459374ed4fa5a5a5b5b03d81c5d5aac
child 4727 f869b8701568e60599165ce1efc3b38f962e4955
push id245
push userkaie@kuix.de
push dateTue, 09 May 2017 11:38:28 +0000
reviewersmcmanus
bugs1358466
Bug 1358466 - Define pt_sendto only on Linux and fix comments. r=mcmanus
pr/src/io/prsocket.c
pr/src/md/windows/w95sock.c
pr/src/pthreads/ptio.c
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -310,29 +310,29 @@ static PRStatus PR_CALLBACK SocketConnec
     }
 
     PR_ASSERT(out_flags & PR_POLL_WRITE);
 
 #if defined(_WIN64)
     if (fd->secret->alreadyConnected) {
         fd->secret->alreadyConnected = PR_FALSE;
     }
-    // TCP Fast Open on Windows must use ConnectEx, which uses overlapped
-    // input/output.
-    // To get result we need to use GetOverlappedResult.
+    /* TCP Fast Open on Windows must use ConnectEx, which uses overlapped
+     * input/output.
+     * To get result we need to use GetOverlappedResult. */
     if (fd->secret->overlappedActive) {
         PR_ASSERT(fd->secret->nonblocking);
         PRInt32 rvSent;
         if (GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
             fd->secret->overlappedActive = FALSE;
             PR_LOG(_pr_io_lm, PR_LOG_MIN,
                ("SocketConnectContinue GetOverlappedResult succeeded\n"));
-            // When ConnectEx is used, all previously set socket options and
-            // property are not enabled and to enable them
-            // SO_UPDATE_CONNECT_CONTEXT option need to be set.
+            /* When ConnectEx is used, all previously set socket options and
+             * property are not enabled and to enable them
+             * SO_UPDATE_CONNECT_CONTEXT option need to be set. */
             if (setsockopt((SOCKET)osfd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0) != 0) {
                 err = WSAGetLastError();
                 PR_LOG(_pr_io_lm, PR_LOG_MIN,
                        ("SocketConnectContinue setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
                 _PR_MD_MAP_SETSOCKOPT_ERROR(err);
                 return PR_FAILURE;
             }
             return PR_SUCCESS;
@@ -1193,17 +1193,17 @@ static PRIOMethods tcpMethods = {
 	SocketAccept,
 	SocketBind,
 	SocketListen,
 	SocketShutdown,
 	SocketRecv,
 	SocketSend,
 	(PRRecvfromFN)_PR_InvalidInt,
 #if defined(_WIN64) && defined(WIN95)
-	SocketTCPSendTo, // This is for fast open. We imitate Linux interface.
+	SocketTCPSendTo, /* This is for fast open. We imitate Linux interface. */
 #else
 	(PRSendtoFN)_PR_InvalidInt,
 #endif
 	SocketPoll,
 	SocketAcceptRead,
 	SocketTransmitFile,
 	SocketGetName,
 	SocketGetPeerName,
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -405,17 +405,17 @@ PRInt32
         if (err == WSAENOPROTOOPT) {
             PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
         } else {
             _PR_MD_MAP_SETSOCKOPT_ERROR(err);
         }
         return -1;
     }
 
-    // ConnectEx requires the socket to be initially bound. We will use INADDR_ANY
+    /* ConnectEx requires the socket to be initially bound. We will use INADDR_ANY. */
     PRNetAddr bindAddr;
     memset(&bindAddr, 0, sizeof(bindAddr));
     if (addr->raw.family == PR_AF_INET) {
         bindAddr.inet.family = PR_AF_INET;
     } else if (addr->raw.family == PR_AF_INET6) {
         bindAddr.ipv6.family = PR_AF_INET6;
     }
     rv = bind((SOCKET)osfd, (SOCKADDR*) &bindAddr, sizeof(bindAddr));
@@ -427,52 +427,52 @@ PRInt32
         return -1;
     }
 
     PR_LOG(_pr_io_lm, PR_LOG_MIN,
            ("_PR_MD_TCPSENDTO calling _pr_win_connectex  %d %p\n", amount, (char*)buf));
 
     rvSent = 0;
     memset(&fd->secret->ol, 0, sizeof(fd->secret->ol));
-    // ConnectEx return TRUE on a success and FALSE on an error.
+    /* ConnectEx return TRUE on a success and FALSE on an error. */
     if (_pr_win_connectex( (SOCKET)osfd, (struct sockaddr *) addr,
                            addrlen, buf, amount,
                            &rvSent, &fd->secret->ol) == TRUE) {
-        // When ConnectEx is used, all previously set socket options and
-        // property are not enabled and to enable them
-        // SO_UPDATE_CONNECT_CONTEXT option need to be set.
+        /* When ConnectEx is used, all previously set socket options and
+         * property are not enabled and to enable them
+         * SO_UPDATE_CONNECT_CONTEXT option need to be set. */
         rv = setsockopt((SOCKET)osfd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0);
         if (rv != 0) {
             err = WSAGetLastError();
             PR_LOG(_pr_io_lm, PR_LOG_MIN,
                ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
             _PR_MD_MAP_SETSOCKOPT_ERROR(err);
             return -1;
         }
-        // We imitate Linux here. SendTo will return number of bytes send but
-        // it can not return connection success at the same time, so we return
-        // number of bytes send and "connection success" will be return on the
-        // connectcontinue.
+        /* We imitate Linux here. SendTo will return number of bytes send but
+         * it can not return connection success at the same time, so we return
+         * number of bytes send and "connection success" will be return on the
+         * connectcontinue. */
         fd->secret->alreadyConnected = PR_TRUE;
         return rvSent;
     } else {
         err = WSAGetLastError();
         PR_LOG(_pr_io_lm, PR_LOG_MIN,
                ("_PR_MD_TCPSENDTO error _pr_win_connectex failed %d\n", err));
         if (err != ERROR_IO_PENDING) {
             _PR_MD_MAP_CONNECT_ERROR(err);
             return -1;
         } else if (fd->secret->nonblocking) {
-            // Remember that overlapped structure is set. We will neede to get
-            // the final result of ConnectEx call.
+            /* Remember that overlapped structure is set. We will neede to get
+             * the final result of ConnectEx call. */
             fd->secret->overlappedActive = PR_TRUE;
             _PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK);
-            // ConnectEx will copy supplied data to a internal buffer and send
-            // them during Fast Open or after connect. Therefore we can assumed
-            // this data already send.
+            /* ConnectEx will copy supplied data to a internal buffer and send
+             * them during Fast Open or after connect. Therefore we can assumed
+             * this data already send. */
             return amount;
         }
         while (err == ERROR_IO_PENDING) {
             rv = socket_io_wait(osfd, WRITE_FD, timeout);
             if ( rv < 0 ) {
                 return -1;
             }
             rv = GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE);
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -2051,24 +2051,25 @@ static PRInt32 pt_SendTo(
         bytes = pt_Continue(&op);
         syserrno = op.syserrno;
     }
     if (bytes < 0)
         pt_MapError(_PR_MD_MAP_SENDTO_ERROR, syserrno);
     return bytes;
 }  /* pt_SendTo */
 
-// Linux uses SendTo to send data during TCP Fast Open. OSX uses connectx, but
-// we will make it imitate the Linux's interface.
+#if defined(LINUX) || defined(DARWIN)
+/* Linux uses SendTo to send data during TCP Fast Open. OSX uses connectx, but
+ * we will make it imitate the Linux's interface. */
 static PRInt32 pt_TCP_SendTo(
     PRFileDesc *fd, const void *buf,
     PRInt32 amount, PRIntn flags, const PRNetAddr *addr,
     PRIntervalTime timeout)
 {
-#if !defined(DARWIN) || HAS_CONNECTX
+#if defined(LINUX) || HAS_CONNECTX
     PRInt32 syserrno, bytes = -1;
     PRBool fNeedContinue = PR_FALSE;
     pt_SockLen addr_len;
     const PRNetAddr *addrp = addr;
 #if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
     PRNetAddr addrCopy;
 #endif
 #ifdef _PR_HAVE_SOCKADDR_LEN
@@ -2079,28 +2080,28 @@ static PRInt32 pt_TCP_SendTo(
 
     PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
     addr_len = PR_NETADDR_SIZE(addr);
 #if defined(_PR_INET6)
     if (addr->raw.family == PR_AF_INET6) {
 #ifdef _PR_HAVE_SOCKADDR_LEN
         md_af = AF_INET6;
 #else
-        // If _PR_INET6 is defined and it is PR_AF_INET6 we set family
-        // to AF_INET6.
+        /* If _PR_INET6 is defined and it is PR_AF_INET6 we set family
+         * to AF_INET6. */
         addrCopy = *addr;
         addrCopy.raw.family = AF_INET6;
         addrp = &addrCopy;
 #endif
     }
 #endif
 
 #ifdef _PR_HAVE_SOCKADDR_LEN
-    // if _PR_HAVE_SOCKADDR_LEN is defined and it is PR_AF_INET6 we set family
-    // to AF_INET6 and we set address length.
+    /* if _PR_HAVE_SOCKADDR_LEN is defined and it is PR_AF_INET6 we set family
+     * to AF_INET6 and we set address length. */
     addrCopy = *addr;
     ((struct sockaddr*)&addrCopy)->sa_len = addr_len;
     ((struct sockaddr*)&addrCopy)->sa_family = md_af;
     addrp = &addrCopy;
 #endif
 
 #ifndef HAS_CONNECTX
     bytes = sendto(
@@ -2138,21 +2139,22 @@ static PRInt32 pt_TCP_SendTo(
         op.event = POLLOUT | POLLPRI;
         bytes = pt_Continue(&op);
         syserrno = op.syserrno;
     }
     if (bytes < 0) {
         pt_MapError(_PR_MD_MAP_SENDTO_ERROR, syserrno);
     }
     return bytes;
-#else
+#else /* !HAS_CONNECTX */
     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     return -1;
 #endif
 }  /* pt_TCP_SendTo */
+#endif /* LINUX || DARWIN */
 
 static PRInt32 pt_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
     PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
 {
     PRBool fNeedContinue = PR_FALSE;
     PRInt32 syserrno, bytes = -1;
     pt_SockLen addr_len = sizeof(PRNetAddr);
 
@@ -3255,17 +3257,21 @@ static PRIOMethods _pr_tcp_methods = {
     pt_Connect,
     pt_Accept,
     pt_Bind,
     pt_Listen,
     pt_Shutdown,
     pt_Recv,
     pt_Send,
     (PRRecvfromFN)_PR_InvalidInt,
-    pt_TCP_SendTo, // This is for TCP Fast Open. Linux uses SendTo function for this. OSX uses connectx, but we imitate Linux.
+#if defined(LINUX) || defined(DARWIN)
+    pt_TCP_SendTo, /* This is for TCP Fast Open. Linux uses SendTo function for this. OSX uses connectx, but we imitate Linux. */
+#else
+    (PRSendtoFN)_PR_InvalidInt,
+#endif
     pt_Poll,
     pt_AcceptRead,
     pt_TransmitFile,
     pt_GetSockName,
     pt_GetPeerName,
     (PRReservedFN)_PR_InvalidInt,
     (PRReservedFN)_PR_InvalidInt,
     pt_GetSocketOption,