Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetUIUDP Class Reference

#include <netui.h>

Static Public Member Functions

static SOCKETALT createSocket (const char *host, unsigned short srv_port, unsigned short clt_port, SocketSet &set)
 
static SOCKETALT createServerSocket (unsigned short port, SocketSet &set)
 
static void disconnectSaveUDP (SOCKETALT udp)
 

Detailed Description

Definition at line 55 of file netui.h.

Member Function Documentation

SOCKETALT NetUIUDP::createServerSocket ( unsigned short  port,
SocketSet set 
)
static

Definition at line 240 of file netui.cpp.

References COUT, NetUIBase::createServerSocket(), NetUIBase::lookupHost(), SERVER_PORT, SOCKETALT::set_nonblock(), SOCKETALT::setLocalAddress(), and static_initNetwork().

Referenced by NetServer::start().

241 {
242  COUT<<"enter "<<__PRETTY_FUNCTION__<<std::endl;
244  //If port is not given, use the defaults ones --> do not work with specified ones yet... well, didn't try
245  if (port == 0) port = SERVER_PORT;
246  AddressIP local_ip = NetUIBase::lookupHost( "0.0.0.0", port );
247  int local_fd = NetUIBase::createServerSocket( local_ip, false );
248  if (local_fd == -1) {
249  SOCKETALT ret;
250  return ret;
251  }
252  SOCKETALT ret( local_fd, SOCKETALT::UDP, local_ip, set );
253  ret.setLocalAddress( local_ip );
254  if (ret.set_nonblock() == false)
255  COUT<<"Setting server socket mode to nonblocking failed";
256  //ret.disconnect( "Setting server socket mode to nonblocking failed", true );
257  //SOCKETALT ret;
258  //return ret;
259 
260  COUT<<"Bind on localhost, "<<ret<<std::endl;
261  return ret;
262 }
SOCKETALT NetUIUDP::createSocket ( const char *  host,
unsigned short  srv_port,
unsigned short  clt_port,
SocketSet set 
)
static

Definition at line 206 of file netui.cpp.

References COUT, NetUIBase::createClientSocket(), NetUIBase::lookupHost(), SERVER_PORT, SOCKETALT::set_nonblock(), SOCKETALT::setLocalAddress(), SOCKETALT::setRemoteAddress(), SOCKETALT::setSet(), static_initNetwork(), and UDP_pool.

Referenced by NetClient::synchronizeTime().

207 {
208  COUT<<" enter "<<__PRETTY_FUNCTION__<<std::endl;
210  //If port is not given, use the defaults ones --> do not work with specified ones yet... well, didn't try
211  if (srv_port == 0) srv_port = SERVER_PORT;
212  if (clt_port == 0) clt_port = SERVER_PORT;
213  AddressIP remote_ip = NetUIBase::lookupHost( host, srv_port );
214  AddressIP local_ip = NetUIBase::lookupHost( "0.0.0.0", clt_port );
215 
216  UDP_pool_type::iterator iter( UDP_pool.find( local_ip ) );
217  if ( iter != UDP_pool.end() ) {
218  SOCKETALT ret( (*iter).second );
219  //bindFd(ret.get_fd(), local_ip); // Don't care if it fails... could be binding on itself.
220  ret.setSet( &set );
221  ret.setRemoteAddress( remote_ip );
222  return ret;
223  }
224  int local_fd = NetUIBase::createClientSocket( local_ip, false, false );
225  if (local_fd == -1) {
226  SOCKETALT ret;
227  return ret;
228  }
229  SOCKETALT ret( local_fd, SOCKETALT::UDP, remote_ip, set );
230  ret.setLocalAddress( local_ip );
231  if (ret.set_nonblock() == false)
232  COUT<<"Could not set socket to nonblocking state";
233  //ret.disconnect( "Could not set socket to nonblocking state" );
234  //SOCKETALT ret; // ( -1, SOCKETALT::UDP, remote_ip );
235  //return ret;
236  COUT<<"Bind on localhost, "<<ret<<std::endl;
237  return ret;
238 }
void NetUIUDP::disconnectSaveUDP ( SOCKETALT  udp)
static

Definition at line 264 of file netui.cpp.

References SOCKETALT::getLocalAddress(), SOCKETALT::setSet(), UDP_pool, and SOCKETALT::valid().

Referenced by NetClient::init(), NetClient::logout(), and NetClient::synchronizeTime().

265 {
266  if ( udp.valid() )
267  UDP_pool[udp.getLocalAddress()] = udp;
268  udp.setSet( NULL );
269 }

The documentation for this class was generated from the following files: