kernel - Tear out socket polling
authorSamuel J. Greear <sjg@thesjg.com>
Mon, 12 Jul 2010 02:56:57 +0000 (02:56 +0000)
committerSamuel J. Greear <sjg@thesjg.com>
Mon, 12 Jul 2010 02:56:57 +0000 (02:56 +0000)
* Remove existing (now legacy) code that implements socket polling, kq
  filters are now the "One True (and only) Way"

* Implement a new socket_wait() that can be used to wait for data to arrive
  on a single descriptor with an optional timeout.

40 files changed:
sys/kern/sys_generic.c
sys/kern/uipc_domain.c
sys/kern/uipc_msg.c
sys/kern/uipc_socket.c
sys/kern/uipc_socket2.c
sys/kern/uipc_usrreq.c
sys/net/netisr.h
sys/net/netmsg.h
sys/net/raw_usrreq.c
sys/net/rtsock.c
sys/netbt/hci_socket.c
sys/netbt/l2cap_socket.c
sys/netbt/rfcomm_socket.c
sys/netbt/sco_socket.c
sys/netgraph/socket/ng_socket.c
sys/netinet/ip_divert.c
sys/netinet/raw_ip.c
sys/netinet/sctp_usrreq.c
sys/netinet/tcp_usrreq.c
sys/netinet/udp_usrreq.c
sys/netinet6/raw_ip6.c
sys/netinet6/sctp6_usrreq.c
sys/netinet6/udp6_usrreq.c
sys/netproto/atalk/ddp_usrreq.c
sys/netproto/atm/atm_aal5.c
sys/netproto/atm/atm_usrreq.c
sys/netproto/ipsec/keysock.c
sys/netproto/ipx/ipx_usrreq.c
sys/netproto/ipx/spx_usrreq.c
sys/netproto/key/keysock.c
sys/netproto/natm/natm.c
sys/netproto/ncp/ncp_ncp.c
sys/netproto/ncp/ncp_sock.c
sys/netproto/ncp/ncp_sock.h
sys/netproto/ns/idp_usrreq.c
sys/netproto/ns/spp_usrreq.c
sys/netproto/smb/smb_trantcp.c
sys/sys/protosw.h
sys/sys/socketops.h
sys/sys/socketvar.h

index 3f6291d..21209d9 100644 (file)
@@ -61,6 +61,7 @@
 #include <sys/poll.h>
 #include <sys/queue.h>
 #include <sys/resourcevar.h>
+#include <sys/socketops.h>
 #include <sys/sysctl.h>
 #include <sys/sysent.h>
 #include <sys/buf.h>
@@ -1365,6 +1366,51 @@ dopoll(int nfds, struct pollfd *fds, struct timespec *ts, int *res)
        return (error);
 }
 
+static int
+socket_wait_copyin(void *arg, struct kevent *kevp, int maxevents, int *events)
+{
+       return (0);
+}
+
+static int
+socket_wait_copyout(void *arg, struct kevent *kevp, int count, int *res)
+{
+       ++*res;
+       return (0);
+}
+
+extern struct fileops socketops;
+int
+socket_wait(struct socket *so, struct timespec *ts, int *res)
+{
+       struct file *fp;
+       struct filedesc fd;
+       struct kqueue kq;
+       struct kevent kev;
+       int error;
+
+       if ((error = falloc(NULL, &fp, NULL)) != 0)
+               return (error);
+
+       fp->f_ops = &socketops;
+       fp->f_data = so;
+       fsetfd(&fd, fp, 0);
+
+       kqueue_init(&kq, &fd);
+
+       EV_SET(&kev, 0, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, NULL);
+       if ((error = kqueue_register(&kq, &kev)) != 0) {
+               fdrop(fp);
+               return (error);
+       }
+
+       error = kern_kevent(&kq, 1, res, NULL, socket_wait_copyin,
+                           socket_wait_copyout, ts);
+       fdrop(fp);
+
+       return (error);
+}
+
 /*
  * OpenBSD poll system call.
  * XXX this isn't quite a true representation..  OpenBSD uses select ops.
index 4fa3067..7fd6efc 100644 (file)
@@ -114,7 +114,6 @@ net_init_domain(struct domain *dp)
                PRU_NOTSUPP(pu, sockaddr);
                PRU_NOTSUPP(pu, sosend);
                PRU_NOTSUPP(pu, soreceive);
-               PRU_NOTSUPP(pu, sopoll);
                PRU_NOTSUPP(pu, ctloutput);
 
                if (pr->pr_init)
index 0340daf..bbff71c 100644 (file)
@@ -362,22 +362,6 @@ so_pru_sockaddr(struct socket *so, struct sockaddr **nam)
        return (error);
 }
 
-int
-so_pru_sopoll(struct socket *so, int events, struct ucred *cred)
-{
-       int error;
-       struct netmsg_pru_sopoll msg;
-
-       netmsg_init(&msg.nm_netmsg, so, &curthread->td_msgport,
-                   0, netmsg_pru_sopoll);
-       msg.nm_prufn = so->so_proto->pr_usrreqs->pru_sopoll;
-       msg.nm_events = events;
-       msg.nm_cred = cred;
-       msg.nm_td = curthread;
-       error = lwkt_domsg(so->so_port, &msg.nm_netmsg.nm_lmsg, 0);
-       return (error);
-}
-
 int
 so_pru_ctloutput(struct socket *so, struct sockopt *sopt)
 {
@@ -590,16 +574,6 @@ netmsg_pru_sockaddr(netmsg_t msg)
        lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(msg->nm_so, nm->nm_nam));
 }
 
-void
-netmsg_pru_sopoll(netmsg_t msg)
-{
-       struct netmsg_pru_sopoll *nm = (void *)msg;
-       int error;
-
-       error = nm->nm_prufn(msg->nm_so, nm->nm_events, nm->nm_cred, nm->nm_td);
-       lwkt_replymsg(&msg->nm_lmsg, error);
-}
-
 void
 netmsg_pru_ctloutput(netmsg_t msg)
 {
index 64a77d4..85e3bee 100644 (file)
@@ -81,7 +81,6 @@
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/event.h>
-#include <sys/poll.h>
 #include <sys/proc.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
@@ -1703,48 +1702,6 @@ sohasoutofband(struct socket *so)
        KNOTE(&so->so_rcv.ssb_sel.si_note, NOTE_OOB);
 }
 
-int
-sopoll(struct socket *so, int events, struct ucred *cred, struct thread *td)
-{
-       int revents = 0;
-
-       crit_enter();
-
-       if (events & (POLLIN | POLLRDNORM))
-               if (soreadable(so))
-                       revents |= events & (POLLIN | POLLRDNORM);
-
-       if (events & POLLINIGNEOF)
-               if (so->so_rcv.ssb_cc >= so->so_rcv.ssb_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_state & SS_RCVATMARK))
-                       revents |= events & (POLLPRI | POLLRDBAND);
-
-       if (revents == 0) {
-               if (events &
-                       (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM |
-                        POLLRDBAND)) {
-                       selrecord(td, &so->so_rcv.ssb_sel);
-                       so->so_rcv.ssb_flags |= SSB_SEL;
-               }
-
-               if (events & (POLLOUT | POLLWRNORM)) {
-                       selrecord(td, &so->so_snd.ssb_sel);
-                       so->so_snd.ssb_flags |= SSB_SEL;
-               }
-       }
-
-       crit_exit();
-       return (revents);
-}
-
 int
 sokqfilter(struct file *fp, struct knote *kn)
 {
index c0918a3..74aadf8 100644 (file)
@@ -596,13 +596,6 @@ pru_soreceive_notsupp(struct socket *so, struct sockaddr **paddr,
        return (EOPNOTSUPP);
 }
 
-int
-pru_sopoll_notsupp(struct socket *so, int events,
-                  struct ucred *cred, struct thread *td)
-{
-       return (EOPNOTSUPP);
-}
-
 int
 pru_ctloutput_notsupp(struct socket *so, struct sockopt *sopt)
 {
index ef89a21..1ebd684 100644 (file)
@@ -468,8 +468,7 @@ struct pr_usrreqs uipc_usrreqs = {
        .pru_shutdown = uipc_shutdown,
        .pru_sockaddr = uipc_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 int
index 5642f2b..4ace6aa 100644 (file)
@@ -183,7 +183,6 @@ void netmsg_pru_sense(netmsg_t);
 void netmsg_pru_shutdown(netmsg_t);
 void netmsg_pru_sockaddr(netmsg_t);
 
-void netmsg_pru_sopoll(netmsg_t);
 void netmsg_pru_ctloutput(netmsg_t);
 void netmsg_pru_ctlinput(netmsg_t);
 
index da0c5c2..bf642de 100644 (file)
@@ -191,14 +191,6 @@ struct netmsg_pru_soreceive {
     int                        *nm_flagsp;
 };
 
-struct netmsg_pru_sopoll {
-    struct netmsg      nm_netmsg;
-    pru_sopoll_fn_t    nm_prufn;
-    int                        nm_events;
-    struct ucred       *nm_cred;
-    struct thread      *nm_td;
-};
-
 struct netmsg_pru_ctloutput {
     struct netmsg      nm_netmsg;
     pru_ctloutput_fn_t nm_prufn;
index dc05009..54be725 100644 (file)
@@ -310,7 +310,5 @@ struct pr_usrreqs raw_usrreqs = {
        .pru_shutdown = raw_ushutdown,
        .pru_sockaddr = raw_usockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
-
index c396b3a..1bd97f6 100644 (file)
@@ -325,8 +325,7 @@ static struct pr_usrreqs route_usrreqs = {
        .pru_shutdown = rts_shutdown,
        .pru_sockaddr = rts_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 static __inline sa_family_t
index 0489721..ae785e7 100644 (file)
@@ -982,6 +982,5 @@ struct pr_usrreqs hci_usrreqs = {
         .pru_shutdown = hci_sshutdown,
         .pru_sockaddr = hci_ssockaddr,
         .pru_sosend = sosend,
-        .pru_soreceive = soreceive,
-        .pru_sopoll = sopoll
+        .pru_soreceive = soreceive
 };
index e822648..4eabfdf 100644 (file)
@@ -456,6 +456,5 @@ struct pr_usrreqs l2cap_usrreqs = {
         .pru_shutdown = l2cap_sshutdown,
         .pru_sockaddr = l2cap_ssockaddr,
         .pru_sosend = sosend,
-        .pru_soreceive = soreceive,
-        .pru_sopoll = sopoll
+        .pru_soreceive = soreceive
 };
index e57c6b6..7d5c02b 100644 (file)
@@ -457,6 +457,5 @@ struct pr_usrreqs rfcomm_usrreqs = {
         .pru_shutdown = rfcomm_sshutdown,
         .pru_sockaddr = rfcomm_ssockaddr,
         .pru_sosend = sosend,
-        .pru_soreceive = soreceive,
-        .pru_sopoll = sopoll
+        .pru_soreceive = soreceive
 };
index 527ac92..5695392 100644 (file)
@@ -426,6 +426,5 @@ struct pr_usrreqs sco_usrreqs = {
         .pru_shutdown = sco_sshutdown,
         .pru_sockaddr = sco_ssockaddr,
         .pru_sosend = sosend,
-        .pru_soreceive = soreceive,
-        .pru_sopoll = sopoll
+        .pru_soreceive = soreceive
 };
index e5a31bb..a11f1bd 100644 (file)
@@ -892,8 +892,7 @@ static struct pr_usrreqs ngc_usrreqs = {
        .pru_shutdown = NULL,
        .pru_sockaddr = ng_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 static struct pr_usrreqs ngd_usrreqs = {
@@ -915,8 +914,7 @@ static struct pr_usrreqs ngd_usrreqs = {
        .pru_shutdown = NULL,
        .pru_sockaddr = ng_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 /*
index 496c626..07b2c47 100644 (file)
@@ -573,8 +573,7 @@ struct pr_usrreqs div_usrreqs = {
        .pru_shutdown = div_shutdown,
        .pru_sockaddr = in_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 static struct mbuf *
index 097bad6..80b1b9b 100644 (file)
@@ -673,6 +673,5 @@ struct pr_usrreqs rip_usrreqs = {
        .pru_shutdown = rip_shutdown,
        .pru_sockaddr = in_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
index 0a6f4f6..cf09ad2 100644 (file)
@@ -4350,8 +4350,7 @@ struct pr_usrreqs sctp_usrreqs = {
        .pru_shutdown = sctp_shutdown,
        .pru_sockaddr = sctp_ingetaddr,
        .pru_sosend = sctp_sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 #else
index 8c5f54f..785d25a 100644 (file)
@@ -831,8 +831,7 @@ struct pr_usrreqs tcp_usrreqs = {
        .pru_shutdown = tcp_usr_shutdown,
        .pru_sockaddr = in_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 #ifdef INET6
@@ -855,8 +854,7 @@ struct pr_usrreqs tcp6_usrreqs = {
        .pru_shutdown = tcp_usr_shutdown,
        .pru_sockaddr = in6_mapped_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 #endif /* INET6 */
 
index 373c407..351965c 100644 (file)
@@ -1165,7 +1165,6 @@ struct pr_usrreqs udp_usrreqs = {
        .pru_shutdown = udp_shutdown,
        .pru_sockaddr = in_setsockaddr,
        .pru_sosend = sosendudp,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
index e65b2bb..0204ad4 100644 (file)
@@ -750,6 +750,5 @@ struct pr_usrreqs rip6_usrreqs = {
        .pru_shutdown = rip6_shutdown,
        .pru_sockaddr = in6_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
index d8e0664..eccd6da 100644 (file)
@@ -1643,8 +1643,7 @@ struct pr_usrreqs sctp6_usrreqs = {
        .pru_shutdown = sctp_shutdown,
        .pru_sockaddr = sctp6_in6getaddr,
        .pru_sosend = sctp_sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 #else
index 23da964..795aea8 100644 (file)
@@ -790,7 +790,6 @@ struct pr_usrreqs udp6_usrreqs = {
        .pru_shutdown = udp_shutdown,
        .pru_sockaddr = in6_mapped_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
index af1e7be..b07142c 100644 (file)
@@ -580,6 +580,5 @@ struct pr_usrreqs ddp_usrreqs = {
        .pru_shutdown = ddp_shutdown,
        .pru_sockaddr = at_setsockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
index b1a761f..c46d98c 100644 (file)
@@ -95,8 +95,7 @@ struct pr_usrreqs     atm_aal5_usrreqs = {
        .pru_shutdown = atm_aal5_shutdown,
        .pru_sockaddr = atm_aal5_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 /*
index 8a928fc..4d043e6 100644 (file)
@@ -68,8 +68,7 @@ struct pr_usrreqs     atm_dgram_usrreqs = {
        .pru_shutdown = atm_proto_notsupp1,
        .pru_sockaddr = atm_proto_notsupp3,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 /*
index b89ad0d..2cca895 100644 (file)
@@ -549,8 +549,7 @@ struct pr_usrreqs key_usrreqs = {
        .pru_shutdown = key_shutdown,
        .pru_sockaddr = key_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 /* sysctl */
index 32b2cdb..fd84623 100644 (file)
@@ -109,8 +109,7 @@ struct      pr_usrreqs ipx_usrreqs = {
        .pru_shutdown = ipx_shutdown,
        .pru_sockaddr = ipx_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 struct pr_usrreqs ripx_usrreqs = {
@@ -132,8 +131,7 @@ struct      pr_usrreqs ripx_usrreqs = {
        .pru_shutdown = ipx_shutdown,
        .pru_sockaddr = ipx_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 /*
index 01509e6..477fffa 100644 (file)
@@ -127,8 +127,7 @@ struct      pr_usrreqs spx_usrreqs = {
        .pru_shutdown = spx_shutdown,
        .pru_sockaddr = ipx_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 struct pr_usrreqs spx_usrreq_sps = {
@@ -150,8 +149,7 @@ struct      pr_usrreqs spx_usrreq_sps = {
        .pru_shutdown = spx_shutdown,
        .pru_sockaddr = ipx_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 static MALLOC_DEFINE(M_SPX_Q, "ipx_spx_q", "IPX Packet Management");
index 4e72b7a..10ed19a 100644 (file)
@@ -554,7 +554,7 @@ struct pr_usrreqs key_usrreqs = {
        key_disconnect, pru_listen_notsupp, key_peeraddr,
        pru_rcvd_notsupp,
        pru_rcvoob_notsupp, key_send, pru_sense_null, key_shutdown,
-       key_sockaddr, sosend, soreceive, sopoll
+       key_sockaddr, sosend, soreceive
 };
 
 /* sysctl */
index cd56285..af9ea73 100644 (file)
@@ -437,8 +437,7 @@ struct pr_usrreqs natm_usrreqs = {
        .pru_shutdown = natm_usr_shutdown,
        .pru_sockaddr = natm_usr_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 #else  /* !FREEBSD_USRREQS */
index f39fc8d..5a4cded 100644 (file)
@@ -191,8 +191,9 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) {
        struct thread *td = conn->td;
        struct ncp_rqhdr *rq;
        struct ncp_rphdr *rp=NULL;
-       struct timeval tv;
+       struct timespec ts;
        struct mbuf *m, *mreply = NULL;
+       int res;
        
        conn->nc_rq = rqp;
        rqp->conn = conn;
@@ -214,8 +215,11 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) {
        crit_enter();
        while (1/*so->so_rcv.sb_cc*/) {
                struct sockbuf sio;
+               ts.tv_sec = 0;
+               ts.tv_nsec = 0;
 
-               if (ncp_poll(so, POLLIN) == 0)
+               error = socket_wait(so, &ts, &res);
+               if (error || !res)
                        break;
                if (ncp_sock_recv(so, &sio) != 0)       
                        break;
@@ -259,15 +263,15 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) {
                        error = ncp_sock_send(so, rqp->rq, rqp);
                        if (error) break;
                }
-               tv.tv_sec = conn->li.timeout;
-               tv.tv_usec = 0;
-               error = ncp_sock_rselect(so, td, &tv, POLLIN);
+               ts.tv_sec = conn->li.timeout;
+               ts.tv_nsec = 0;
+               error = socket_wait(so, &ts, &res);
                if (error == EWOULDBLOCK )      /* timeout expired */
                        continue;
                error = ncp_chkintr(conn, td);
                if (error == EINTR)             /* we dont restart */
                        break;
-               if (error) break;
+               if (error || !res) break;
                /*
                 * At this point it is possible to get more than one
                 * reply from server. In general, last reply should be for
@@ -280,7 +284,11 @@ ncp_do_request(struct ncp_conn *conn, struct ncp_rq *rqp) {
                        struct sockbuf sio;
 
                        error = 0;
-                       if (ncp_poll(so,POLLIN) == 0) break;
+                       ts.tv_sec = 0;
+                       ts.tv_nsec = 0;
+                       error = socket_wait(so, &ts, &res);
+                       if (error || !res)
+                               break;
                        error = ncp_sock_recv(so, &sio);
                        if (error) break;               /* must be more checks !!! */
 
index d239955..efb0201 100644 (file)
@@ -182,64 +182,6 @@ ncp_sock_send(struct socket *so, struct mbuf *top, struct ncp_rq *rqp)
        return error;
 }
 
-int
-ncp_poll(struct socket *so, int events)
-{
-    return (so_pru_sopoll(so, events, NULL));
-}
-
-int
-ncp_sock_rselect(struct socket *so, struct thread *td,
-       struct timeval *tv, int events)
-{
-       struct timeval atv,rtv,ttv;
-       struct lwp *lp = td->td_lwp;
-       int timo,error=0;
-
-       KKASSERT(lp);
-
-       if (tv) {
-               atv=*tv;
-               if (itimerfix(&atv)) {
-                       error = EINVAL;
-                       goto done;
-               }
-               getmicrouptime(&rtv);
-               timevaladd(&atv, &rtv);
-       }
-       timo = 0;
-retry:
-       lp->lwp_flag |= LWP_SELECT;
-       error = ncp_poll(so, events);
-       if (error) {
-               error = 0;
-               goto done;
-       }
-       if (tv) {
-               getmicrouptime(&rtv);
-               if (timevalcmp(&rtv, &atv, >=))
-                       goto done;
-               ttv=atv;
-               timevalsub(&ttv, &rtv);
-               timo = tvtohz_high(&ttv);
-       }
-       crit_enter();
-       if ((lp->lwp_flag & LWP_SELECT) == 0) {
-               crit_exit();
-               goto retry;
-       }
-       lp->lwp_flag &= ~LWP_SELECT;
-       error = tsleep((caddr_t)&selwait, 0, "ncpslt", timo);
-       crit_exit();
-done:
-       lp->lwp_flag &= ~LWP_SELECT;
-       if (error == ERESTART) {
-/*             kprintf("Signal: %x", CURSIG(p));*/
-               error = 0;
-       }
-       return (error);
-}
-
 #ifdef IPX
 /* 
  * Connect to specified server via IPX
index 8bc79b3..2edb07f 100644 (file)
@@ -48,8 +48,6 @@ int  ncp_sock_connect_in(struct ncp_conn *);
 int  ncp_sock_recv(struct socket *so, struct sockbuf *sio);
 int  ncp_sock_send(struct socket *so, struct mbuf *data, struct ncp_rq *rqp);
 int  ncp_sock_disconnect(struct ncp_conn *conn);
-int  ncp_poll(struct socket *so, int events);
-int  ncp_sock_rselect(struct socket *so,struct thread *td, struct timeval *tv,int events);
 int  ncp_sock_checksum(struct ncp_conn *conn, int enable);
 
 void ncp_check_rq(struct ncp_conn *conn);
index 14ffeb1..d8b70f2 100644 (file)
@@ -605,8 +605,7 @@ struct pr_usrreqs idp_usrreqs = {
        .pru_shutdown = idp_shutdown,
        .pru_sockaddr = idp_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 struct pr_usrreqs idp_raw_usrreqs = {
@@ -628,7 +627,6 @@ struct pr_usrreqs idp_raw_usrreqs = {
        .pru_shutdown = idp_shutdown,
        .pru_sockaddr = idp_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
index f95040b..f768b21 100644 (file)
@@ -1641,8 +1641,7 @@ struct pr_usrreqs spp_usrreqs = {
        .pru_shutdown = spp_shutdown,
        .pru_sockaddr = spp_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 struct pr_usrreqs spp_usrreqs_sp = {
@@ -1664,8 +1663,7 @@ struct pr_usrreqs spp_usrreqs_sp = {
        .pru_shutdown = spp_shutdown,
        .pru_sockaddr = spp_sockaddr,
        .pru_sosend = sosend,
-       .pru_soreceive = soreceive,
-       .pru_sopoll = sopoll
+       .pru_soreceive = soreceive
 };
 
 /*
index d47a287..aa57254 100644 (file)
@@ -94,60 +94,6 @@ nb_setsockopt_int(struct socket *so, int level, int name, int val)
        return sosetopt(so, &sopt);
 }
 
-static __inline int
-nb_poll(struct nbpcb *nbp, int events, struct thread *td)
-{
-       return so_pru_sopoll(nbp->nbp_tso, events, NULL);
-}
-
-static int
-nbssn_rselect(struct nbpcb *nbp, struct timeval *tv, int events, struct thread *td)
-{
-       struct lwp *lp = td->td_lwp;
-       struct timeval atv, rtv, ttv;
-       int timo, error;
-
-       if (tv) {
-               atv = *tv;
-               if (itimerfix(&atv)) {
-                       error = EINVAL;
-                       goto done;
-               }
-               getmicrouptime(&rtv);
-               timevaladd(&atv, &rtv);
-       }
-       timo = 0;
-       KKASSERT(lp);
-retry:
-       lp->lwp_flag |= LWP_SELECT;
-       error = nb_poll(nbp, events, td);
-       if (error) {
-               error = 0;
-               goto done;
-       }
-       if (tv) {
-               getmicrouptime(&rtv);
-               if (timevalcmp(&rtv, &atv, >=))
-                       goto done;
-               ttv = atv;
-               timevalsub(&ttv, &rtv);
-               timo = tvtohz_high(&ttv);
-       }
-       crit_enter();
-       if ((lp->lwp_flag & LWP_SELECT) == 0) {
-               crit_exit();
-               goto retry;
-       }
-       lp->lwp_flag &= ~LWP_SELECT;
-       error = tsleep((caddr_t)&selwait, 0, "nbsel", timo);
-       crit_exit();
-done:
-       lp->lwp_flag &= ~LWP_SELECT;
-       if (error == ERESTART)
-               return 0;
-       return error;
-}
-
 static int
 nb_intr(struct nbpcb *nbp, struct thread *td)
 {
@@ -257,11 +203,10 @@ nbssn_rq_request(struct nbpcb *nbp, struct thread *td)
        struct mbchain mb, *mbp = &mb;
        struct mdchain md, *mdp = &md;
        struct mbuf *m0;
-       struct timeval tv;
        struct sockaddr_in sin;
        u_short port;
        u_int8_t rpcode;
-       int error, rplen;
+       int error, rplen, res;
 
        error = mb_init(mbp);
        if (error)
@@ -278,8 +223,7 @@ nbssn_rq_request(struct nbpcb *nbp, struct thread *td)
        mb_done(mbp);
        if (error)
                return error;
-       TIMESPEC_TO_TIMEVAL(&tv, &nbp->nbp_timo);
-       error = nbssn_rselect(nbp, &tv, POLLIN, td);
+       error = socket_wait(nbp->nbp_tso, &nbp->nbp_timo, &res);
        if (error == EWOULDBLOCK) {     /* Timeout */
                NBDEBUG("initial request timeout\n");
                return ETIMEDOUT;
index 88df95e..f716695 100644 (file)
@@ -161,7 +161,7 @@ struct protosw {
 #define        PRU_SOCKADDR            15      /* fetch socket's address */
 #define        PRU_PEERADDR            16      /* fetch peer's address */
 #define        PRU_CONNECT2            17      /* connect two sockets */
-#define PRU_SOPOLL             18
+#define PRU_RESERVED1          18      /* formerly PRU_SOPOLL */
 /* begin for protocols internal use */
 #define        PRU_FASTTIMO            19      /* 200ms timeout */
 #define        PRU_SLOWTIMO            20      /* 500ms timeout */
@@ -179,7 +179,7 @@ const char *prurequests[] = {
        "CONNECT",      "ACCEPT",       "DISCONNECT",   "SHUTDOWN",
        "RCVD",         "SEND",         "ABORT",        "CONTROL",
        "SENSE",        "RCVOOB",       "SENDOOB",      "SOCKADDR",
-       "PEERADDR",     "CONNECT2",     "SOPOLL",
+       "PEERADDR",     "CONNECT2",     "",
        "FASTTIMO",     "SLOWTIMO",     "PROTORCV",     "PROTOSEND",
        "SEND_EOF",     "PREDICATE"
 };
@@ -253,8 +253,6 @@ struct pr_usrreqs {
                                      struct uio *uio,
                                      struct sockbuf *sio,
                                      struct mbuf **controlp, int *flagsp);
-       int     (*pru_sopoll) (struct socket *so, int events,
-                                    struct ucred *cred, struct thread *td);
        int     (*pru_ctloutput) (struct socket *so, struct sockopt *sopt);
 };
 
@@ -292,9 +290,6 @@ typedef int (*pru_soreceive_fn_t) (struct socket *so, struct sockaddr **paddr,
                                        struct sockbuf *sio,
                                        struct mbuf **controlp,
                                        int *flagsp);
-typedef int (*pru_sopoll_fn_t) (struct socket *so, int events,
-                                       struct ucred *cred,
-                                       struct thread *td);
 typedef        int     (*pru_ctloutput_fn_t) (struct socket *so, struct sockopt *sopt);
 typedef        void (*pru_ctlinput_fn_t) (int cmd, struct sockaddr *arg, void *extra);
 
@@ -322,8 +317,6 @@ int pru_soreceive_notsupp(struct socket *so,
                                struct uio *uio,
                                struct sockbuf *sio,
                                struct mbuf **controlp, int *flagsp);
-int    pru_sopoll_notsupp(struct socket *so, int events,
-                               struct ucred *cred, struct thread *td);
 int    pru_ctloutput_notsupp(struct socket *so, struct sockopt *sopt);
 int    pru_sense_null (struct socket *so, struct stat *sb);
 
index a091ebe..d965fcd 100644 (file)
@@ -95,7 +95,6 @@ int so_pru_send (struct socket *so, int flags, struct mbuf *m,
 int so_pru_sense (struct socket *so, struct stat *sb);
 int so_pru_shutdown (struct socket *so);
 int so_pru_sockaddr (struct socket *so, struct sockaddr **nam);
-int so_pru_sopoll (struct socket *so, int events, struct ucred *cred);
 int so_pru_ctloutput(struct socket *so, struct sockopt *sopt);
 void so_pru_ctlinput(struct protosw *pr, int cmd,
                struct sockaddr *arg, void *extra);
index 613467a..d96c923 100644 (file)
@@ -366,6 +366,7 @@ struct      socket *soalloc (int waitok);
 int    sobind (struct socket *so, struct sockaddr *nam, struct thread *td);
 void   socantrcvmore (struct socket *so);
 void   socantsendmore (struct socket *so);
+int    socket_wait (struct socket *so, struct timespec *ts, int *res);
 int    soclose (struct socket *so, int fflags);
 int    soconnect (struct socket *so, struct sockaddr *nam, struct thread *td);
 int    soconnect2 (struct socket *so1, struct socket *so2);
@@ -397,8 +398,6 @@ void        soopt_to_mbuf (struct sockopt *sopt, struct mbuf *m);
 int    soopt_mcopyout (struct sockopt *sopt, struct mbuf *m);
 int    soopt_from_mbuf (struct sockopt *sopt, struct mbuf *m);
 
-int    sopoll (struct socket *so, int events, struct ucred *cred,
-                   struct thread *td);
 int    soreceive (struct socket *so, struct sockaddr **paddr,
                       struct uio *uio, struct sockbuf *sio,
                       struct mbuf **controlp, int *flagsp);