]> git.lizzy.rs Git - dragonnet.git/blob - dragonnet/send.c
Add CMake config
[dragonnet.git] / dragonnet / send.c
1 #include <errno.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "send.h"
6 #include "sock.h"
7
8 bool dragonnet_send_raw(DragonnetPeer *p, bool submit, const void *buf, size_t n)
9 {
10         ssize_t len = send(p->sock, buf, n, MSG_NOSIGNAL | (submit ? 0 : MSG_MORE));
11
12         if (len < 0) {
13                 if (errno == ECONNRESET || errno == EPIPE || errno == ETIMEDOUT) {
14                         shutdown(p->sock, SHUT_RDWR);
15                         pthread_mutex_unlock(&p->mtx);
16                         return false;
17                 }
18
19                 perror("send");
20                 abort();
21         }
22
23         if (submit)
24                 pthread_mutex_unlock(&p->mtx);
25
26         return true;
27 }