]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/dsi/dsi_stream.c
Fix a possible bug handling disconnected sessions, NetAFP Bug ID #16
[netatalk.git] / libatalk / dsi / dsi_stream.c
index 6c8b51e4b620da5e5ceec9197e6f5150d4db6f99..ab1339184b48b1394a89415c481f2689ad0d83c9 100644 (file)
@@ -62,6 +62,9 @@ static int dsi_peek(DSI *dsi)
     maxfd = dsi->socket + 1;
 
     while (1) {
+        if (dsi->socket == -1)
+            /* eg dsi_disconnect() might have disconnected us */
+            return -1;
         FD_ZERO(&readfds);
         FD_ZERO(&writefds);
 
@@ -342,6 +345,14 @@ ssize_t dsi_stream_read_file(DSI *dsi, int fromfd, off_t offset, const size_t le
           goto exit;
       }          
       if (errno == EAGAIN || errno == EWOULDBLOCK) {
+#if defined(SOLARIS) || defined(FREEBSD)
+          if (pos > offset) {
+              /* we actually have sent sth., adjust counters and keep trying */
+              len = pos - offset;
+              written += len;
+              offset = pos;
+          }
+#endif
           if (dsi_peek(dsi)) {
               /* can't go back to blocking mode, exit, the next read
                  will return with an error and afpd will die.