diff options
author | sijanec <sijanecantonluka@gmail.com> | 2020-12-12 00:29:36 +0100 |
---|---|---|
committer | sijanec <sijanecantonluka@gmail.com> | 2020-12-12 00:29:36 +0100 |
commit | 28a090346c752a453d00cf0ada7123d20d5d703e (patch) | |
tree | a3e09dcd1c6bd602b4d3a9fda6179c5b4e3e8d78 /tcp.c | |
parent | initial "release" (diff) | |
download | rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.gz rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.bz2 rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.lz rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.xz rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.tar.zst rtv4d-dl-28a090346c752a453d00cf0ada7123d20d5d703e.zip |
Diffstat (limited to '')
-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); |