]> Pileus Git - ~andy/fetchmail/commitdiff
Anticipate the IDLE extension.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 2 Oct 1999 12:07:02 +0000 (12:07 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 2 Oct 1999 12:07:02 +0000 (12:07 -0000)
svn path=/trunk/; revision=2630

socket.c
socket.h

index c09257234215d09ad69d2e5b3969791c502127b3..058fe2d505123e27ed3625fdb0945802bb3ddd7a 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -92,6 +92,31 @@ static int handle_plugin(const char *host,
 }
 #endif /* HAVE_SOCKETPAIR */
 
+#ifdef __UNUSED__
+#include <sys/time.h>
+
+int SockCheckOpen(int fd)
+/* poll given socket; is it selectable? */
+{
+    fd_set r, w, e;
+    int rt;
+    struct timeval tv;
+  
+    for (;;) 
+    {
+       FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
+       FD_SET(fd, &e);
+    
+       tv.tv_sec = 0; tv.tv_usec = 0;
+       rt = select(fd+1, &r, &w, &e, &tv);
+       if (rt == -1 && (errno != EAGAIN && errno != EINTR))
+           return 0;
+       if (rt != -1)
+           return 1;
+    }
+}
+#endif /* __UNUSED__ */
+
 #if INET6
 int SockOpen(const char *host, const char *service, const char *options,
             const char *plugin)
@@ -148,7 +173,7 @@ int SockOpen(const char *host, const char *service, const char *options,
 int SockOpen(const char *host, int clientPort, const char *options,
             const char *plugin)
 {
-    int sock;
+    int sock = -1;     /* pacify -Wall */
 #ifndef HAVE_INET_ATON
     unsigned long inaddr;
 #endif /* HAVE_INET_ATON */
index c493daa67067f2222e0f35a2f12e34a94471be3f..658918bbfa74902cc5f8da390357223aeee8b7e2 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -16,6 +16,13 @@ int SockOpen(const char *host, int clientPort, const char *options,
             const char *plugin);
 #endif /* INET6 */
 
+/* Returns 1 if this socket is OK, 0 if it isn't select()able
+ * on - probably because it's been closed. You should
+ * always check this function before passing stuff to the
+ * select()-based waiter, as otherwise it may loop. 
+ */
+int SockCheckOpen(int fd);
+
 /* 
 Get a string terminated by an '\n' (matches interface of fgets).
 Pass it a valid socket, a buffer for the string, and