ManaPlus
sdltcpnet.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef NET_SDLTCPNET_H
23 #define NET_SDLTCPNET_H
24 
25 #include "localconsts.h"
26 
27 PRAGMACLANG5(GCC diagnostic push)
28 PRAGMACLANG5(GCC diagnostic ignored "-Wzero-as-null-pointer-constant")
29 PRAGMA48(GCC diagnostic push)
30 PRAGMA48(GCC diagnostic ignored "-Wshadow")
31 #include <SDL_net.h>
32 PRAGMA48(GCC diagnostic pop)
33 PRAGMACLANG5(GCC diagnostic pop)
34 
35 namespace TcpNet
36 {
37  typedef ::SDLNet_SocketSet SocketSet;
38  typedef ::TCPsocket Socket;
39 
40  void init();
41 
42  void quit();
43 
44  void closeSocket(const TcpNet::Socket socket);
45 
46  int send(const TcpNet::Socket sock, const void *const data, const int len);
47 
48  const char *getError();
49 
50  int resolveHost(IPaddress *const address, const char *const host,
51  const Uint16 port);
52 
53  TcpNet::Socket open(IPaddress *const ip);
54 
55  SocketSet allocSocketSet(const int maxsockets);
56 
57  int addSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock);
58 
59  int socketReady(const TcpNet::Socket sock);
60 
61  int checkSockets(const TcpNet::SocketSet set, const Uint32 timeout);
62 
63  int recv(const TcpNet::Socket sock, void *const data, const int maxlen);
64 
65  int delSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock);
66 
67  void freeSocketSet(const TcpNet::SocketSet set);
68 
70 } // namespace TcpNet
71 
72 #endif // NET_SDLTCPNET_H
#define PRAGMA48(str)
Definition: localconsts.h:199
#define PRAGMACLANG5(str)
Definition: localconsts.h:230
uint32_t data
int delSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock)
Definition: sdltcpnet.cpp:185
::SDLNet_SocketSet SocketSet
Definition: sdltcpnet.h:37
int send(const TcpNet::Socket sock, const void *const data, const int len)
Definition: sdltcpnet.cpp:93
int resolveHost(IPaddress *const address, const char *const host, const Uint16 port)
Definition: sdltcpnet.cpp:104
void quit()
Definition: sdltcpnet.cpp:83
void freeSocketSet(const TcpNet::SocketSet set)
Definition: sdltcpnet.cpp:193
int socketReady(const TcpNet::Socket sock)
Definition: sdltcpnet.cpp:164
TcpNet::Socket open(IPaddress *const ip)
Definition: sdltcpnet.cpp:110
void init()
Definition: sdltcpnet.cpp:78
::TCPsocket Socket
Definition: sdltcpnet.h:38
int addSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock)
Definition: sdltcpnet.cpp:156
SocketSet allocSocketSet(const int maxsockets)
Definition: sdltcpnet.cpp:151
const char * getError()
Definition: sdltcpnet.cpp:99
int checkSockets(const TcpNet::SocketSet set, const Uint32 timeout)
Definition: sdltcpnet.cpp:175
void closeSocket(const TcpNet::Socket socket)
Definition: sdltcpnet.cpp:88
int recv(const TcpNet::Socket sock, void *const data, const int maxlen)
Definition: sdltcpnet.cpp:180
TcpNet::Socket accept(const TcpNet::Socket sock)
Definition: sdltcpnet.cpp:198