From 28a090346c752a453d00cf0ada7123d20d5d703e Mon Sep 17 00:00:00 2001 From: sijanec Date: Sat, 12 Dec 2020 00:29:36 +0100 Subject: dodal podporo za radio --- tcp.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index d30e7b5..93558f3 100644 --- a/tcp.c +++ b/tcp.c @@ -14,6 +14,7 @@ #include #include #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); -- cgit v1.2.3