1 /* 2 * Copyright (C) 2021 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 /* -------------- UNIVERSAL -------------- */ 34 35 int univnonblock(int fd); 36 int32_t univtoread(int fd,void *buff,uint32_t leng,uint32_t msecto); 37 int32_t univtowrite(int fd,const void *buff,uint32_t leng,uint32_t msecto); 38 int32_t univtoforward(int srcfd,int dstfd,void *buff,uint32_t leng,uint32_t rcvd,uint32_t sent,uint32_t msecto); 39 40 /* ----------------- TCP ----------------- */ 41 42 int tcpsocket(void); 43 int tcpresolve(const char *hostname,const char *service,uint32_t *ip,uint16_t *port,int passiveflag); 44 int tcpnonblock(int sock); 45 int tcpgetstatus(int sock); 46 int tcpsetacceptfilter(int sock); 47 int tcpreuseaddr(int sock); 48 int tcpnodelay(int sock); 49 int tcpaccfhttp(int sock); 50 int tcpaccfdata(int sock); 51 int tcpnumbind(int sock,uint32_t ip,uint16_t port); 52 int tcpstrbind(int sock,const char *hostname,const char *service); 53 int tcpnumconnect(int sock,uint32_t ip,uint16_t port); 54 int tcpnumtoconnect(int sock,uint32_t ip,uint16_t port,uint32_t msecto); 55 int tcpstrconnect(int sock,const char *hostname,const char *service); 56 int tcpstrtoconnect(int sock,const char *hostname,const char *service,uint32_t msecto); 57 int tcpnumlisten(int sock,uint32_t ip,uint16_t port,uint16_t queue); 58 int tcpstrlisten(int sock,const char *hostname,const char *service,uint16_t queue); 59 int32_t tcptoread(int sock,void *buff,uint32_t leng,uint32_t msecto); 60 int32_t tcptowrite(int sock,const void *buff,uint32_t leng,uint32_t msecto); 61 int32_t tcptoforward(int srcsock,int dstsock,void *buff,uint32_t leng,uint32_t rcvd,uint32_t sent,uint32_t msecto); 62 int tcptoaccept(int sock,uint32_t msecto); 63 int tcpaccept(int lsock); 64 int tcpgetpeer(int sock,uint32_t *ip,uint16_t *port); 65 int tcpgetmyaddr(int sock,uint32_t *ip,uint16_t *port); 66 int tcpclose(int sock); 67 68 /* ----------------- UDP ----------------- */ 69 70 int udpsocket(void); 71 int udpresolve(const char *hostname,const char *service,uint32_t *ip,uint16_t *port,int passiveflag); 72 int udpnonblock(int sock); 73 int udpgetstatus(int sock); 74 int udpnumlisten(int sock,uint32_t ip,uint16_t port); 75 int udpstrlisten(int sock,const char *hostname,const char *service); 76 int udpwrite(int sock,uint32_t ip,uint16_t port,const void *buff,uint16_t leng); 77 int udpread(int sock,uint32_t *ip,uint16_t *port,void *buff,uint16_t leng); 78 int udpclose(int sock); 79 80 /* ----------------- UNIX ---------------- */ 81 #ifndef WIN32 82 int unixsocket(void); 83 int unixnonblock(int sock); 84 int unixgetstatus(int sock); 85 int unixconnect(int sock,const char *path); 86 int unixtoconnect(int sock,const char *path,uint32_t msecto); 87 int unixlisten(int sock,const char *path,int queue); 88 int32_t unixtoread(int sock,void *buff,uint32_t leng,uint32_t msecto); 89 int32_t unixtowrite(int sock,const void *buff,uint32_t leng,uint32_t msecto); 90 int32_t unixtoforward(int srcsock,int dstsock,void *buff,uint32_t leng,uint32_t rcvd,uint32_t sent,uint32_t msecto); 91 int unixtoaccept(int sock,uint32_t msecto); 92 int unixaccept(int lsock); 93 #define unixclose close 94 #endif 95 96 #endif 97