Commit 7a8bdb3e5edb1d7e4648c07f6cf7416ad4f8b57a
1 parent
9ff3d493
Add a way to create TR_Socket socket pairs
Showing
4 changed files
with
61 additions
and
1 deletions
src/socket_pair.c
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright © 2014 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +//#include <errno.h> | |
24 | +//#include <stdlib.h> | |
25 | +//#include <unistd.h> | |
26 | +//#include <stdio.h> | |
27 | +//#include <fcntl.h> | |
28 | + | |
29 | +#include <sys/types.h> | |
30 | +#include <sys/socket.h> | |
31 | +#include <netdb.h> | |
32 | + | |
33 | +#include "tr/socket.h" | |
34 | +#include "trbase.h" | |
35 | + | |
36 | +void | |
37 | +TR_socketPair(TR_Socket sockets[2], int type) | |
38 | +{ | |
39 | + int handles[2]; | |
40 | + | |
41 | + if (0 > socketpair(AF_UNIX, SOCK_DGRAM, 0, handles)) { | |
42 | + TR_loggerLog( | |
43 | + TR_logger, | |
44 | + TR_LOGGER_ERR, | |
45 | + "Unable to create socket pair"); | |
46 | + return; | |
47 | + } | |
48 | + | |
49 | + sockets[0] = TR_new(TR_Socket, NULL, NULL, 0, 0); | |
50 | + sockets[1] = TR_new(TR_Socket, NULL, NULL, 0, 0); | |
51 | + TR_socketType(sockets[0]) = type; | |
52 | + TR_socketType(sockets[1]) = type; | |
53 | + TR_socketHandle(sockets[0]) = handles[0]; | |
54 | + TR_socketHandle(sockets[1]) = handles[1]; | |
55 | +} | |
56 | + | |
57 | +// vim: set ts=4 sw=4: | ... | ... |
... | ... | @@ -55,7 +55,7 @@ udpSocketRecv(void * _this, size_t size) |
55 | 55 | ssize_t received; |
56 | 56 | TR_RemoteData rdata; |
57 | 57 | TR_Socket remote = TR_new(TR_UdpSocket, this->log, NULL, 0, 0); |
58 | - | |
58 | + | |
59 | 59 | size = size>TR_UDP_MAX_READ_BLOCK ? TR_UDP_MAX_READ_BLOCK : size; |
60 | 60 | |
61 | 61 | unsigned char buffer[size]; | ... | ... |
Please
register
or
login
to post a comment