11e7ac7dd1c46b928ad290e33046998cfc1e7236
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / shared / emugl / common / sockets.h
1 // Copyright (C) 2014 The Android Open Source Project
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 #ifndef EMUGL_COMMON_SOCKETS_H
16 #define EMUGL_COMMON_SOCKETS_H
17
18 // A set of helper functions used to deal with sockets in a portable way.
19
20 namespace emugl {
21
22 // Disable Nagle's algorithm for socket descriptor |s|. This assumes
23 // that |s| is a TCP socket descriptor.
24 void socketTcpDisableNagle(int s);
25
26 // Return the port associated with a given IP or IPv6 socket,
27 // or -errno code on failure.
28 int socketGetPort(int s);
29
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);
33
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);
37
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);
41
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);
45
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);
49
50 // Accept a new connection. |serverSocket| must be a bound server socket
51 // descriptor. Returns new socket descriptor on success, or -errno code
52 // on failure.
53 int socketAccept(int serverSocket);
54
55 }  // namespace emugl
56
57 #endif  // EMUGL_COMMON_SOCKETS_H