Index: uipc_socket.c =================================================================== RCS file: /home/ncvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.212 diff -u -r1.212 uipc_socket.c --- uipc_socket.c 5 Sep 2004 14:33:21 -0000 1.212 +++ uipc_socket.c 6 Sep 2004 02:52:05 -0000 @@ -2086,43 +2086,57 @@ sopoll(struct socket *so, int events, struct ucred *active_cred, struct thread *td) { + int recv_interesting = 0; + int send_interesting = 0; int revents = 0; - SOCKBUF_LOCK(&so->so_snd); - SOCKBUF_LOCK(&so->so_rcv); - if (events & (POLLIN | POLLRDNORM)) - if (soreadable(so)) - revents |= events & (POLLIN | POLLRDNORM); - - if (events & POLLINIGNEOF) - if (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat || - !TAILQ_EMPTY(&so->so_comp) || so->so_error) - revents |= POLLINIGNEOF; - - if (events & (POLLOUT | POLLWRNORM)) - if (sowriteable(so)) - revents |= events & (POLLOUT | POLLWRNORM); - - if (events & (POLLPRI | POLLRDBAND)) - if (so->so_oobmark || (so->so_rcv.sb_state & SBS_RCVATMARK)) - revents |= events & (POLLPRI | POLLRDBAND); + if (events & (POLLOUT | POLLWRNORM)) { + send_interesting = 1; + SOCKBUF_LOCK(&so->so_snd); + + if (events & (POLLOUT | POLLWRNORM)) + if (sowriteable(so)) + revents |= events & (POLLOUT | POLLWRNORM); + } + + if (events & (POLLIN | POLLRDNORM | POLLINIGNEOF | POLLPRI | + POLLRDBAND)) { + recv_interesting = 1; + SOCKBUF_LOCK(&so->so_rcv); + + if (events & (POLLIN | POLLRDNORM)) + if (soreadable(so)) + revents |= events & (POLLIN | POLLRDNORM); + + if (events & POLLINIGNEOF) + if (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat || + !TAILQ_EMPTY(&so->so_comp) || so->so_error) + revents |= POLLINIGNEOF; + + if (events & (POLLPRI | POLLRDBAND)) + if (so->so_oobmark || (so->so_rcv.sb_state & + SBS_RCVATMARK)) + revents |= events & (POLLPRI | POLLRDBAND); + } if (revents == 0) { - if (events & - (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | - POLLRDBAND)) { + if (recv_interesting) { selrecord(td, &so->so_rcv.sb_sel); so->so_rcv.sb_flags |= SB_SEL; } - if (events & (POLLOUT | POLLWRNORM)) { + if (send_interesting) { selrecord(td, &so->so_snd.sb_sel); so->so_snd.sb_flags |= SB_SEL; } } - SOCKBUF_UNLOCK(&so->so_rcv); - SOCKBUF_UNLOCK(&so->so_snd); + if (recv_interesting) + SOCKBUF_UNLOCK(&so->so_rcv); + + if (send_interesting) + SOCKBUF_UNLOCK(&so->so_snd); + return (revents); }