]> git.lizzy.rs Git - dragonnet.git/blob - send.c
Use getaddrinfo and getnameinfo for address parsing
[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 #include <sys/socket.h>
7 #include <sys/types.h>
8
9 bool dragonnet_send_raw(DragonnetPeer *p, bool submit, const void *buf, size_t n)
10 {
11         ssize_t len = send(p->sock, buf, n, MSG_NOSIGNAL | (submit ? 0 : MSG_MORE));
12
13         if (len < 0) {
14                 if (errno == ECONNRESET || errno == EPIPE || errno == ETIMEDOUT) {
15                         shutdown(p->sock, SHUT_RDWR);
16                         pthread_mutex_unlock(&p->mtx);
17                         return false;
18                 }
19
20                 perror("send");
21                 exit(EXIT_FAILURE);
22         }
23
24         if (submit)
25                 pthread_mutex_unlock(&p->mtx);
26
27         return true;
28 }