]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
2001-11-08 Pavel Tsekov <ptsekov@syntrex.com>
authorRobert Collins <rbtcollins@hotmail.com>
Fri, 9 Nov 2001 13:03:02 +0000 (13:03 +0000)
committerRobert Collins <rbtcollins@hotmail.com>
Fri, 9 Nov 2001 13:03:02 +0000 (13:03 +0000)
        * simpsock.h (SimpleSocket::invalidate): Declare new method.
        * simpsock.cc (SimpleSocket::invalidate): Implement new method.
        (SimpleSocket::SimpleSocket): Initialize buf to zero. Do not allocate
        memory for buf in the constructor.
        (SimpleSocket::~SimpleSocket): Use SimpleSocket::invalidate().
        (SimpleSocket::printf): Use SimpleSocket::write() instead of send().
        (SimpleSocket::write): Check object consistency - return -1 on error.
        invalidate() the object on socket write error.
        (SimpleSocket::fill): Check object consistency - return -1 on error.
        invalidate() the object if socket read error is encountered and there
        is no more data available in the internal read buffer.
        Allocate memory for the internal read buffer.
        (SimpleSocket::gets): Return zero (NULL pointer) if error is encountered
        during fill() and no more data is available in the internal read buffer.
        (SimpleSocket::read): Check object consistency - return -1 on error.
        invalidate() the object if socket read error is encountered.
        * nio-ftp.cc (NetIO_FTP:NetIO_FTP): Allow 125 as valid response code to
        the RETR command (fix for MS IIS ftp server 5 - possibly others too).
        (NetIO_FTP::ok): Check if the SimpleSocket object is ok().
        (NetIO_FTP::read): Use NetIO_FTP::ok().
        * nio-http.cc: Check for valid return value of SimpleSocket::gets().
        (NetIO_HTTP::ok): Check if the SimpleSocket object is ok().

ChangeLog
nio-ftp.cc
nio-http.cc
simpsock.cc
simpsock.h

index 2b9682eee0b98e69719246ea03b2615660d2c686..fb818781da57b7962c8c86e45b07fb47eee9faf4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2001-11-08  Pavel Tsekov  <ptsekov@syntrex.com>
+       * simpsock.h (SimpleSocket::invalidate): Declare new method.
+       * simpsock.cc (SimpleSocket::invalidate): Implement new method.
+       (SimpleSocket::SimpleSocket): Initialize buf to zero. Do not allocate
+       memory for buf in the constructor.
+       (SimpleSocket::~SimpleSocket): Use SimpleSocket::invalidate().
+       (SimpleSocket::printf): Use SimpleSocket::write() instead of send().
+       (SimpleSocket::write): Check object consistency - return -1 on error.
+       invalidate() the object on socket write error.
+       (SimpleSocket::fill): Check object consistency - return -1 on error.
+       invalidate() the object if socket read error is encountered and there
+       is no more data available in the internal read buffer.
+       Allocate memory for the internal read buffer.
+       (SimpleSocket::gets): Return zero (NULL pointer) if error is encountered
+       during fill() and no more data is available in the internal read buffer.
+       (SimpleSocket::read): Check object consistency - return -1 on error.
+       invalidate() the object if socket read error is encountered.
+       * nio-ftp.cc (NetIO_FTP:NetIO_FTP): Allow 125 as valid response code to
+       the RETR command (fix for MS IIS ftp server 5 - possibly others too).
+       (NetIO_FTP::ok): Check if the SimpleSocket object is ok().
+       (NetIO_FTP::read): Use NetIO_FTP::ok().
+       * nio-http.cc: Check for valid return value of SimpleSocket::gets().
+       (NetIO_HTTP::ok): Check if the SimpleSocket object is ok().
+
 2001-11-09  Robert Collins  <rbtcollins@hotmail.com>
 
        * simpsock.cc (cvsid): Avoid compiler warnings (not used, deprecated conversion).
index fe69835f2189f88ba6b8aa6e68f0c80819b4dab9..c0d0bbc98a45d632d98a12a74f444d2ea08fafa1 100644 (file)
@@ -45,7 +45,7 @@ ftp_line (SimpleSocket *s)
 {
   do {
     last_line = s->gets ();
-    log (LOG_BABBLE, "ftp > %s", last_line);
+    log (LOG_BABBLE, "ftp > %s", last_line ? last_line : "error");
   } while (last_line && (!isdigit (last_line[0]) || last_line[3] != ' '));
   return atoi (last_line ?: "0");
 }
@@ -128,7 +128,7 @@ auth_retry:
 
   cmd->printf ("RETR %s\r\n", path);
   code = ftp_line (cmd);
-  if (code != 150)
+  if (code != 150 && code != 125)
     {
       delete s;
       s = 0;
@@ -145,7 +145,7 @@ NetIO_FTP::~NetIO_FTP ()
 int
 NetIO_FTP::ok ()
 {
-  if (s)
+  if (s && s->ok ())
     return 1;
   return 0;
 }
@@ -153,7 +153,7 @@ NetIO_FTP::ok ()
 int
 NetIO_FTP::read (char *buf, int nbytes)
 {
-  if (!s)
+  if (!ok ())
     return 0;
   return s->read (buf, nbytes);
 }
index 962dcfda4458e87a0a956a1c9782b8674b7c3c71..7f17aa50c305fb463df3d9aa342b663e5da6c36e 100644 (file)
@@ -123,11 +123,12 @@ NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth)
 
   char *l = s->gets ();
   int code;
+  if (!l)
+    return;
   sscanf (l, "%*s %d", &code);
   if (code >= 300 && code < 400)
     {
-      do {
-       l = s->gets ();
+      while ((l = s->gets ()) != 0) {
        if (_strnicmp (l, "Location:", 9) == 0)
          {
            char *u = l + 9;
@@ -137,7 +138,7 @@ NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth)
            delete s;
            goto retry_get;
          }
-      } while (*l);
+      }
     }
   if (code == 401) /* authorization required */
     {
@@ -171,11 +172,10 @@ NetIO_HTTP::NetIO_HTTP (char *Purl, BOOL allow_ftp_auth)
       s = 0;
       return;
     }
-  do {
-    l = s->gets ();
+  while ((l = s->gets ()) != 0) {
     if (_strnicmp (l, "Content-Length:", 15) == 0)
       sscanf (l, "%*s %d", &file_size);
-  } while (*l);
+  }
 }
 
 NetIO_HTTP::~NetIO_HTTP ()
@@ -187,7 +187,7 @@ NetIO_HTTP::~NetIO_HTTP ()
 int
 NetIO_HTTP::ok ()
 {
-  if (s)
+  if (s && s->ok ())
     return 1;
   return 0;
 }
index 3aba9e589cc38d5e1bbfdcce424304e11e1c9f7b..880b2a58778544d77f5c743261a35defaebb9345 100644 (file)
@@ -41,7 +41,7 @@ SimpleSocket::SimpleSocket (const char *hostname, int port)
     }
 
   s = INVALID_SOCKET;
-  buf = (char *) malloc (SSBUFSZ + 3);
+  buf = 0;
   putp = getp = 0;
 
   int i1, i2, i3, i4;
@@ -93,12 +93,7 @@ SimpleSocket::SimpleSocket (const char *hostname, int port)
 
 SimpleSocket::~SimpleSocket ()
 {
-  if (s != INVALID_SOCKET)
-    closesocket (s);
-  s = INVALID_SOCKET;
-  if (buf)
-    free (buf);
-  buf = 0;
+  invalidate ();
 }
 
 int
@@ -116,18 +111,28 @@ SimpleSocket::printf (const char *fmt, ...)
   va_list args;
   va_start (args, fmt);
   vsprintf (buf, fmt, args);
-  return send (s, buf, strlen (buf), 0);
+  return write (buf, strlen (buf));
 }
 
 int
 SimpleSocket::write (const char *buf, int len)
 {
-  return send (s, buf, len, 0);
+  int rv;
+  if (!ok ())
+    return -1;
+  if ((rv = send (s, buf, len, 0)) == -1)
+    invalidate ();
+  return rv;
 }
 
 int
 SimpleSocket::fill ()
 {
+  if (!ok ())
+    return -1;
+
+  if (buf == 0)
+    buf = (char *) malloc (SSBUFSZ + 3);
   if (putp == getp)
     putp = getp = 0;
 
@@ -138,9 +143,12 @@ SimpleSocket::fill ()
   if (r > 0)
     {
       putp += r;
-      return r;
     }
-  return 0;
+  else if (r < 0 && putp == getp)
+    {
+      invalidate();
+    }
+  return r;
 }
 
 char *
@@ -153,7 +161,8 @@ SimpleSocket::gets ()
       getp = 0;
     }
   if (putp == getp)
-    fill();
+    if (fill () <= 0)
+      return 0;
 
   // getp is zero, always, here, and putp is the count
   char *nl;
@@ -167,12 +176,14 @@ SimpleSocket::gets ()
       while ((*nl == '\n' || *nl == '\r') && nl >= buf)
        *nl-- = 0;
     }
-  else
+  else if (putp > getp)
     {
       getp = putp;
       nl = buf + putp;
       nl[1] = 0;
     }
+  else
+    return 0;
 
   return buf;
 }
@@ -182,6 +193,9 @@ SimpleSocket::gets ()
 int
 SimpleSocket::read (char *ubuf, int ulen)
 {
+  if (!ok ())
+    return -1;
+
   int n, rv=0;
   if (putp > getp)
     {
@@ -195,11 +209,25 @@ SimpleSocket::read (char *ubuf, int ulen)
   while (ulen > 0)
     {
       n = recv (s, ubuf, ulen, 0);
+      if (n < 0)
+        invalidate();
       if (n <= 0)
-       return rv;
+        return rv > 0 ? rv : n;
       ubuf += n;
       ulen -= n;
       rv += n;
     }
   return rv;
 }
+
+void
+SimpleSocket::invalidate (void)
+{
+  if (s != INVALID_SOCKET)
+    closesocket (s);
+  s = INVALID_SOCKET;
+  if (buf)
+    free (buf);
+  buf = 0;
+  getp = putp = 0;
+}
index 7fbf4a21c23ca128cd27b196081ce06d1d26b266..e09e6612c61f3d27c71128f693a99950689f3312 100644 (file)
@@ -21,6 +21,7 @@ class SimpleSocket {
   char *buf;
   int putp, getp;
   int fill ();
+  void invalidate (void);
 
  public:
   SimpleSocket (const char *hostname, int port);
This page took 0.044025 seconds and 5 git commands to generate.