version 1.66, 2007/03/06 05:16:01 |
version 1.67, 2007/06/16 08:58:33 |
|
|
return (r); |
return (r); |
} |
} |
|
|
|
int keep_alive_timeout = 0; /* 0 -> no timeout */ |
|
|
|
static int full_noops_sent = 0; |
|
static time_t last_timestamp = 0; /* 0 -> no measurement yet */ |
|
static char noop[] = "NOOP\r\n"; |
|
#define NOOP_LENGTH (sizeof noop - 1) |
|
static int current_nop_pos = 0; /* 0 -> no noop started */ |
|
|
|
/* to achieve keep alive, we send noop one byte at a time */ |
|
void |
|
send_noop_char() |
|
{ |
|
if (debug) |
|
fprintf(ttyout, "---> %c\n", noop[current_nop_pos]); |
|
fputc(noop[current_nop_pos++], cout); |
|
(void)fflush(cout); |
|
if (current_nop_pos >= NOOP_LENGTH) { |
|
full_noops_sent++; |
|
current_nop_pos = 0; |
|
} |
|
} |
|
|
|
void |
|
may_reset_noop_timeout() |
|
{ |
|
if (keep_alive_timeout != 0) |
|
last_timestamp = time(NULL); |
|
} |
|
|
|
void |
|
may_receive_noop_ack() |
|
{ |
|
int i; |
|
|
|
/* finish sending last incomplete noop */ |
|
if (current_nop_pos != 0) { |
|
fputs(&(noop[current_nop_pos]), cout); |
|
if (debug) |
|
fprintf(ttyout, "---> %s\n", &(noop[current_nop_pos])); |
|
(void)fflush(cout); |
|
current_nop_pos = 0; |
|
full_noops_sent++; |
|
} |
|
/* and get the replies */ |
|
for (i = 0; i < full_noops_sent; i++) |
|
(void)getreply(0); |
|
|
|
full_noops_sent = 0; |
|
} |
|
|
|
void |
|
may_send_noop_char() |
|
{ |
|
if (keep_alive_timeout != 0) { |
|
if (last_timestamp != 0) { |
|
time_t t = time(NULL); |
|
|
|
if (t - last_timestamp >= keep_alive_timeout) { |
|
last_timestamp = t; |
|
send_noop_char(); |
|
} |
|
} else { |
|
last_timestamp = time(NULL); |
|
} |
|
} |
|
} |
|
|
char reply_string[BUFSIZ]; /* first line of previous reply */ |
char reply_string[BUFSIZ]; /* first line of previous reply */ |
|
|
int |
int |
|
|
if (dout == NULL) |
if (dout == NULL) |
goto abort; |
goto abort; |
progressmeter(-1); |
progressmeter(-1); |
|
may_reset_noop_timeout(); |
oldintp = signal(SIGPIPE, SIG_IGN); |
oldintp = signal(SIGPIPE, SIG_IGN); |
switch (curtype) { |
switch (curtype) { |
|
|
|
|
case TYPE_L: |
case TYPE_L: |
errno = d = 0; |
errno = d = 0; |
while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) { |
while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) { |
|
may_send_noop_char(); |
bytes += c; |
bytes += c; |
for (bufp = buf; c > 0; c -= d, bufp += d) |
for (bufp = buf; c > 0; c -= d, bufp += d) |
if ((d = write(fileno(dout), bufp, (size_t)c)) |
if ((d = write(fileno(dout), bufp, (size_t)c)) |
|
|
|
|
case TYPE_A: |
case TYPE_A: |
while ((c = fgetc(fin)) != EOF) { |
while ((c = fgetc(fin)) != EOF) { |
|
may_send_noop_char(); |
if (c == '\n') { |
if (c == '\n') { |
while (hash && (!progress || filesize < 0) && |
while (hash && (!progress || filesize < 0) && |
(bytes >= hashbytes)) { |
(bytes >= hashbytes)) { |
|
|
(*closefunc)(fin); |
(*closefunc)(fin); |
(void)fclose(dout); |
(void)fclose(dout); |
(void)getreply(0); |
(void)getreply(0); |
|
may_receive_noop_ack(); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINFO, oldinti); |
(void)signal(SIGINFO, oldinti); |
if (oldintp) |
if (oldintp) |
|
|
preserve = 0; |
preserve = 0; |
} |
} |
progressmeter(-1); |
progressmeter(-1); |
|
may_reset_noop_timeout(); |
switch (curtype) { |
switch (curtype) { |
|
|
case TYPE_I: |
case TYPE_I: |
|
|
ssize_t wr; |
ssize_t wr; |
size_t rd = c; |
size_t rd = c; |
|
|
|
may_send_noop_char(); |
d = 0; |
d = 0; |
do { |
do { |
wr = write(fileno(fout), buf + d, rd); |
wr = write(fileno(fout), buf + d, rd); |
|
|
} |
} |
} |
} |
while ((c = fgetc(din)) != EOF) { |
while ((c = fgetc(din)) != EOF) { |
|
may_send_noop_char(); |
if (c == '\n') |
if (c == '\n') |
bare_lfs++; |
bare_lfs++; |
while (c == '\r') { |
while (c == '\r') { |
|
|
(void)signal(SIGPIPE, oldintp); |
(void)signal(SIGPIPE, oldintp); |
(void)fclose(din); |
(void)fclose(din); |
(void)getreply(0); |
(void)getreply(0); |
|
may_receive_noop_ack(); |
if (bytes >= 0 && is_retr) { |
if (bytes >= 0 && is_retr) { |
if (bytes > 0) |
if (bytes > 0) |
ptransfer(0); |
ptransfer(0); |