1 /*
2  * Copyright (C) 2016 Jakub Kruszona-Zawadzki, Core Technology Sp. z o.o.
3  *
4  * This file is part of MooseFS.
5  *
6  * MooseFS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, version 2 (only).
9  *
10  * MooseFS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with MooseFS; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA
18  * or visit http://www.gnu.org/licenses/gpl-2.0.html
19  */
20 
21 #ifndef _SOCKETS_H_
22 #define _SOCKETS_H_
23 
24 #include <inttypes.h>
25 #include <errno.h>
26 
27 #ifdef EWOULDBLOCK
28 #  define ERRNO_ERROR (errno!=EAGAIN && errno!=EWOULDBLOCK)
29 #else
30 #  define ERRNO_ERROR (errno!=EAGAIN)
31 #endif
32 
33 /* ----------------- TCP ----------------- */
34 
35 int tcpsocket(void);
36 int tcpresolve(const char *hostname,const char *service,uint32_t *ip,uint16_t *port,int passiveflag);
37 int tcpnonblock(int sock);
38 int tcpgetstatus(int sock);
39 int tcpsetacceptfilter(int sock);
40 int tcpreuseaddr(int sock);
41 int tcpnodelay(int sock);
42 int tcpaccfhttp(int sock);
43 int tcpaccfdata(int sock);
44 int tcpnumbind(int sock,uint32_t ip,uint16_t port);
45 int tcpstrbind(int sock,const char *hostname,const char *service);
46 int tcpnumconnect(int sock,uint32_t ip,uint16_t port);
47 int tcpnumtoconnect(int sock,uint32_t ip,uint16_t port,uint32_t msecto);
48 int tcpstrconnect(int sock,const char *hostname,const char *service);
49 int tcpstrtoconnect(int sock,const char *hostname,const char *service,uint32_t msecto);
50 int tcpnumlisten(int sock,uint32_t ip,uint16_t port,uint16_t queue);
51 int tcpstrlisten(int sock,const char *hostname,const char *service,uint16_t queue);
52 int32_t tcptoread(int sock,void *buff,uint32_t leng,uint32_t msecto);
53 int32_t tcptowrite(int sock,const void *buff,uint32_t leng,uint32_t msecto);
54 int32_t tcptoforward(int srcsock,int dstsock,void *buff,uint32_t leng,uint32_t rcvd,uint32_t sent,uint32_t msecto);
55 int tcptoaccept(int sock,uint32_t msecto);
56 int tcpaccept(int lsock);
57 int tcpgetpeer(int sock,uint32_t *ip,uint16_t *port);
58 int tcpgetmyaddr(int sock,uint32_t *ip,uint16_t *port);
59 int tcpclose(int sock);
60 
61 /* ----------------- UDP ----------------- */
62 
63 int udpsocket(void);
64 int udpresolve(const char *hostname,const char *service,uint32_t *ip,uint16_t *port,int passiveflag);
65 int udpnonblock(int sock);
66 int udpgetstatus(int sock);
67 int udpnumlisten(int sock,uint32_t ip,uint16_t port);
68 int udpstrlisten(int sock,const char *hostname,const char *service);
69 int udpwrite(int sock,uint32_t ip,uint16_t port,const void *buff,uint16_t leng);
70 int udpread(int sock,uint32_t *ip,uint16_t *port,void *buff,uint16_t leng);
71 int udpclose(int sock);
72 
73 /* ----------------- UNIX ---------------- */
74 
75 int unixsocket(void);
76 int unixnonblock(int sock);
77 int unixgetstatus(int sock);
78 int unixconnect(int sock,const char *path);
79 int unixtoconnect(int sock,const char *path,uint32_t msecto);
80 int unixlisten(int sock,const char *path,int queue);
81 int32_t unixtoread(int sock,void *buff,uint32_t leng,uint32_t msecto);
82 int32_t unixtowrite(int sock,const void *buff,uint32_t leng,uint32_t msecto);
83 int32_t unixtoforward(int srcsock,int dstsock,void *buff,uint32_t leng,uint32_t rcvd,uint32_t sent,uint32_t msecto);
84 int unixtoaccept(int sock,uint32_t msecto);
85 int unixaccept(int lsock);
86 
87 #endif
88