tImplement function pwphv() to send HAVE messages - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 6b4860db6568bda6501332cb6134d1aeb0d9289c
(DIR) parent 8bd983aaaf8eba4628785591c859d718300103a1
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Sun, 1 Jul 2018 13:02:26 +0200
Implement function pwphv() to send HAVE messages
Diffstat:
M libeech.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/libeech.c b/libeech.c
t@@ -66,6 +66,7 @@ static ssize_t pwphsrecv(struct peer *);
static int pwphsck(struct torrent *, char *, long);
static ssize_t pwpst(struct peer *, int);
+static ssize_t pwphv(struct peer *, int);
static ssize_t pwpbf(struct torrent *, struct peer *);
static ssize_t pwprq(struct torrent *, struct peer *);
t@@ -437,6 +438,31 @@ pwpst(struct peer *p, int t)
}
static ssize_t
+pwphv(struct peer *p, int n)
+{
+ char m[MSGSIZ];
+ ssize_t off = 0;
+
+ memset(m, 0, 9);
+ /* Message length */
+ m[off++] = (9 >> 24) & 0xff;
+ m[off++] = (9 >> 16) & 0xff;
+ m[off++] = (9 >> 8) & 0xff;
+ m[off++] = (9 >> 0) & 0xff;
+
+ /* Message type */
+ m[off++] = HAVE;
+
+ /* Piece number */
+ m[off++] = (n >> 24) & 0xff;
+ m[off++] = (n >> 16) & 0xff;
+ m[off++] = (n >> 8) & 0xff;
+ m[off++] = (n >> 0) & 0xff;
+
+ return send(p->fd, m, 9, MSG_NOSIGNAL);
+}
+
+static ssize_t
pwpbf(struct torrent *t, struct peer *p)
{
char m[MSGSIZ];