summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>2001-03-02 02:33:07 +0000
committerwtc%netscape.com <devnull@localhost>2001-03-02 02:33:07 +0000
commit5badaa8045ef35f6cfd6b4e05b7c38ce556d18ed (patch)
treed10edd203b768de8cdaf4e5838809804af36b750
parent3cdac5663ce9a88604a32cca7336ce610e4d2801 (diff)
downloadnspr-hg-5badaa8045ef35f6cfd6b4e05b7c38ce556d18ed.tar.gz
Bugzilla bug #62877: checked in patches contributed by Javier Pedemonte
<pedemont@us.ibm.com> and Dmitry Kubov <dmitry@north.cs.msu.su>. Modified files: prinet.h, _os2.h, os2poll.c, and os2sock.c. (NSPRPUB_CLIENT_BRANCH)
-rw-r--r--pr/include/md/_os2.h12
-rw-r--r--pr/include/prinet.h2
-rw-r--r--pr/src/md/os2/os2poll.c154
-rw-r--r--pr/src/md/os2/os2sock.c268
4 files changed, 321 insertions, 115 deletions
diff --git a/pr/include/md/_os2.h b/pr/include/md/_os2.h
index 70e8d112..6d0170e0 100644
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -43,6 +43,11 @@
#define sock_errno() errno
#define soclose close
#define sock_init()
+
+#include <sys/builtin.h>
+#include <sys/smutex.h>
+static _smutex _md_shm_lock = 0;
+
#endif
/*
@@ -251,7 +256,14 @@ extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
#define _MD_GETPEERNAME (_PR_MD_GETPEERNAME)
#define _MD_GETSOCKOPT (_PR_MD_GETSOCKOPT)
#define _MD_SETSOCKOPT (_PR_MD_SETSOCKOPT)
+
+#ifdef XP_OS2_EMX
+extern PRInt32 _MD_SELECT(int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout);
+#else
#define _MD_SELECT select
+#endif
+
#define _MD_FSYNC _PR_MD_FSYNC
#define _MD_SET_FD_INHERITABLE (_PR_MD_SET_FD_INHERITABLE)
diff --git a/pr/include/prinet.h b/pr/include/prinet.h
index 440352ed..994ce806 100644
--- a/pr/include/prinet.h
+++ b/pr/include/prinet.h
@@ -75,7 +75,7 @@ struct sockaddr_dl;
* socket headers.
*/
#if defined(OS2) && !defined(INADDR_LOOPBACK)
-#define INADDR_LOOPBACK gethostid()
+#define INADDR_LOOPBACK 0x7f000001
#endif
/*
diff --git a/pr/src/md/os2/os2poll.c b/pr/src/md/os2/os2poll.c
index 47b1791e..99740c66 100644
--- a/pr/src/md/os2/os2poll.c
+++ b/pr/src/md/os2/os2poll.c
@@ -61,6 +61,9 @@ PRInt32 _PR_MD_PR_POLL(
return 0;
}
+ remaining = timeout;
+ start = PR_IntervalNow();
+
FD_ZERO(&rd);
FD_ZERO(&wt);
FD_ZERO(&ex);
@@ -161,9 +164,6 @@ PRInt32 _PR_MD_PR_POLL(
if (0 != ready) return ready; /* no need to block */
- remaining = timeout;
- start = PR_IntervalNow();
-
retry:
if (timeout != PR_INTERVAL_NO_TIMEOUT)
{
@@ -260,3 +260,151 @@ retry:
return ready;
}
+#ifdef XP_OS2_EMX
+HMTX thread_select_mutex = 0; /* because EMX's select is not thread safe - duh! */
+
+typedef struct _thread_select_st {
+ int nfds;
+ int isrdfds;
+ struct _fd_set *readfds;
+ int iswrfds;
+ struct _fd_set *writefds;
+ int isexfds;
+ struct _fd_set *exceptfds;
+ int istimeout;
+ struct timeval timeout;
+ volatile HEV event;
+ int result;
+ int select_errno;
+ volatile int done;
+} *pthread_select_t;
+
+void _thread_select(void * arg)
+{
+ pthread_select_t self = arg;
+ int result, chkstdin;
+ struct _fd_set readfds;
+ struct _fd_set writefds;
+ struct _fd_set exceptfds;
+ HEV event = self->event;
+
+ chkstdin = (self->isrdfds && FD_ISSET(0,self->readfds))?1:0;
+
+ do {
+ struct timeval timeout = {0L,0L};
+
+
+ if (self->isrdfds) readfds = *self->readfds;
+ if (self->iswrfds) writefds = *self->writefds;
+ if (self->isexfds) exceptfds = *self->exceptfds;
+
+ if (chkstdin) FD_CLR(0,&readfds);
+
+ if (!thread_select_mutex)
+ DosCreateMutexSem(NULL,&thread_select_mutex,0,1);
+ else
+ DosRequestMutexSem(thread_select_mutex,SEM_INDEFINITE_WAIT);
+ result = select(
+ self->nfds,
+ self->isrdfds?&readfds:NULL,
+ self->iswrfds?&writefds:NULL,
+ self->isexfds?&exceptfds:NULL,
+ &timeout);
+ DosReleaseMutexSem(thread_select_mutex);
+
+ if (chkstdin) {
+ int charcount = 0, res;
+ res = ioctl(0,FIONREAD,&charcount);
+ if (res==0 && charcount>0) FD_SET(0,&readfds);
+ }
+
+ if (result>0) {
+ self->done++;
+ if (self->isrdfds) *self->readfds = readfds;
+ if (self->iswrfds) *self->writefds = writefds;
+ if (self->isexfds) *self->exceptfds = exceptfds;
+ } else
+ if (result) self->done++;
+ else DosSleep(1);
+
+ } while (self->event!=0 && self->done==0);
+
+ if (self->event) {
+ self->select_errno = (result < 0)?errno:0;
+ self->result = result;
+ self->done = 3;
+ DosPostEventSem(event);
+ } else {
+ self->done = 3;
+ free(self);
+ }
+
+}
+
+PRInt32
+_MD_SELECT(int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
+{
+ pthread_select_t sel;
+ HEV ev = 0;
+ HTIMER timer = 0;
+ int result = 0;
+ APIRET rc;
+ unsigned long msecs = SEM_INDEFINITE_WAIT;
+
+ if (timeout) {
+ if (timeout->tv_sec != 0 || timeout->tv_usec != 0)
+ msecs = (timeout->tv_sec * 1000L) + (timeout->tv_usec / 1000L);
+ else
+ msecs = SEM_IMMEDIATE_RETURN;
+ };
+
+ if (!(sel = (pthread_select_t) malloc(sizeof(struct _thread_select_st)))) {
+ result = -1;
+ errno = ENOMEM;
+ } else {
+ sel->nfds = nfds;
+ sel->isrdfds = readfds?1:0;
+ if (sel->isrdfds) sel->readfds = readfds;
+ sel->iswrfds = writefds?1:0;
+ if (sel->iswrfds) sel->writefds = writefds;
+ sel->isexfds = exceptfds?1:0;
+ if (sel->isexfds) sel->exceptfds = exceptfds;
+ sel->istimeout = timeout?1:0;
+ if (sel->istimeout) sel->timeout = *timeout;
+
+ rc = DosCreateEventSem(NULL,&ev,0,FALSE);
+
+ sel->event = ev;
+ if (msecs == SEM_IMMEDIATE_RETURN)
+ sel->done = 1;
+ else
+ sel->done = 0;
+
+ if (_beginthread(_thread_select,NULL,65536,(void *)sel) == -1) {
+ result = -1; sel->event = 0;
+ DosCloseEventSem(ev);
+ } else {
+ rc = DosWaitEventSem(ev,msecs);
+ if ((!sel->done) && (msecs != SEM_IMMEDIATE_RETURN)) { /* Interrupted by other thread or timeout */
+ sel->event = 0;
+ result = 0;
+ errno = ETIMEDOUT;
+
+ } else {
+ while (sel->done && sel->done != 3) {
+ DosSleep(1);
+ }
+ sel->event = 0;
+ result = sel->result;
+ if (sel->select_errno) errno = sel->select_errno;
+ free(sel);
+ }
+ rc = DosCloseEventSem(ev);
+ }
+ }
+
+ return (result);
+}
+
+#endif
diff --git a/pr/src/md/os2/os2sock.c b/pr/src/md/os2/os2sock.c
index 34f5ff43..d8e78a0e 100644
--- a/pr/src/md/os2/os2sock.c
+++ b/pr/src/md/os2/os2sock.c
@@ -55,7 +55,7 @@ _PR_MD_SOCKET(int af, int type, int flags)
{
int rv = sock_errno();
soclose(sock);
- _PR_MD_MAP_SOCKET_ERROR(rv);
+ _PR_MD_MAP_SOCKET_ERROR(rv);
return (PRInt32) -1;
}
@@ -82,8 +82,8 @@ _MD_CloseSocket(PRInt32 osfd)
PRInt32 rv = -1;
rv = soclose((int) osfd );
- if (rv < 0)
- _PR_MD_MAP_SOCKET_ERROR(sock_errno());
+ if (rv < 0)
+ _PR_MD_MAP_SOCKET_ERROR(sock_errno());
return rv;
}
@@ -94,7 +94,7 @@ _MD_SocketAvailable(PRFileDesc *fd)
PRInt32 result;
if (ioctl(fd->secret->md.osfd, FIONREAD, (char *) &result, sizeof(result)) < 0) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, sock_errno());
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, sock_errno());
return -1;
}
return result;
@@ -124,18 +124,18 @@ _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
&& (!fd->secret->nonblocking))
{
#ifdef BSD_SELECT
- if ((rv = select(osfd + 1, &rd, NULL, NULL,NULL)) == -1) {
+ if ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL,NULL)) == -1) {
#else
- if ((rv = select(socks, 1, 0, 0, -1)) == -1) {
+ if ((rv = _MD_SELECT(socks, 1, 0, 0, -1)) == -1) {
#endif
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
break;
- }
+ }
}
else {
- _PR_MD_MAP_ACCEPT_ERROR(err);
+ _PR_MD_MAP_ACCEPT_ERROR(err);
break;
- }
+ }
}
return(rv);
}
@@ -146,14 +146,14 @@ _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
if (((err = sock_errno()) == EWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
}
else
{
_PR_MD_MAP_ACCEPT_ERROR(err);
}
}
- return(rv);
+ return(rv);
}
else
{
@@ -165,26 +165,25 @@ retry:
{
#ifdef BSD_SELECT
tv.tv_sec = PR_IntervalToSeconds(timeout);
- tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ tv.tv_usec = PR_IntervalToMicroseconds(timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
- rv = select(osfd + 1, &rd, NULL, NULL, tvp);
+ rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, tvp);
#else
long lTimeout = PR_IntervalToMilliseconds(timeout);
- rv = select(socks, 1, 0, 0, lTimeout);
+ rv = _MD_SELECT(socks, 1, 0, 0, lTimeout);
#endif
if (rv > 0) {
goto retry;
}
else if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
rv = -1;
} else {
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
}
} else {
- _PR_MD_MAP_ACCEPT_ERROR(err);
+ _PR_MD_MAP_ACCEPT_ERROR(err);
}
}
}
@@ -201,7 +200,11 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRInt32 rv;
int err, len;
#ifdef BSD_SELECT
+#ifdef XP_OS2//_VACPP
+ fd_set wd;
+#else
fd_set wd, ex;
+#endif #vacpp
struct timeval tv, *tvp;
#else
int socks[1];
@@ -219,17 +222,20 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
else
{
tv.tv_sec = PR_IntervalToSeconds(timeout);
- tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ tv.tv_usec = PR_IntervalToMicroseconds(timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET(osfd, &wd);
+#ifdef XP_OS2//_VACPP
+ rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, tvp);
+#else
FD_ZERO(&ex);
FD_SET(osfd, &ex);
- rv = select(osfd + 1, NULL, &wd, &ex, tvp);
-#else
+ rv = _MD_SELECT(osfd + 1, NULL, &wd, &ex, tvp);
+#endif #vacpp
+#else #!bsd_select
if (timeout == PR_INTERVAL_NO_TIMEOUT)
lTimeout = -1;
else
@@ -238,11 +244,38 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
}
socks[0] = osfd;
- rv = select(socks, 0, 1, 1, lTimeout);
+#ifdef XP_OS2//_VACPP
+ rv = _MD_SELECT(socks, 0, 1, 0, lTimeout);
+#else
+ rv = _MD_SELECT(socks, 0, 1, 1, lTimeout);
+#endif #vacpp
#endif
if (rv > 0)
{
#ifdef BSD_SELECT
+#ifdef XP_OS2//_VACPP
+ if (FD_ISSET(osfd, &wd))
+ {
+ //DosSleep(0);
+ len = sizeof(err);
+ if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
+ (char *) &err, &len) < 0)
+ {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());
+ return -1;
+ }
+
+ if (err != 0)
+ {
+ _PR_MD_MAP_CONNECT_ERROR(err);
+ return -1;
+ }
+ else
+ return 0; /* it's connected */
+ }
+ else
+ return -1;
+#else
if (FD_ISSET(osfd, &ex))
{
DosSleep(0);
@@ -264,24 +297,37 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
/* it's connected */
return 0;
}
-#else
- if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) < 0)
- {
- _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());
- return -1;
- }
- else
- return 0; /* It's connected ! */
+#endif #vacpp
+#else #!bsd_select
+ if (socks[0] == osfd)
+ {
+ len = sizeof(err);
+ if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
+ (char *) &err, &len) < 0)
+ {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());
+ return -1;
+ }
+
+ if (err != 0)
+ {
+ _PR_MD_MAP_CONNECT_ERROR(err);
+ return -1;
+ }
+ else
+ return 0; /* it's connected */
+ }
+ else
+ return -1;
#endif
- }
+ }
else if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
return(-1);
} else if (rv < 0)
{
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
return(-1);
}
}
@@ -340,7 +386,7 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
- if ((rv = select(osfd + 1, &rd, NULL, NULL, tvp)) == -1)
+ if ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, tvp)) == -1)
#else
socks[0] = osfd;
if (timeout == PR_INTERVAL_NO_TIMEOUT)
@@ -351,22 +397,22 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
{
lTimeout = PR_IntervalToMilliseconds(timeout);
}
- if ((rv = select(socks, 1, 0, 0, lTimeout)) == -1)
+ if ((rv = _MD_SELECT(socks, 1, 0, 0, lTimeout)) == -1)
#endif
{
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
return -1;
}
else if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
rv = -1;
break;
}
}
else
{
- _PR_MD_MAP_RECV_ERROR(err);
+ _PR_MD_MAP_RECV_ERROR(err);
break;
}
} /* end while() */
@@ -409,7 +455,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
FD_ZERO(&wd);
FD_SET(osfd, &wd);
- if ((rv = select( osfd + 1, NULL, &wd, NULL,tvp)) == -1) {
+ if ((rv = _MD_SELECT( osfd + 1, NULL, &wd, NULL,tvp)) == -1) {
#else
if ( timeout == PR_INTERVAL_NO_TIMEOUT )
{
@@ -420,21 +466,21 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
lTimeout = PR_IntervalToMilliseconds(timeout);
}
socks[0] = osfd;
- if ((rv = select( socks, 0, 1, 0, lTimeout)) == -1) {
+ if ((rv = _MD_SELECT( socks, 0, 1, 0, lTimeout)) == -1) {
#endif
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
break;
- }
+ }
if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- return -1;
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ return -1;
}
}
else {
- _PR_MD_MAP_SEND_ERROR(err);
+ _PR_MD_MAP_SEND_ERROR(err);
return -1;
- }
+ }
}
bytesSent += rv;
if (fd->secret->nonblocking)
@@ -457,7 +503,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
FD_ZERO(&wd);
FD_SET(osfd, &wd);
- if ((rv = select(osfd + 1, NULL, &wd, NULL,tvp)) == -1) {
+ if ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL,tvp)) == -1) {
#else
if ( timeout == PR_INTERVAL_NO_TIMEOUT )
{
@@ -468,15 +514,15 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
lTimeout = PR_IntervalToMilliseconds(timeout);
}
socks[0] = osfd;
- if ((rv = select(socks, 0, 1, 0,lTimeout)) == -1) {
+ if ((rv = _MD_SELECT(socks, 0, 1, 0,lTimeout)) == -1) {
#endif
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
break;
- }
+ }
if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- return -1;
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ return -1;
}
}
}
@@ -520,7 +566,7 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
FD_ZERO(&wd);
FD_SET(osfd, &wd);
- if ((rv = select(osfd + 1, NULL, &wd, NULL, tvp)) == -1) {
+ if ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, tvp)) == -1) {
#else
if ( timeout == PR_INTERVAL_NO_TIMEOUT )
{
@@ -531,21 +577,21 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
lTimeout = PR_IntervalToMilliseconds(timeout);
}
socks[0] = osfd;
- if ((rv = select(socks, 0, 1, 0, lTimeout)) == -1) {
+ if ((rv = _MD_SELECT(socks, 0, 1, 0, lTimeout)) == -1) {
#endif
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
break;
- }
+ }
if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- return -1;
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ return -1;
}
}
else {
- _PR_MD_MAP_SENDTO_ERROR(err);
+ _PR_MD_MAP_SENDTO_ERROR(err);
return -1;
- }
+ }
}
bytesSent += rv;
if (fd->secret->nonblocking)
@@ -568,7 +614,7 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
FD_ZERO(&wd);
FD_SET(osfd, &wd);
- if ((rv = select( osfd + 1, NULL, &wd, NULL, tvp)) == -1) {
+ if ((rv = _MD_SELECT( osfd + 1, NULL, &wd, NULL, tvp)) == -1) {
#else
if ( timeout == PR_INTERVAL_NO_TIMEOUT )
{
@@ -579,15 +625,15 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
lTimeout = PR_IntervalToMilliseconds(timeout);
}
socks[0] = osfd;
- if ((rv = select( socks, 0, 1, 0, lTimeout)) == -1) {
+ if ((rv = _MD_SELECT( socks, 0, 1, 0, lTimeout)) == -1) {
#endif
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
break;
- }
+ }
if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- return -1;
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ return -1;
}
}
}
@@ -616,20 +662,20 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
&& (!fd->secret->nonblocking))
{
#ifdef BSD_SELECT
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
- {
- tvp = NULL;
- }
- else
- {
- tv.tv_sec = PR_IntervalToSeconds(timeout);
- tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
- tvp = &tv;
- }
- FD_ZERO(&rd);
- FD_SET(osfd, &rd);
- if ((rv = select(osfd + 1, &rd, NULL, NULL, tvp)) == -1)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ {
+ tvp = NULL;
+ }
+ else
+ {
+ tv.tv_sec = PR_IntervalToSeconds(timeout);
+ tv.tv_usec = PR_IntervalToMicroseconds(
+ timeout - PR_SecondsToInterval(tv.tv_sec));
+ tvp = &tv;
+ }
+ FD_ZERO(&rd);
+ FD_SET(osfd, &rd);
+ if ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, tvp)) == -1)
#else
if (timeout == PR_INTERVAL_NO_TIMEOUT)
{
@@ -640,14 +686,14 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
lTimeout = PR_IntervalToMilliseconds(timeout);
}
socks[0] = osfd;
- if ((rv = select(socks, 1, 0, 0, lTimeout)) == -1)
+ if ((rv = _MD_SELECT(socks, 1, 0, 0, lTimeout)) == -1)
#endif
{
- _PR_MD_MAP_SELECT_ERROR(sock_errno());
+ _PR_MD_MAP_SELECT_ERROR(sock_errno());
return -1;
} else if (rv == 0)
{
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+ PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
rv = -1;
break;
}
@@ -657,7 +703,7 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
else
{
- _PR_MD_MAP_RECVFROM_ERROR(err);
+ _PR_MD_MAP_RECVFROM_ERROR(err);
break;
}
}
@@ -702,12 +748,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)
- _PR_MD_MAP_SHUTDOWN_ERROR(sock_errno());
- return rv;
+ if (rv < 0)
+ _PR_MD_MAP_SHUTDOWN_ERROR(sock_errno());
+ return rv;
}
PRStatus
@@ -717,11 +763,11 @@ _PR_MD_GETSOCKNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
rv = getsockname((int)fd->secret->md.osfd, (struct sockaddr *)addr, (int *) len);
if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKNAME_ERROR(sock_errno());
- return PR_FAILURE;
- }
+ return PR_SUCCESS;
+ else {
+ _PR_MD_MAP_GETSOCKNAME_ERROR(sock_errno());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -731,11 +777,11 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
rv = getpeername((int)fd->secret->md.osfd, (struct sockaddr *)addr, (int *) len);
if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETPEERNAME_ERROR(sock_errno());
- return PR_FAILURE;
- }
+ return PR_SUCCESS;
+ else {
+ _PR_MD_MAP_GETPEERNAME_ERROR(sock_errno());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -745,11 +791,11 @@ _PR_MD_GETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval,
rv = getsockopt((int)fd->secret->md.osfd, level, optname, optval, optlen);
if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());
- return PR_FAILURE;
- }
+ return PR_SUCCESS;
+ else {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(sock_errno());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -759,11 +805,11 @@ _PR_MD_SETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* op
rv = setsockopt((int)fd->secret->md.osfd, level, optname, (char *) optval, optlen);
if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_SETSOCKOPT_ERROR(sock_errno());
- return PR_FAILURE;
- }
+ return PR_SUCCESS;
+ else {
+ _PR_MD_MAP_SETSOCKOPT_ERROR(sock_errno());
+ return PR_FAILURE;
+ }
}
void