]> Pileus Git - ~andy/fetchmail/blobdiff - socket.c
The great name change.
[~andy/fetchmail] / socket.c
index e7d40904f01a56ad74d5ac24194f928af28917ef..b2173755dc6333224fb90090854ff5acdc860f7a 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -5,7 +5,7 @@
 
 /***********************************************************************
   module:       socket.c
-  project:      popclient
+  project:      fetchmail
   programmer:   Carl Harris, ceharris@mal.com
   description:  socket library functions
 
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <sys/time.h>
+#include <sys/ioctl.h>
 #if defined(STDC_HEADERS)
 #include <string.h>
 #endif
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>
 #endif
+#if defined(QNX)
+#include <stdio.h>
+#include <stdarg.h>
+#else
 #include <stdlib.h>
+#endif
 #include <varargs.h>
-
+#include <errno.h>
 #include "bzero.h"
 #include "socket.h"
 
@@ -140,12 +146,13 @@ int len;
     return 0;
 }
 
+static int sbuflen = 0;
+
 int SockInternalRead (socket,buf,len)
 int socket;
 char *buf;
 int len;
 {
-   static int sbuflen = 0;
    static char sbuf [INTERNAL_BUFSIZE];
    static char *bp;
    
@@ -179,11 +186,77 @@ int len;
    else {
      bcopy(bp,buf,len);
      sbuflen -= len;
+#if defined(QNX)
+int SockPrintf(int socket, char* format, ...)
+{
+#else
      bp += len;
    }
    return(len);
 }
+#endif
+
+/* SockClearHeader: call this procedure in order to kill off any
+   forthcoming Header info from the socket that we no longer want.
+   */
+#if defined(QNX)
+    va_start(ap, format) ;
+#else
+int SockClearHeader(socket)
+#endif
+int socket;
+{
+   char *bufp;
+   static char sbuf[INTERNAL_BUFSIZE];
+   int nBytes;
+   int res;
+
+   if ((res = SockDataWaiting(socket))  <= 0)
+     return res;
 
+   while (1) 
+     {
+        if (SockGets(socket,sbuf,INTERNAL_BUFSIZE) < 0)
+         return 0;
+       bufp = sbuf;
+       if (*bufp == '.') {
+         bufp++;
+         if (*bufp == 0)
+           break;
+       }
+     }
+   sbuflen = 0;
+   return 0;
+}
+
+
+/* SockDataWaiting: Return a non-zero value if this socket is waiting
+  for data.   */
+int  SockDataWaiting(int socket)
+{
+  int flags;
+  char sbuf[INTERNAL_BUFSIZE];
+  int n;
+  int res;
+  flags = fcntl(socket,F_GETFL,0);
+  
+  /* set it to non-block */
+  if (fcntl(socket,F_SETFL,flags | O_NONBLOCK) == -1)
+    return -1;
+
+  if ((n = recv(socket,sbuf,INTERNAL_BUFSIZE,MSG_PEEK)) == -1)
+    { 
+      /* No data to read. */
+      if (errno == EWOULDBLOCK)
+       res = 0;
+    }
+  else
+    res = n;
+
+  /* reset it to block (or, whatever it was). */
+  fcntl(socket,F_SETFL,flags);
+  return res;
+}
 
 int SockPrintf(socket,format,va_alist)
 int socket;