ManaPlus
Typedefs | Functions
TcpNet Namespace Reference

Typedefs

typedef ::SDLNet_SocketSet SocketSet
 
typedef ::TCPsocket Socket
 

Functions

void init ()
 
void quit ()
 
void closeSocket (const TcpNet::Socket socket)
 
int send (const TcpNet::Socket sock, const void *const data, const int len)
 
const char * getError ()
 
int resolveHost (IPaddress *const address, const char *const host, const Uint16 port)
 
TcpNet::Socket open (IPaddress *const ip)
 
SocketSet allocSocketSet (const int maxsockets)
 
int addSocket (const TcpNet::SocketSet set, const TcpNet::Socket sock)
 
int socketReady (const TcpNet::Socket sock)
 
int checkSockets (const TcpNet::SocketSet set, const Uint32 timeout)
 
int recv (const TcpNet::Socket sock, void *const data, const int maxlen)
 
int delSocket (const TcpNet::SocketSet set, const TcpNet::Socket sock)
 
void freeSocketSet (const TcpNet::SocketSet set)
 
TcpNet::Socket accept (const TcpNet::Socket sock)
 

Typedef Documentation

◆ Socket

typedef ::TCPsocket TcpNet::Socket

Definition at line 38 of file sdltcpnet.h.

◆ SocketSet

typedef ::SDLNet_SocketSet TcpNet::SocketSet

Definition at line 37 of file sdltcpnet.h.

Function Documentation

◆ accept()

TcpNet::Socket TcpNet::accept ( const TcpNet::Socket  sock)

◆ addSocket()

int TcpNet::addSocket ( const TcpNet::SocketSet  set,
const TcpNet::Socket  sock 
)

Definition at line 156 of file sdltcpnet.cpp.

157 {
158  PRAGMACLANG6GCC(GCC diagnostic push)
159  PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
160  return SDLNet_TCP_AddSocket(set, sock);
161  PRAGMACLANG6GCC(GCC diagnostic pop)
162 }
#define PRAGMACLANG6GCC(str)
Definition: localconsts.h:240

References PRAGMACLANG6GCC.

Referenced by IPC::acceptLoop(), and Ea::Network::receive().

◆ allocSocketSet()

TcpNet::SocketSet TcpNet::allocSocketSet ( const int  maxsockets)

Definition at line 151 of file sdltcpnet.cpp.

152 {
153  return SDLNet_AllocSocketSet(maxsockets);
154 }

Referenced by IPC::acceptLoop(), and Ea::Network::receive().

◆ checkSockets()

int TcpNet::checkSockets ( const TcpNet::SocketSet  set,
const Uint32  timeout 
)

Definition at line 175 of file sdltcpnet.cpp.

176 {
177  return SDLNet_CheckSockets(set, timeout);
178 }

Referenced by IPC::acceptLoop(), and Ea::Network::receive().

◆ closeSocket()

void TcpNet::closeSocket ( const TcpNet::Socket  socket)

Definition at line 88 of file sdltcpnet.cpp.

89 {
90  SDLNet_TCP_Close(socket);
91 }

Referenced by IPC::acceptLoop(), Ea::Network::disconnect(), and IPC::~IPC().

◆ delSocket()

int TcpNet::delSocket ( const TcpNet::SocketSet  set,
const TcpNet::Socket  sock 
)

Definition at line 185 of file sdltcpnet.cpp.

186 {
187  PRAGMACLANG6GCC(GCC diagnostic push)
188  PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
189  return SDLNet_TCP_DelSocket(set, sock);
190  PRAGMACLANG6GCC(GCC diagnostic pop)
191 }

References PRAGMACLANG6GCC.

Referenced by Ea::Network::receive().

◆ freeSocketSet()

void TcpNet::freeSocketSet ( const TcpNet::SocketSet  set)

Definition at line 193 of file sdltcpnet.cpp.

194 {
195  SDLNet_FreeSocketSet(set);
196 }

Referenced by IPC::acceptLoop(), and Ea::Network::receive().

◆ getError()

const char * TcpNet::getError ( )

◆ init()

void TcpNet::init ( )

Definition at line 78 of file sdltcpnet.cpp.

79 {
80  SDLNet_Init();
81 }

Referenced by Ea::Network::Network().

◆ open()

TcpNet::Socket TcpNet::open ( IPaddress *const  ip)

Definition at line 110 of file sdltcpnet.cpp.

111 {
112  const TcpNet::Socket sock = SDLNet_TCP_Open(ip);
113 #if !defined(__native_client__) \
114  && (defined(TCP_THIN_LINEAR_TIMEOUTS) \
115  || defined(TCP_THIN_DUPACK))
116  if ((sock != nullptr) && (ip != nullptr))
117  {
118  const TCPsocketHack *const hack
119  = reinterpret_cast<const TCPsocketHack *>(sock);
120  // here we using some magic to compare TCPsocket and own padding
121  // because actual struct TCPsocket not in headers
122  if (hack != nullptr)
123  {
124  const IPaddress &addr = hack->remoteAddress;
125  if (addr.host == ip->host && addr.port == ip->port)
126  {
127  const int val = 1;
128 #ifdef TCP_THIN_LINEAR_TIMEOUTS
129  if (setsockopt(hack->channel, IPPROTO_TCP,
130  TCP_THIN_LINEAR_TIMEOUTS, &val, sizeof(val)) != 0)
131  {
132  logger->log_r("error on set TCP_THIN_LINEAR_TIMEOUTS");
133  }
134 #endif // TCP_THIN_LINEAR_TIMEOUTS
135 #ifdef TCP_THIN_DUPACK
136  if (setsockopt(hack->channel, IPPROTO_TCP,
137  TCP_THIN_DUPACK, &val, sizeof(val)) != 0)
138  {
139  logger->log_r("error on set TCP_THIN_DUPACK");
140  }
141 #endif // TCP_THIN_DUPACK
142  }
143  }
144  }
145 #endif // !defined(__native_client__)
146  // && (defined(TCP_THIN_LINEAR_TIMEOUTS)
147  // || defined(TCP_THIN_DUPACK))
148  return sock;
149 }
void log_r(const char *const log_text,...)
Definition: logger.cpp:365
Logger * logger
Definition: logger.cpp:89
bool hack(InputEvent &event)
Definition: commands.cpp:76
::TCPsocket Socket
Definition: sdltcpnet.h:38

References Actions::hack(), Logger::log_r(), and logger.

Referenced by IPC::init(), and Ea::Network::realConnect().

◆ quit()

void TcpNet::quit ( )

Definition at line 83 of file sdltcpnet.cpp.

84 {
85  SDLNet_Quit();
86 }

Referenced by Ea::Network::~Network().

◆ recv()

int TcpNet::recv ( const TcpNet::Socket  sock,
void *const  data,
const int  maxlen 
)

Definition at line 180 of file sdltcpnet.cpp.

181 {
182  return SDLNet_TCP_Recv(sock, data, maxlen);
183 }
uint32_t data

References data.

Referenced by IPC::acceptLoop(), and Ea::Network::receive().

◆ resolveHost()

int TcpNet::resolveHost ( IPaddress *const  address,
const char *const  host,
const Uint16  port 
)

Definition at line 104 of file sdltcpnet.cpp.

106 {
107  return SDLNet_ResolveHost(address, host, port);
108 }

Referenced by IPC::init(), and Ea::Network::realConnect().

◆ send()

int TcpNet::send ( const TcpNet::Socket  sock,
const void *const  data,
const int  len 
)

Definition at line 93 of file sdltcpnet.cpp.

95 {
96  return SDLNet_TCP_Send(sock, data, len);
97 }

References data.

Referenced by IPC::acceptLoop(), and Ea::Network::flush().

◆ socketReady()

int TcpNet::socketReady ( const TcpNet::Socket  sock)

Definition at line 164 of file sdltcpnet.cpp.

165 {
166  PRAGMACLANG5(GCC diagnostic push)
167  PRAGMACLANG5(GCC diagnostic ignored "-Wzero-as-null-pointer-constant")
168  PRAGMACLANG6GCC(GCC diagnostic push)
169  PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
170  return SDLNet_SocketReady(sock);
171  PRAGMACLANG6GCC(GCC diagnostic pop)
172  PRAGMACLANG5(GCC diagnostic pop)
173 }
#define PRAGMACLANG5(str)
Definition: localconsts.h:230

References PRAGMACLANG5, and PRAGMACLANG6GCC.

Referenced by IPC::acceptLoop().