diff options
Diffstat (limited to 'nsprpub/pr/src/md/windows/w95sock.c')
-rw-r--r-- | nsprpub/pr/src/md/windows/w95sock.c | 114 |
1 files changed, 61 insertions, 53 deletions
diff --git a/nsprpub/pr/src/md/windows/w95sock.c b/nsprpub/pr/src/md/windows/w95sock.c index c6a3ec111f..7d7362c608 100644 --- a/nsprpub/pr/src/md/windows/w95sock.c +++ b/nsprpub/pr/src/md/windows/w95sock.c @@ -14,7 +14,7 @@ #define CONNECT_FD 3 static PRInt32 socket_io_wait( - PROsfd osfd, + PROsfd osfd, PRInt32 fd_type, PRIntervalTime timeout); @@ -51,7 +51,7 @@ _PR_MD_SOCKET(int af, int type, int flags) sock = socket(af, type, flags); - if (sock == INVALID_SOCKET ) + if (sock == INVALID_SOCKET ) { _PR_MD_MAP_SOCKET_ERROR(WSAGetLastError()); return (PROsfd)sock; @@ -101,8 +101,9 @@ _MD_CloseSocket(PROsfd osfd) PRInt32 rv; rv = closesocket((SOCKET) osfd ); - if (rv < 0) + if (rv < 0) { _PR_MD_MAP_CLOSE_ERROR(WSAGetLastError()); + } return rv; } @@ -120,8 +121,8 @@ _MD_SocketAvailable(PRFileDesc *fd) } PROsfd _MD_Accept( - PRFileDesc *fd, - PRNetAddr *raddr, + PRFileDesc *fd, + PRNetAddr *raddr, PRUint32 *rlen, PRIntervalTime timeout ) { @@ -129,7 +130,7 @@ PROsfd _MD_Accept( SOCKET sock; PRInt32 rv, err; - while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1) + while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1) { err = WSAGetLastError(); if ((err == WSAEWOULDBLOCK) && (!fd->secret->nonblocking)) @@ -149,14 +150,14 @@ PROsfd _MD_Accept( } /* end _MD_accept() */ PRInt32 -_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen, +_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout) { PROsfd osfd = fd->secret->md.osfd; PRInt32 rv; int err; - if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1) + if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1) { err = WSAGetLastError(); if ((!fd->secret->nonblocking) && (err == WSAEWOULDBLOCK)) @@ -171,7 +172,7 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen, PR_ASSERT(rv > 0); /* it's connected */ return(0); - } + } } _PR_MD_MAP_CONNECT_ERROR(err); } @@ -209,7 +210,7 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog) } PRInt32 -_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, +_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRIntervalTime timeout) { PROsfd osfd = fd->secret->md.osfd; @@ -222,18 +223,18 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PR_ASSERT(PR_MSG_PEEK == flags); osflags = MSG_PEEK; } - while ((rv = recv( osfd, buf, amount, osflags)) == -1) + while ((rv = recv( osfd, buf, amount, osflags)) == -1) { - if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) + if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) && (!fd->secret->nonblocking)) { rv = socket_io_wait(osfd, READ_FD, timeout); if ( rv < 0 ) { return -1; - } - } - else + } + } + else { _PR_MD_MAP_RECV_ERROR(err); break; @@ -250,11 +251,11 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, PRInt32 rv, err; PRInt32 bytesSent = 0; - while(bytesSent < amount ) + while(bytesSent < amount ) { - while ((rv = send( osfd, buf, amount, 0 )) == -1) + while ((rv = send( osfd, buf, amount, 0 )) == -1) { - if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) + if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) && (!fd->secret->nonblocking)) { rv = socket_io_wait(osfd, WRITE_FD, timeout); @@ -262,8 +263,8 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, { return -1; } - } - else + } + else { _PR_MD_MAP_SEND_ERROR(err); return -1; @@ -274,7 +275,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, { break; } - if (bytesSent < amount) + if (bytesSent < amount) { rv = socket_io_wait(osfd, WRITE_FD, timeout); if ( rv < 0 ) @@ -296,9 +297,9 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, do { while ((rv = sendto( osfd, buf, amount, 0, (struct sockaddr *) addr, - addrlen)) == -1) + addrlen)) == -1) { - if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) + if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) && (!fd->secret->nonblocking)) { rv = socket_io_wait(osfd, WRITE_FD, timeout); @@ -306,8 +307,8 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, { return -1; } - } - else + } + else { _PR_MD_MAP_SENDTO_ERROR(err); return -1; @@ -318,10 +319,10 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, { break; } - if (bytesSent < amount) + if (bytesSent < amount) { rv = socket_io_wait(osfd, WRITE_FD, timeout); - if (rv < 0) + if (rv < 0) { return -1; } @@ -361,8 +362,9 @@ static PRStatus PR_CALLBACK _pr_set_connectex(void) /* Dummy socket needed for WSAIoctl */ sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock == INVALID_SOCKET) + if (sock == INVALID_SOCKET) { return PR_SUCCESS; + } GUID guid = WSAID_CONNECTEX; rc = WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, @@ -446,7 +448,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, 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_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err)); _PR_MD_MAP_SETSOCKOPT_ERROR(err); return -1; } @@ -472,7 +474,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, * them during Fast Open or after connect. Therefore we can assumed * this data already send. */ if (amount > 0) { - return amount; + return amount; } _PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK); @@ -510,18 +512,18 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRInt32 rv, err; while ((rv = recvfrom( osfd, buf, amount, 0, (struct sockaddr *) addr, - addrlen)) == -1) + addrlen)) == -1) { - if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) + if (((err = WSAGetLastError()) == WSAEWOULDBLOCK) && (!fd->secret->nonblocking)) { rv = socket_io_wait(osfd, READ_FD, timeout); if ( rv < 0) { return -1; - } - } - else + } + } + else { _PR_MD_MAP_RECVFROM_ERROR(err); break; @@ -537,12 +539,13 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi int sent = 0; int rv; - for (index=0; index < iov_size; index++) + for (index=0; index < iov_size; index++) { rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0, timeout); - if (rv > 0) + if (rv > 0) { sent += rv; - if ( rv != iov[index].iov_len ) + } + if ( rv != iov[index].iov_len ) { if (rv < 0) { @@ -568,11 +571,12 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi PRInt32 _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how) { -PRInt32 rv; + PRInt32 rv; rv = shutdown(fd->secret->md.osfd, how); - if (rv < 0) + if (rv < 0) { _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError()); + } return rv; } @@ -651,7 +655,7 @@ _MD_MakeNonblock(PRFileDesc *f) #define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5 static PRInt32 socket_io_wait( - PROsfd osfd, + PROsfd osfd, PRInt32 fd_type, PRIntervalTime timeout) { @@ -709,15 +713,17 @@ static PRInt32 socket_io_wait( { len = sizeof(err); if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, - (char *) &err, &len) == SOCKET_ERROR) - { + (char *) &err, &len) == SOCKET_ERROR) + { _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError()); return -1; } - if (err != 0) + if (err != 0) { _PR_MD_MAP_CONNECT_ERROR(err); - else + } + else { PR_SetError(PR_UNKNOWN_ERROR, 0); + } return -1; } if (FD_ISSET((SOCKET)osfd, &rd_wr)) @@ -754,8 +760,8 @@ static PRInt32 socket_io_wait( tv.tv_usec = 0; } else { tv.tv_usec = PR_IntervalToMicroseconds( - remaining - - PR_SecondsToInterval(tv.tv_sec)); + remaining - + PR_SecondsToInterval(tv.tv_sec)); } FD_SET(osfd, &rd_wr); FD_SET(osfd, &ex); @@ -789,15 +795,17 @@ static PRInt32 socket_io_wait( { len = sizeof(err); if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, - (char *) &err, &len) == SOCKET_ERROR) - { + (char *) &err, &len) == SOCKET_ERROR) + { _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError()); return -1; } - if (err != 0) + if (err != 0) { _PR_MD_MAP_CONNECT_ERROR(err); - else + } + else { PR_SetError(PR_UNKNOWN_ERROR, 0); + } return -1; } if (FD_ISSET((SOCKET)osfd, &rd_wr)) @@ -822,8 +830,8 @@ static PRInt32 socket_io_wait( if (wait_for_remaining) { elapsed = remaining; } else { - elapsed = PR_SecondsToInterval(tv.tv_sec) - + PR_MicrosecondsToInterval(tv.tv_usec); + elapsed = PR_SecondsToInterval(tv.tv_sec) + + PR_MicrosecondsToInterval(tv.tv_usec); } if (elapsed >= remaining) { PR_SetError(PR_IO_TIMEOUT_ERROR, 0); |