3 /*-------------------------------------------------------------------------
4 * drawElements Utility Library
5 * ----------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Socket abstraction.
25 * Socket API is thread-safe except to:
29 *//*--------------------------------------------------------------------*/
36 typedef struct deSocket_s deSocket;
37 typedef struct deSocketAddress_s deSocketAddress;
39 typedef enum deSocketFamily_e
41 DE_SOCKETFAMILY_INET4 = 0,
42 DE_SOCKETFAMILY_INET6,
47 typedef enum deSocketType_e
49 DE_SOCKETTYPE_STREAM = 0,
50 DE_SOCKETTYPE_DATAGRAM,
55 typedef enum deSocketProtocol_e
57 DE_SOCKETPROTOCOL_TCP = 0,
58 DE_SOCKETPROTOCOL_UDP,
60 DE_SOCKETPROTOCOL_LAST
63 typedef enum deSocketFlag_e
65 DE_SOCKET_KEEPALIVE = (1<<0),
66 DE_SOCKET_NODELAY = (1<<1),
67 DE_SOCKET_NONBLOCKING = (1<<2),
68 DE_SOCKET_CLOSE_ON_EXEC = (1<<3)
71 /* \todo [2012-07-09 pyry] Separate closed bits for send and receive channels. */
73 typedef enum deSocketState_e
75 DE_SOCKETSTATE_CLOSED = 0,
76 DE_SOCKETSTATE_CONNECTED = 1,
77 DE_SOCKETSTATE_LISTENING = 2,
78 DE_SOCKETSTATE_DISCONNECTED = 3,
83 typedef enum deSocketResult_e
85 DE_SOCKETRESULT_SUCCESS = 0,
86 DE_SOCKETRESULT_WOULD_BLOCK = 1,
87 DE_SOCKETRESULT_CONNECTION_CLOSED = 2,
88 DE_SOCKETRESULT_CONNECTION_TERMINATED = 3,
89 DE_SOCKETRESULT_ERROR = 4,
94 typedef enum deSocketChannel_e
96 DE_SOCKETCHANNEL_RECEIVE = (1<<0),
97 DE_SOCKETCHANNEL_SEND = (1<<1),
99 DE_SOCKETCHANNEL_BOTH = DE_SOCKETCHANNEL_RECEIVE|DE_SOCKETCHANNEL_SEND
102 /* Socket API, similar to Berkeley sockets. */
104 deSocketAddress* deSocketAddress_create (void);
105 void deSocketAddress_destroy (deSocketAddress* address);
107 deBool deSocketAddress_setFamily (deSocketAddress* address, deSocketFamily family);
108 deSocketFamily deSocketAddress_getFamily (const deSocketAddress* address);
109 deBool deSocketAddress_setType (deSocketAddress* address, deSocketType type);
110 deSocketType deSocketAddress_getType (const deSocketAddress* address);
111 deBool deSocketAddress_setProtocol (deSocketAddress* address, deSocketProtocol protocol);
112 deSocketProtocol deSocketAddress_getProtocol (const deSocketAddress* address);
113 deBool deSocketAddress_setPort (deSocketAddress* address, int port);
114 int deSocketAddress_getPort (const deSocketAddress* address);
115 deBool deSocketAddress_setHost (deSocketAddress* address, const char* host);
116 const char* deSocketAddress_getHost (const deSocketAddress* address);
118 deSocket* deSocket_create (void);
119 void deSocket_destroy (deSocket* socket);
121 deSocketState deSocket_getState (const deSocket* socket);
122 deUint32 deSocket_getOpenChannels (const deSocket* socket);
124 deBool deSocket_setFlags (deSocket* socket, deUint32 flags);
126 deBool deSocket_listen (deSocket* socket, const deSocketAddress* address);
127 deSocket* deSocket_accept (deSocket* socket, deSocketAddress* clientAddress);
129 deBool deSocket_connect (deSocket* socket, const deSocketAddress* address);
131 deBool deSocket_shutdown (deSocket* socket, deUint32 channels);
132 deBool deSocket_close (deSocket* socket);
134 deSocketResult deSocket_send (deSocket* socket, const void* buf, size_t bufSize, size_t* numSent);
135 deSocketResult deSocket_receive (deSocket* socket, void* buf, size_t bufSize, size_t* numReceived);
139 const char* deGetSocketFamilyName (deSocketFamily family);
140 const char* deGetSocketResultName (deSocketResult result);
144 #endif /* _DESOCKET_H */