]> git.lizzy.rs Git - dragonnet.git/blob - send.c
89408e49ba7cfe2f34439fdbfa9d5df1f1ec470e
[dragonnet.git] / send.c
1 #include <errno.h>
2 #include <stdio.h>
3
4 #include <dragonnet/send.h>
5
6 void send_raw(DragonnetPeer *p, bool submit, const void *buf, size_t n)
7 {
8         pthread_rwlock_rdlock(&p->mu);
9         int sock = p->sock;
10         pthread_rwlock_unlock(&p->mu);
11
12         ssize_t len = send(sock, buf, n, MSG_NOSIGNAL | (submit ? 0 : MSG_MORE));
13         if (len < 0) {
14                 if (errno == EPIPE) {
15                         dragonnet_peer_close(p);
16                         return;
17                 }
18
19                 perror("send");
20                 dragonnet_peer_delete(p);
21         }
22 }