]> git.lizzy.rs Git - dragonnet.git/blob - send.c
Set thread names using GNU extension
[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 bool dragonnet_send_raw(DragonnetPeer *p, bool submit, const void *buf, size_t n)
8 {
9         ssize_t len = send(p->sock, buf, n, MSG_NOSIGNAL | (submit ? 0 : MSG_MORE));
10
11         if (len < 0) {
12                 if (errno == ECONNRESET || errno == EPIPE || errno == ETIMEDOUT) {
13                         shutdown(p->sock, SHUT_RDWR);
14                         pthread_mutex_unlock(&p->mtx);
15                         return false;
16                 }
17
18                 perror("send");
19                 exit(EXIT_FAILURE);
20         }
21
22         if (submit)
23                 pthread_mutex_unlock(&p->mtx);
24
25         return true;
26 }