Reverting to unbuffered readline.

TOS
Stephane Bortzmeyer 24 years ago
parent dc3b8101fd
commit e9f763c323

@ -1,7 +1,9 @@
Check the TCP timeout with T/TCP
Check the TCP timeout with T/TCP. Difficult to test, few T/TCP
machines exist.
TCP timeout with long packets seem to confuse Cisco routers
TCP timeout with long packets seem to confuse Cisco routers.
ICP always replies even when timeouting. Bug 108577
ICP always replies even when timeouting?
$Id$

@ -391,8 +391,6 @@ main (argc, argv)
for (i = 1; i <= number; i++)
{
clear_read_buffer();
attempts++;
if (!udp)
{

@ -3,7 +3,9 @@
#define DEFLINE 256
#define MAXLINE 65535
#define UDPMAX 65535
#ifdef HTTP
#define MAXTOREAD 150000
#endif
#define MAXNUMBER 20
/* Settings you should not change */
@ -93,7 +95,6 @@ char *sys_err_str ();
int writen ();
/* readline.c */
int readline ();
void clear_read_buffer ();
/* util.c */
char *random_string ();
void tvsub ();

@ -68,7 +68,6 @@ read_from_server (int fd)
while (!body)
{
nr = readline (fd, big_recvline, MAXTOREAD, TRUE);
/* printf ("DEBUG HTTP, I got (%s)\n", big_recvline); */
/* HTTP replies should be separated by CR-LF. Unfortunately, some
servers send only CR :-( */
body = ((nr == 2) || (nr == 1)); /* Empty line CR-LF seen */
@ -92,9 +91,8 @@ read_from_server (int fd)
nr = readline (fd, big_recvline, MAXTOREAD, FALSE);
if ((nr < 2) && (errno == EINTR)) /* Probably a timeout */
return -1;
if (nr < 2) /* Hmm, if the body is empty, we'll
get a meaningless error message */
err_sys ("Reading HTTP body, may be empty");
if (nr < 2) /* Hmm, if the body is empty, we'll get a meaningless error message */
err_sys ("Reading HTTP body");
total = total + nr;
return total; /* How to do if we want only the body's size? */
}

@ -1,19 +1,18 @@
/*
* Read a line from a descriptor.
* Read a line from a descriptor. Read the line one byte at a time, looking
* for the newline. We store the newline in the buffer, then follow it with
* a null (the same as fgets(3)). We return the number of characters up to,
* but not including, the null (the same as strlen(3)). If ln == 0, we treat
* newline as an ordinary charracter.
*
* To save read() system calls, we first check the static buffer if it
* still contains data. If so, we send it back. Otherwise, we call
* read().
*
* If ln == 0, we treat newline as an ordinary charracter.
* Stolen from Stevens' book
*
* $Id$
* */
*
*/
#include "echoping.h"
char buffer[MAXTOREAD]; /* Must survive between calls to readline */
int
readline (fd, ptr, maxlen, ln)
int fd;
@ -21,71 +20,30 @@ readline (fd, ptr, maxlen, ln)
int maxlen;
unsigned short ln;
{
char *origptr = ptr;
int n, i, j, rc;
char s[maxlen];
int bufend = strlen(buffer);
int n, rc;
char c;
n = 0;
/* Use the buffer if it is still full */
for (i = 0; i < strlen(buffer); i++) {
*ptr++ = buffer[i];
n++;
if (buffer[i] == '\n' && ln == 1)
break;
}
if (n) {
/* printf ("DEBUG, got %d bytes from the buffer\n", i); */
strcpy (buffer, (char *)(buffer+i+1));
*ptr = 0;
return (n);
}
bufend = strlen (buffer);
reading:
for (; n < maxlen;)
for (n = 1; n < maxlen; n++)
{
if (timeout_flag)
return n;
if ((rc = read (fd, &s, maxlen)) > 0)
if ((rc = read (fd, &c, 1)) == 1)
{
/* printf ("DEBUG, %d bytes asked (nl = %d) %d bytes read\n", maxlen, ln, rc); */
parsing:
for (i = 0; i < rc; i++) {
*ptr++ = s[i];
/* printf ("DEBUG, adding %c ", s[i]); */
n++;
if (s[i] == '\n' && ln == 1) {
for (j = i+1; j < rc; j++) {
buffer[bufend++] = s[j];
}
break;
}
}
if (s[i] == '\n' && ln == 1) {
*ptr++ = c;
if (c == '\n' && ln == 1)
break;
}
}
else if (rc == 0)
{
if (n == 1)
return (0); /* EOF, no data read */
else {
n++;
else
break; /* EOF, some data was read */
}
}
else
return (-1); /* error */
}
*ptr = 0;
/* printf ("DEBUG, Returning %d bytes (%s)\n", n, origptr); */
return (n);
}
void clear_read_buffer () {
buffer[0] = 0;
}

Loading…
Cancel
Save