1 // Copyright (C) 2014 The Android Open Source Project
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef EMUGL_COMMON_SOCKETS_H
16 #define EMUGL_COMMON_SOCKETS_H
18 // A set of helper functions used to deal with sockets in a portable way.
22 // Disable Nagle's algorithm for socket descriptor |s|. This assumes
23 // that |s| is a TCP socket descriptor.
24 void socketTcpDisableNagle(int s);
26 // Return the port associated with a given IP or IPv6 socket,
27 // or -errno code on failure.
28 int socketGetPort(int s);
30 // Bind to a local/Unix path, and return its socket descriptor on success,
31 // or -errno code on failure.
32 int socketLocalServer(const char* path, int socketType);
34 // Connect to a Unix local path, and return a new socket descriptor
35 // on success, or -errno code on failure.
36 int socketLocalClient(const char* path, int socketType);
38 // Bind to a localhost TCP socket, and return its socket descriptor on
39 // success, or -errno code on failure.
40 int socketTcpLoopbackServer(int port, int socketType);
42 // Connect to a localhost TCP port, and return a new socket descriptor on
43 // success, or -errno code on failure.
44 int socketTcpLoopbackClient(int port, int socketType);
46 // Connect to a TCP host, and return a new socket descriptor on
47 // success, or -errno code on failure.
48 int socketTcpClient(const char* hostname, int port, int socketType);
50 // Accept a new connection. |serverSocket| must be a bound server socket
51 // descriptor. Returns new socket descriptor on success, or -errno code
53 int socketAccept(int serverSocket);
57 #endif // EMUGL_COMMON_SOCKETS_H