s3: Add poll_one_fd()
authorVolker Lendecke <vl@samba.org>
Mon, 7 Feb 2011 15:55:16 +0000 (16:55 +0100)
committerVolker Lendecke <vlendec@samba.org>
Mon, 28 Feb 2011 15:40:19 +0000 (16:40 +0100)
source3/include/proto.h
source3/lib/util_sock.c

index ba0f7adbde987412fb85bd00cc2d22f4206fa107..581c423fa6505fcf47f1f18e4fcf9c169cf4a8dd 100644 (file)
@@ -1333,6 +1333,7 @@ struct tevent_req *getaddrinfo_send(TALLOC_CTX *mem_ctx,
                                    const char *service,
                                    const struct addrinfo *hints);
 int getaddrinfo_recv(struct tevent_req *req, struct addrinfo **res);
+int poll_one_fd(int fd, int events, int timeout, int *revents);
 struct tevent_req *tstream_read_packet_send(TALLOC_CTX *mem_ctx,
                                            struct tevent_context *ev,
                                            struct tstream_context *stream,
index 1de6d17a41ff0cac053024400c6d796def3acc30..3dd84fe8d701b10b9a6d8ef11b7d64df929e5f09 100644 (file)
@@ -1766,3 +1766,30 @@ int getaddrinfo_recv(struct tevent_req *req, struct addrinfo **res)
        }
        return state->ret;
 }
+
+int poll_one_fd(int fd, int events, int timeout, int *revents)
+{
+       struct pollfd *fds;
+       int ret;
+       int saved_errno;
+
+       fds = TALLOC_ZERO_ARRAY(talloc_tos(), struct pollfd, 2);
+       if (fds == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       fds[0].fd = fd;
+       fds[0].events = events;
+
+       ret = sys_poll(fds, 1, timeout);
+
+       /*
+        * Assign whatever poll did, even in the ret<=0 case.
+        */
+       *revents = fds[0].revents;
+       saved_errno = errno;
+       TALLOC_FREE(fds);
+       errno = saved_errno;
+
+       return ret;
+}