1 // socket functions for butt 2 // 3 // Copyright 2007-2018 by Daniel Noethen. 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2, or (at your option) 8 // any later version. 9 // 10 // This program 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 16 #ifndef SOCKFUNCS_H 17 #define SOCKFUNCS_H 18 19 enum { 20 READ = 0, 21 WRITE = 1, 22 RW = 2 23 }; 24 25 enum { 26 SOCK_ERR_CREATE = -1, 27 SOCK_ERR_RESOLVE = -2, 28 SOCK_TIMEOUT = -3, 29 SOCK_INVALID = -4, 30 SOCK_NO_MODE = -5, 31 SOCK_ERR_SET_SBUF = -6, 32 SOCK_ERR_SET_RBUF = -7, 33 SOCK_ERR_BIND = -8, 34 SOCK_ERR_LISTEN = -9 35 }; 36 37 enum { 38 CONN_TIMEOUT = 1000, 39 SEND_TIMEOUT = 3000, 40 RECV_TIMEOUT = 1000 41 }; 42 43 44 int sock_connect(const char *addr, short port, int timout_ms); 45 int sock_listen(void); 46 int sock_setbufsize(int s, int send_size, int recv_size); 47 int sock_isdisconnected(int s); 48 int sock_send(int s, const char *buf, int len, int timout_ms); 49 int sock_recv(int s, char *buf, int len, int timout_ms); 50 int sock_select(int s, int timout_ms, int mode); 51 int sock_nonblock(int s); 52 int sock_block(int s); 53 int sock_isvalid(int s); 54 void sock_close(int s); 55 void sock_fdinit(int s); 56 void sock_fdclr(int s); 57 void sock_fdzero(void); 58 59 60 #endif 61 62