1 /*  Copyright 2013 Theo Berkau
2 
3     This file is part of Yabause.
4 
5     Yabause 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 of the License, or
8     (at your option) any later version.
9 
10     Yabause 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 Yabause; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18 */
19 
20 #ifndef SOCK_H
21 #define SOCK_H
22 
23 typedef int YabSock;
24 
25 // YabSockInit: Initializes socket code.
26 // Returns 0 on success. -1 on error.
27 int YabSockInit();
28 
29 // YabSockDeInit: DeInitialize/frees socket code.
30 // Returns 0 on success. -1 on error.
31 int YabSockDeInit();
32 
33 // YabSockConnectSocket: Attempts to connect to specified ip and port.
34 // Returns 0 on success. -1 on error.
35 int YabSockConnectSocket(const char *ip, int port, YabSock *sock);
36 
37 // YabSockListenSocket: Listen for connection attempts on specified port.
38 // Returns 0 on success. -1 on error.
39 int YabSockListenSocket(int port, YabSock *sock);
40 
41 // YabSockCloseSocket: Closes previously opened socket.
42 // Returns 0 on success. -1 on error.
43 int YabSockCloseSocket(YabSock sock);
44 
45 // YabSockSelect: Determines the status of one or more sockets.
46 // Returns 0 on success. -1 on error.
47 int YabSockSelect(YabSock sock, int check_read, int check_write);
48 
49 // YabSockIsReadSet: Is socket's read flag set
50 // Returns 1 on true. 0 on false.
51 int YabSockIsReadSet(YabSock sock);
52 
53 // YabSockIsWriteSet: Is socket's write flag set
54 // Returns 1 on true. 0 on false.
55 int YabSockIsWriteSet(YabSock sock);
56 
57 // YabSockAccept: Accept connection from socket.
58 // Returns opened connected socket.
59 YabSock YabSockAccept(YabSock sock);
60 
61 // YabSockSend: Sends data via specified socket
62 // Returns 0 on success. -1 on error.
63 int YabSockSend(YabSock sock, const void *buf, int len, int flags);
64 
65 // YabSockSend: Receive data via specified socket
66 // Returns 0 on success. -1 on error.
67 int YabSockReceive(YabSock sock, void *buf, int len, int flags);
68 
69 #endif  // SOCK_H
70