diff options
Diffstat (limited to 'nsprpub/pr/src/md/os2/os2poll.c')
-rw-r--r-- | nsprpub/pr/src/md/os2/os2poll.c | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/nsprpub/pr/src/md/os2/os2poll.c b/nsprpub/pr/src/md/os2/os2poll.c index 9a0a00956f..47d9710454 100644 --- a/nsprpub/pr/src/md/os2/os2poll.c +++ b/nsprpub/pr/src/md/os2/os2poll.c @@ -16,16 +16,17 @@ PRBool IsSocketSet( PRInt32 osfd, int* socks, int start, int count ) { - int i; - PRBool isSet = PR_FALSE; + int i; + PRBool isSet = PR_FALSE; - for( i = start; i < start+count; i++ ) - { - if( socks[i] == osfd ) - isSet = PR_TRUE; - } - - return isSet; + for( i = start; i < start+count; i++ ) + { + if( socks[i] == osfd ) { + isSet = PR_TRUE; + } + } + + return isSet; } #endif @@ -55,7 +56,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) wt = 0; ex = 0; socks = (int) PR_MALLOC( npds * 3 * sizeof(int) ); - + if (!socks) { PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); @@ -74,12 +75,12 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) if (pd->in_flags & PR_POLL_READ) { in_flags_read = (pd->fd->methods->poll)( - pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); + pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read); } if (pd->in_flags & PR_POLL_WRITE) { in_flags_write = (pd->fd->methods->poll)( - pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); + pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write); } if ((0 != (in_flags_read & out_flags_read)) || (0 != (in_flags_write & out_flags_write))) @@ -115,8 +116,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) if (0 == ready) { PRInt32 osfd = bottom->secret->md.osfd; - if (osfd > maxfd) + if (osfd > maxfd) { maxfd = osfd; + } if (in_flags_read & PR_POLL_READ) { pd->out_flags |= _PR_POLL_READ_SYS_READ; @@ -124,7 +126,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) FD_SET(osfd, &rd); #else socks[rd] = osfd; - rd++; + rd++; #endif } if (in_flags_read & PR_POLL_WRITE) @@ -134,7 +136,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) FD_SET(osfd, &wt); #else socks[npds+wt] = osfd; - wt++; + wt++; #endif } if (in_flags_write & PR_POLL_READ) @@ -144,7 +146,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) FD_SET(osfd, &rd); #else socks[rd] = osfd; - rd++; + rd++; #endif } if (in_flags_write & PR_POLL_WRITE) @@ -154,7 +156,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout) FD_SET(osfd, &wt); #else socks[npds+wt] = osfd; - wt++; + wt++; #endif } if (pd->in_flags & PR_POLL_EXCEPT) @@ -224,24 +226,28 @@ retry: msecs = PR_IntervalToMilliseconds(remaining); } - /* compact array */ - for( i = rd, j = npds; j < npds+wt; i++,j++ ) + /* compact array */ + for( i = rd, j = npds; j < npds+wt; i++,j++ ) { socks[i] = socks[j]; - for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ ) + } + for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ ) { socks[i] = socks[j]; - + } + ready = os2_select(socks, rd, wt, ex, msecs); #endif if (ready == -1 && errno == EINTR) { - if (timeout == PR_INTERVAL_NO_TIMEOUT) + if (timeout == PR_INTERVAL_NO_TIMEOUT) { goto retry; + } else { elapsed = (PRIntervalTime) (PR_IntervalNow() - start); - if (elapsed > timeout) - ready = 0; /* timed out */ + if (elapsed > timeout) { + ready = 0; /* timed out */ + } else { remaining = timeout - elapsed; @@ -272,38 +278,44 @@ retry: #ifdef BSD_SELECT if (FD_ISSET(osfd, &rd)) #else - if( IsSocketSet(osfd, socks, 0, rd) ) + if( IsSocketSet(osfd, socks, 0, rd) ) #endif { - if (pd->out_flags & _PR_POLL_READ_SYS_READ) + if (pd->out_flags & _PR_POLL_READ_SYS_READ) { out_flags |= PR_POLL_READ; - if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) + } + if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) { out_flags |= PR_POLL_WRITE; - } + } + } #ifdef BSD_SELECT if (FD_ISSET(osfd, &wt)) #else - if( IsSocketSet(osfd, socks, rd, wt) ) + if( IsSocketSet(osfd, socks, rd, wt) ) #endif { - if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) + if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) { out_flags |= PR_POLL_READ; - if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) + } + if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) { out_flags |= PR_POLL_WRITE; - } + } + } #ifdef BSD_SELECT if (FD_ISSET(osfd, &ex)) #else - if( IsSocketSet(osfd, socks, rd+wt, ex) ) + if( IsSocketSet(osfd, socks, rd+wt, ex) ) #endif { out_flags |= PR_POLL_EXCEPT; } } pd->out_flags = out_flags; - if (out_flags) ready++; + if (out_flags) { + ready++; + } } PR_ASSERT(ready > 0); } @@ -323,7 +335,7 @@ retry: { bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER); if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET, - SO_TYPE, (char *) &optval, &optlen) == -1) + SO_TYPE, (char *) &optval, &optlen) == -1) { PR_ASSERT(sock_errno() == ENOTSOCK); if (sock_errno() == ENOTSOCK) @@ -336,8 +348,9 @@ retry: } PR_ASSERT(ready > 0); } - else + else { _PR_MD_MAP_SELECT_ERROR(err); + } } #ifndef BSD_SELECT |