]> git.lizzy.rs Git - dragonnet.git/blob - send.c
Fix #include order
[dragonnet.git] / send.c
1 #include <dragonnet/send.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 void dragonnet_send_raw(DragonnetPeer *p, bool submit, const void *buf, size_t n)
8 {
9         pthread_rwlock_rdlock(&p->mu);
10         int sock = p->sock;
11         pthread_rwlock_unlock(&p->mu);
12
13         ssize_t len = send(sock, buf, n, MSG_NOSIGNAL | (submit ? 0 : MSG_MORE));
14         if (len < 0) {
15                 if (errno == EPIPE) {
16                         dragonnet_peer_close(p);
17                         return;
18                 }
19
20                 perror("send");
21                 dragonnet_peer_delete(p);
22         }
23 }
24
25 void dragonnet_write_raw(u8 **buf, size_t *n, const void *data, size_t len)
26 {
27         *buf = realloc(*buf, len + *n);
28         memcpy(&((*buf)[*n]), data, len);
29         *n += len;
30 }