Fix bug #633333 and may be others (the code related to timeout conditions was quite screwed)

Initial
Stephane Bortzmeyer 20 years ago
parent 0a1f940135
commit afe8f6c903

@ -414,7 +414,7 @@ main (argc, argv)
{ {
(void) fprintf (stderr, (void) fprintf (stderr,
"%s: %s and message size specification are incompatible.\n", "%s: %s and message size specification are incompatible.\n",
http ? "HTTP" : "SMTP", progname); progname, http ? "HTTP" : "SMTP");
exit (1); exit (1);
} }
if (ssl && !http) if (ssl && !http)
@ -777,6 +777,9 @@ main (argc, argv)
for (i = 1; i <= number; i++) for (i = 1; i <= number; i++)
{ {
timeout_flag = 0;
if (timeout_requested)
alarm (timeout);
if (i > 1) if (i > 1)
{ {
#ifdef HAVE_USLEEP #ifdef HAVE_USLEEP
@ -1065,13 +1068,15 @@ main (argc, argv)
{ {
if ((nr < 0 || nr != n) && timeout_flag) if ((nr < 0 || nr != n) && timeout_flag)
{ {
printf
("Timeout while writing (%d byte(s) written so far)\n",
(nr == -1) ? 0 : nr);
nr = n; nr = n;
printf ("Timeout while writing\n");
close (sockfd); close (sockfd);
continue; continue;
} }
else else
err_sys ("writen error on socket"); err_sys ("writen error on TCP socket %d", sockfd);
} }
} }
#ifdef OPENSSL #ifdef OPENSSL
@ -1118,19 +1123,6 @@ main (argc, argv)
} }
} }
#endif #endif
/* Write something to the server */
if (writen (sockfd, sendline, n) != n)
{
if ((nr < 0 || nr != n) && timeout_flag)
{
nr = n;
printf ("Timeout while writing\n");
close (sockfd);
continue;
}
else
err_sys ("writen error on socket");
}
} }
else else
{ {
@ -1259,7 +1251,6 @@ main (argc, argv)
signal (SIGALRM, to_alarm); signal (SIGALRM, to_alarm);
#endif #endif
timeout_flag = 0; /* for signal handler */ timeout_flag = 0; /* for signal handler */
alarm (timeout);
#ifdef ICP #ifdef ICP
if (icp) if (icp)
{ {
@ -1283,7 +1274,6 @@ main (argc, argv)
* Todo: in UDP, we should loop to read: we * Todo: in UDP, we should loop to read: we
* can have several reads necessary. * can have several reads necessary.
*/ */
alarm (0);
if ((nr < 0) && (errno == EINTR) && (timeout_flag)) if ((nr < 0) && (errno == EINTR) && (timeout_flag))
{ {
nr = n; nr = n;
@ -1324,10 +1314,12 @@ main (argc, argv)
else else
/* This is probably HTTP */ /* This is probably HTTP */
{ {
if ((nr < 0) && (errno == EINTR) && (timeout_flag)) /* printf ("DEBUG: received %d bytes (flag is %d, errno is %d)\n", nr, timeout_flag, errno); */
if ((errno == EINTR) && timeout_flag)
{ {
printf ("Timeout while reading (%d byte(s) read)\n", printf
(nr == -1) ? 0 : nr); ("Timeout while reading (%d byte(s) read so far)\n",
(nr == -1) ? 0 : nr);
#ifdef FLUSH_OUTPUT #ifdef FLUSH_OUTPUT
if (fflush ((FILE *) NULL) != 0) if (fflush ((FILE *) NULL) != 0)
{ {
@ -1346,8 +1338,7 @@ main (argc, argv)
printf ("%d bytes read from server.\n", nr); printf ("%d bytes read from server.\n", nr);
} }
} /* That's all, folks */ } /* That's all, folks */
if (tcp) alarm (0);
alarm (0);
if (http) if (http)
{ {
#ifdef OPENSSL #ifdef OPENSSL
@ -1541,6 +1532,7 @@ printstats ()
void void
to_alarm () to_alarm ()
{ {
/* printf ("DEBUG: timeout handler called\n"); */
timeout_flag = 1; /* set flag for function above */ timeout_flag = 1; /* set flag for function above */
} }

@ -60,7 +60,7 @@ read_from_server (CHANNEL fs, short ssl)
#ifdef OPENSSL #ifdef OPENSSL
int sslcode; int sslcode;
#endif #endif
while (!body) while (!body && !timeout_flag)
{ {
if (!ssl) if (!ssl)
nr = readline (fs.fs, big_recvline, MAXTOREAD, TRUE); nr = readline (fs.fs, big_recvline, MAXTOREAD, TRUE);
@ -90,7 +90,7 @@ read_from_server (CHANNEL fs, short ssl)
/* HTTP replies should be separated by CR-LF. Unfortunately, some /* HTTP replies should be separated by CR-LF. Unfortunately, some
servers send only CR :-( */ servers send only CR :-( */
body = ((nr == 2) || (nr == 1)); /* Empty line CR-LF seen */ body = ((nr == 2) || (nr == 1)); /* Empty line CR-LF seen */
if ((nr < 1) && (errno == EINTR)) /* Probably a timeout */ if ((nr < 1) && (timeout_flag)) /* Probably a timeout */
return -1; return -1;
if (nr < 1) if (nr < 1)
/* SourceForge bug #109385 */ /* SourceForge bug #109385 */
@ -120,7 +120,7 @@ read_from_server (CHANNEL fs, short ssl)
nr = TLS_readline (fs.tls, big_recvline, MAXTOREAD, FALSE); nr = TLS_readline (fs.tls, big_recvline, MAXTOREAD, FALSE);
#endif #endif
/* printf ("DEBUG: reading body \"%s\"\n (%d chars)\n", big_recvline, nr); */ /* printf ("DEBUG: reading body \"%s\"\n (%d chars)\n", big_recvline, nr); */
if ((nr < 2) && (errno == EINTR)) /* Probably a timeout */ if ((nr < 2) && (timeout_flag)) /* Probably a timeout */
return -1; return -1;
if (nr < 2) /* Hmm, if the body is empty, we'll if (nr < 2) /* Hmm, if the body is empty, we'll
get a meaningless error message */ get a meaningless error message */

@ -26,6 +26,8 @@ readline (fs, ptr, maxlen, ln)
rc = fgets (ptr, maxlen + 1, fs); rc = fgets (ptr, maxlen + 1, fs);
if (rc == NULL) if (rc == NULL)
{ {
if (timeout_flag)
return n;
return (-1); return (-1);
} }
n = strlen (rc); n = strlen (rc);
@ -36,10 +38,10 @@ readline (fs, ptr, maxlen, ln)
while (n < maxlen) while (n < maxlen)
{ {
r = fread (ptr, 1, maxlen, fs); r = fread (ptr, 1, maxlen, fs);
if (timeout_flag)
return r;
if (r == 0) if (r == 0)
{ {
if (timeout_flag)
return n;
if (n == 1) if (n == 1)
return (0); /* EOF, no data read */ return (0); /* EOF, no data read */
else else

Loading…
Cancel
Save