summaryrefslogtreecommitdiffstats
path: root/tcp.c
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-12-12 00:29:36 +0100
committersijanec <sijanecantonluka@gmail.com>2020-12-12 00:29:36 +0100
commit28a090346c752a453d00cf0ada7123d20d5d703e (patch)
treea3e09dcd1c6bd602b4d3a9fda6179c5b4e3e8d78 /tcp.c
parentinitial "release" (diff)
downloadrtv4d-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 'tcp.c')
-rw-r--r--tcp.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/tcp.c b/tcp.c
index d30e7b5..93558f3 100644
--- a/tcp.c
+++ b/tcp.c
@@ -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);