diff options
Diffstat (limited to 'tcp.c')
-rw-r--r-- | tcp.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -14,6 +14,7 @@ #include <string.h> #include <sys/time.h> #define ERR_INET_ADDR "0.9.9.0" +#define TCPC_READ_BUF 1024 union ip_conv { unsigned char c[4]; struct in_addr in; @@ -86,9 +87,9 @@ int read_until(int conn_fd, FILE * out, unsigned int timeout, const char * ma, unsigned int match = 0; struct timeval start, stop; gettimeofday(&start, NULL); - char c[2] = {'\0', '\0'}; + char c[TCPC_READ_BUF+1]; while (1) { - ret = read(conn_fd, c, 1); + ret = read(conn_fd, c, ma ? 1 : TCPC_READ_BUF); if (ret == -1) { if (errno == EWOULDBLOCK) { } else { @@ -99,18 +100,20 @@ int read_until(int conn_fd, FILE * out, unsigned int timeout, const char * ma, fprintf(stderr, "%s@" __FILE__ ":%d read(): server closed connection\n", __func__, __LINE__); return 0; } else { - fputc(c[0], out); + fwrite(c, ret, 1, out); max_bytes--; if (max_bytes <= 0) { return 0; } - if (ma[match] == c[0]) { - match++; - if (match == strlen(ma)) { - return 0; + if (ma != NULL) { + if (ma[match] == c[0]) { + match++; + if (match == strlen(ma)) { + return 0; + } + } else { + match = 0; } - } else { - match = 0; } } gettimeofday(&stop, NULL); |