*/
int time_to_check = 1;
-#ifndef HAVE_SPRINTF
+#ifndef HAVE_SNPRINTF
/*
* snprintf(): snprintf() replacement for systems that miss it. Note
* that this implementation does _not_ necessarily protect
#endif
f->dir_listing = 0;
+#if WANT_UPLOAD
+ f->upload = 0;
+#endif
return f;
}
c->buf_len += bytes_avail;
parse_command(c);
- if (fds[c->sock].revents & (POLLERR|POLLHUP|POLLNVAL)) {
+ if (c->free_me || (fds[c->sock].revents & (POLLERR|POLLHUP|POLLNVAL))) {
destroy_conn(c);
}
}
void finish_transfer(struct ftran * const f)
{
char finished[] = "226 Transfer complete.\r\n";
- if (send(f->owner->sock, finished, sizeof(finished), 0) == -1 && errno == EPIPE) {
+ if (send(f->owner->sock, finished, strlen(finished), 0) == -1 && errno == EPIPE) {
destroy_conn(f->owner);
return;
}
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
#endif
if (size > 0 && (write(f->local_file, upload_buf, size) == size)) {
return 1;
- } else if (size == -1) {
+ } else if (size == -1 && errno != EAGAIN) {
/* don't write xferlog... or? */
numeric(f->owner, 426, strerror(errno));
destroy_ftran(f);
memcpy(&(c->addr), &tempaddr, sizeof(struct sockaddr));
#endif
- if (send(tempsock, hello, sizeof(hello), 0) == -1 && errno == EPIPE)
+ if (send(tempsock, hello, strlen(hello), 0) == -1 && errno == EPIPE)
destroy_conn(c);
}
}
{
char fmt[256];
va_list args;
- int i, err;
+ int i;
int in_buf = strlen(message_buf);
snprintf(fmt, 256, "%03u %s\r\n", numeric, 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