|
Lines 316-325
Link Here
|
| 316 |
* one of the file descriptors). |
316 |
* one of the file descriptors). |
| 317 |
*/ |
317 |
*/ |
| 318 |
|
318 |
|
| 319 |
static void |
319 |
static int |
| 320 |
client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, |
320 |
client_wait_until_can_do_something(fd_set **readsetp, fd_set **writesetp, |
| 321 |
int *maxfdp, int *nallocp, int rekeying) |
321 |
int *maxfdp, int *nallocp, int rekeying) |
| 322 |
{ |
322 |
{ |
|
|
323 |
struct timeval tv, *tvp; |
| 324 |
int n; |
| 325 |
extern Options options; |
| 326 |
|
| 323 |
/* Add any selections by the channel mechanism. */ |
327 |
/* Add any selections by the channel mechanism. */ |
| 324 |
channel_prepare_select(readsetp, writesetp, maxfdp, nallocp, rekeying); |
328 |
channel_prepare_select(readsetp, writesetp, maxfdp, nallocp, rekeying); |
| 325 |
|
329 |
|
|
Lines 348-354
Link Here
|
| 348 |
/* clear mask since we did not call select() */ |
352 |
/* clear mask since we did not call select() */ |
| 349 |
memset(*readsetp, 0, *nallocp); |
353 |
memset(*readsetp, 0, *nallocp); |
| 350 |
memset(*writesetp, 0, *nallocp); |
354 |
memset(*writesetp, 0, *nallocp); |
| 351 |
return; |
355 |
return 0; |
| 352 |
} else { |
356 |
} else { |
| 353 |
FD_SET(connection_in, *readsetp); |
357 |
FD_SET(connection_in, *readsetp); |
| 354 |
} |
358 |
} |
|
Lines 367-373
Link Here
|
| 367 |
* SSH_MSG_IGNORE packet when the timeout expires. |
371 |
* SSH_MSG_IGNORE packet when the timeout expires. |
| 368 |
*/ |
372 |
*/ |
| 369 |
|
373 |
|
| 370 |
if (select((*maxfdp)+1, *readsetp, *writesetp, NULL, NULL) < 0) { |
374 |
/* |
|
|
375 |
* We don't do the 'random' bit, but we want periodic ignored |
| 376 |
* message anyway, so as to notice when the other ends TCP |
| 377 |
* has given up during an outage. |
| 378 |
*/ |
| 379 |
|
| 380 |
if (options.protocolkeepalives > 0) { |
| 381 |
tvp = &tv; |
| 382 |
tv.tv_sec = options.protocolkeepalives; |
| 383 |
tv.tv_usec = 0; |
| 384 |
} else |
| 385 |
tvp = 0; |
| 386 |
|
| 387 |
n = select((*maxfdp)+1, *readsetp, *writesetp, NULL, tvp); |
| 388 |
if (n < 0) { |
| 371 |
char buf[100]; |
389 |
char buf[100]; |
| 372 |
|
390 |
|
| 373 |
/* |
391 |
/* |
|
Lines 379-390
Link Here
|
| 379 |
memset(*writesetp, 0, *nallocp); |
397 |
memset(*writesetp, 0, *nallocp); |
| 380 |
|
398 |
|
| 381 |
if (errno == EINTR) |
399 |
if (errno == EINTR) |
| 382 |
return; |
400 |
return 0; |
| 383 |
/* Note: we might still have data in the buffers. */ |
401 |
/* Note: we might still have data in the buffers. */ |
| 384 |
snprintf(buf, sizeof buf, "select: %s\r\n", strerror(errno)); |
402 |
snprintf(buf, sizeof buf, "select: %s\r\n", strerror(errno)); |
| 385 |
buffer_append(&stderr_buffer, buf, strlen(buf)); |
403 |
buffer_append(&stderr_buffer, buf, strlen(buf)); |
| 386 |
quit_pending = 1; |
404 |
quit_pending = 1; |
| 387 |
} |
405 |
} |
|
|
406 |
return n == 0; |
| 388 |
} |
407 |
} |
| 389 |
|
408 |
|
| 390 |
static void |
409 |
static void |
|
Lines 777-782
Link Here
|
| 777 |
{ |
796 |
{ |
| 778 |
fd_set *readset = NULL, *writeset = NULL; |
797 |
fd_set *readset = NULL, *writeset = NULL; |
| 779 |
double start_time, total_time; |
798 |
double start_time, total_time; |
|
|
799 |
int timed_out; |
| 780 |
int max_fd = 0, max_fd2 = 0, len, rekeying = 0, nalloc = 0; |
800 |
int max_fd = 0, max_fd2 = 0, len, rekeying = 0, nalloc = 0; |
| 781 |
char buf[100]; |
801 |
char buf[100]; |
| 782 |
|
802 |
|
|
Lines 884-890
Link Here
|
| 884 |
* available on one of the descriptors). |
904 |
* available on one of the descriptors). |
| 885 |
*/ |
905 |
*/ |
| 886 |
max_fd2 = max_fd; |
906 |
max_fd2 = max_fd; |
| 887 |
client_wait_until_can_do_something(&readset, &writeset, |
907 |
timed_out = client_wait_until_can_do_something(&readset, &writeset, |
| 888 |
&max_fd2, &nalloc, rekeying); |
908 |
&max_fd2, &nalloc, rekeying); |
| 889 |
|
909 |
|
| 890 |
if (quit_pending) |
910 |
if (quit_pending) |
|
Lines 907-912
Link Here
|
| 907 |
|
927 |
|
| 908 |
if (quit_pending) |
928 |
if (quit_pending) |
| 909 |
break; |
929 |
break; |
|
|
930 |
|
| 931 |
if(timed_out) { |
| 932 |
/* |
| 933 |
* Nothing is happening, so synthesize some |
| 934 |
* bogus activity |
| 935 |
*/ |
| 936 |
packet_start(compat20 |
| 937 |
? SSH2_MSG_IGNORE |
| 938 |
: SSH_MSG_IGNORE); |
| 939 |
packet_put_cstring(""); |
| 940 |
packet_send(); |
| 941 |
if (FD_ISSET(connection_out, writeset)) |
| 942 |
packet_write_poll(); |
| 943 |
continue; |
| 944 |
} |
| 910 |
|
945 |
|
| 911 |
if (!compat20) { |
946 |
if (!compat20) { |
| 912 |
/* Buffer data from stdin */ |
947 |
/* Buffer data from stdin */ |