tCorrectly define TCP functions pwprecv/pwpsend - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 1871407a84e54060480834c2b7577b62dfd12198
(DIR) parent 43f71d66c05978eb4778835f80b83ac57dec3504
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Tue, 3 Jul 2018 23:28:11 +0200
Correctly define TCP functions pwprecv/pwpsend
Diffstat:
M libeech.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -70,6 +70,9 @@ static ssize_t pwptxhs(struct torrent *, struct peer *);
static ssize_t pwprxhs(struct peer *);
static int pwphsck(struct torrent *, char *, long);
+static ssize_t pwprecv(struct peer *);
+static ssize_t pwpsend(struct peer *, char *, size_t);
+
static ssize_t pwptxst(struct peer *, int);
static ssize_t pwptxhv(struct peer *, int);
static ssize_t pwptxbf(struct torrent *, struct peer *);
t@@ -391,7 +394,7 @@ pwptxhs(struct torrent *t, struct peer *p)
memcpy(m + 28, t->ih, 20);
memcpy(m + 48, t->id, 20);
- return send(p->fd, m, 68, MSG_NOSIGNAL);
+ return pwpsend(p, m, 68);
}
static ssize_t
t@@ -452,6 +455,12 @@ pwprecv(struct peer *p)
return l - p->rxbufsz;
}
+static ssize_t
+pwpsend(struct peer *p, char *m, size_t sz)
+{
+ return send(p->fd, m, sz, MSG_NOSIGNAL);
+}
+
/*
* Standard PWP messages: [LENGTH][TYPE][PAYLOAD]
* Length: 4 bytes bigendian; Size of the type + payload
t@@ -472,7 +481,7 @@ pwptxst(struct peer *p, int t)
/* Message type */
m[4] = t;
- return send(p->fd, m, 5, MSG_NOSIGNAL);
+ return pwpsend(p, m, 5);
}
static ssize_t
t@@ -497,7 +506,7 @@ pwptxhv(struct peer *p, int n)
m[off++] = (n >> 8) & 0xff;
m[off++] = (n >> 0) & 0xff;
- return send(p->fd, m, 9, MSG_NOSIGNAL);
+ return pwpsend(p, m, 9);
}
static ssize_t
t@@ -518,7 +527,7 @@ pwptxbf(struct torrent *t, struct peer *p)
/* Message type */
m[off++] = BITFIELD;
- return send(p->fd, m, l + 5, MSG_NOSIGNAL);
+ return pwpsend(p, m, l + 5);
}
static ssize_t
t@@ -569,7 +578,7 @@ pwptxrq(struct torrent *t, struct peer *p)
m[off++] = (bl >> 8) & 0xff;
m[off++] = (bl >> 0) & 0xff;
- send(p->fd, m, 17, MSG_NOSIGNAL);
+ pwpsend(p, m, 17);
i += bl;
}