]> git.sesse.net Git - betaftpd/blobdiff - ftpd.c
Fixed a file transfer bug, where the initial "150 Opening connection (...)" message...
[betaftpd] / ftpd.c
diff --git a/ftpd.c b/ftpd.c
index 73f1dcad7105cf5232acc6605051e0a0c12798a7..19816bfd489801da7c80087166d1563831b2ad31 100644 (file)
--- a/ftpd.c
+++ b/ftpd.c
@@ -683,12 +683,25 @@ int process_all_sendfiles(fd_set * const active_clients, const int num_ac)
                        f->sock = tempsock;
                        ioctl(f->sock, FIONBIO, &one);
                        init_file_transfer(f);
+                       
+                       flush_numeric(f->owner);
+                       if (f->owner->free_me) {
+                               destroy_conn(f->owner);
+                               continue;
+                       }
+       
 #if WANT_UPLOAD
                        if (f->upload) continue;
 #endif
                }
                if (f->state < 5) {
                        init_file_transfer(f);
+                       
+                       flush_numeric(f->owner);
+                       if (f->owner->free_me) {
+                               destroy_conn(f->owner);
+                               continue;
+                       }
 #if WANT_UPLOAD
                        if (f->upload) continue;
 #endif
@@ -1225,6 +1238,16 @@ void numeric(struct conn * const c, const int numeric, const char * const format
        va_end(args);
 }
 
+/* flush_numeric():
+ *             Actually flushes the buffer written by numeric() -- but does
+ *             NOT erase it. If an error, sets the "free_me" flag in the socket.
+ */
+void flush_numeric(struct conn * const c)
+{
+       if (send(c->sock, message_buf, strlen(message_buf), 0) == -1 && errno == EPIPE)
+               c->free_me = 1;
+}
+
 /*
  * init_file_transfer():
  *             Initiate a data connection for sending. This does not open