Bug 1358466 - Define pt_sendto only on Linux and fix comments. r=mcmanus

This commit is contained in:
Dragana Damjanovic dd.mozilla@gmail.com 2017-04-24 17:32:23 +02:00
parent 33ee94b632
commit 7e58b54e20
3 changed files with 36 additions and 30 deletions

View file

@ -315,9 +315,9 @@ static PRStatus PR_CALLBACK SocketConnectContinue(
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;
@ -325,9 +325,9 @@ static PRStatus PR_CALLBACK SocketConnectContinue(
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,
@ -1198,7 +1198,7 @@ static PRIOMethods tcpMethods = {
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

View file

@ -410,7 +410,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
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) {
@ -432,13 +432,13 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
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();
@ -447,10 +447,10 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
_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 {
@ -461,13 +461,13 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
_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) {

View file

@ -2056,14 +2056,15 @@ static PRInt32 pt_SendTo(
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;
@ -2084,8 +2085,8 @@ static PRInt32 pt_TCP_SendTo(
#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;
@ -2094,8 +2095,8 @@ static PRInt32 pt_TCP_SendTo(
#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;
@ -2143,11 +2144,12 @@ static PRInt32 pt_TCP_SendTo(
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)
@ -3260,7 +3262,11 @@ static PRIOMethods _pr_tcp_methods = {
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,