static int wait_for_data(Socket* fp, bool wait_for_read) { errno = 0; const int r = sock_check_pending(fp, !wait_for_read); #if 0 if(r < 0 && errno == EINTR && gvSigStopReceived && ftp_sigints() == 0) { gvSigStopReceived = false; r = 0; } #endif if(r < 0) { /* perror("\nselect");*/ if(errno == EINTR) { if(gvSighupReceived) return 1; if(gvInterrupted) return -1; if(ftp_sigints() == 0) /* assume it is a SIGSTOP/SIGCONT signal */ return 0; } return -1; } if(r) ftp->ti.stalled = 0; else ftp->ti.stalled++; return r; }
void ftp_flush_reply(void) { if(!ftp_connected()) return; #ifdef HAVE_LIBSSH if (ftp->session) return; #endif /* ftp_set_signal(SIGINT, SIG_IGN);*/ fprintf(stderr, "flushing replies...\r"); /* ftp_reply_timeout(10);*/ while(ftp_connected()) { if (sock_check_pending(ftp->ctrl, false) == 1) ftp_read_reply(); else break; } #if 0 if(ftp_loggedin()) ftp_chdir(ftp->curdir); #endif ftp_set_close_handler(); }
/* abort routine originally from Cftp by Dieter Baron */ int ftp_abort(Socket* fp) { char buf[4096]; #ifdef HAVE_LIBSSH if(ftp->session) /* FIXME: what? */ return 0; #endif if(!ftp_connected()) return -1; ftp_set_close_handler(); if (sock_check_pending(fp, false) == 1) { ftp_trace("There is data on the control channel, won't send ABOR\n"); /* read remaining bytes from connection */ while(fp && sock_read(fp, buf, sizeof(buf)) > 0) /* LOOP */ ; return 0; } ftp->ti.interrupted = true; ftp_err(_("Waiting for remote to finish abort...\n")); ftp_trace("--> telnet interrupt\n"); if(sock_telnet_interrupt(ftp->ctrl) != 0) ftp_err("telnet interrupt: %s\n", strerror(errno)); /* ftp_cmd("ABOR") won't work here, * we must flush data between the ABOR command and ftp_read_reply() */ sock_krb_printf(ftp->ctrl, "ABOR"); sock_printf(ftp->ctrl, "\r\n"); sock_flush(ftp->ctrl); if(ftp_get_verbosity() == vbDebug) ftp_err("--> [%s] ABOR\n", ftp->url->hostname); else ftp_trace("--> [%s] ABOR\n", ftp->url->hostname); /* read remaining bytes from connection */ while(fp && sock_read(fp, buf, sizeof(buf)) > 0) /* LOOP */ ; /* we expect a 426 or 226 reply here... */ ftp_read_reply(); if(ftp->fullcode != 426 && ftp->fullcode != 226) ftp_trace("Huh!? Expected a 426 or 226 reply\n"); /* ... and a 226 or 225 reply here, respectively */ /* FIXME: should skip this reply if prev. reply wasn't 426 or 226 ? */ ftp_read_reply(); if(ftp->fullcode != 226 && ftp->fullcode != 225) ftp_trace("Huh!? Expected a 226 or 225 reply\n"); return -1; }