nBasicNetworkSystem Class Reference

basic network system: manages sockets More...

#include <nSocket.h>

Collaboration diagram for nBasicNetworkSystem:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 nBasicNetworkSystem ()
 constructor
 ~nBasicNetworkSystem ()
 destructor
nSocket * Init (void)
 initializes the network
void Shutdown (void)
 shuts donw the network
bool Select (REAL dt)
 waits the specified time for data to arrive on the sockets
nSocketListener & AccessListener (void)
 Accesses listening sockets.
nBasicNetworkSystem & SetListener (nSocketListener const &listener)
 Sets listening sockets.
nSocketListener const & GetListener (void) const
 Gets listening sockets.
nSocket const & GetControlSocket (void) const
 Gets network control socket.

Private Member Functions

 nBasicNetworkSystem (const nBasicNetworkSystem &)
nBasicNetworkSystem & operator= (const nBasicNetworkSystem &)
nSocket & AccessControlSocket (void)
 Accesses network control socket.

Private Attributes

nSocketListener listener_
 listening sockets
nSocket controlSocket_
 network control socket


Detailed Description

basic network system: manages sockets

Definition at line 221 of file nSocket.h.


Constructor & Destructor Documentation

nBasicNetworkSystem::nBasicNetworkSystem ( void   ) 

constructor

Definition at line 2530 of file nSocket.cpp.

02533 {

nBasicNetworkSystem::~nBasicNetworkSystem ( void   ) 

destructor

Definition at line 2544 of file nSocket.cpp.

References Shutdown().

02547 {
02548     // shut down the system

Here is the call graph for this function:

nBasicNetworkSystem::nBasicNetworkSystem ( const nBasicNetworkSystem &   )  [private]


Member Function Documentation

nSocket * nBasicNetworkSystem::Init ( void   ) 

initializes the network

Returns:

Definition at line 2560 of file nSocket.cpp.

References controlSocket_, nSocket::IsOpen(), nSocket::Open(), sn_InitOSNetworking(), and Sys_Error().

02563 {
02564     // test if network was already initialized
02565     if ( controlSocket_.IsOpen() )
02566         return &controlSocket_;
02567 
02568     // initialize networking at OS level
02569     sn_InitOSNetworking();
02570 
02571     if ( 0 != controlSocket_.Open() )
02572         Sys_Error("ANET_Init: Unable to open control socket\n");
02573 
02574     return &controlSocket_;
02575 
02576     //struct hostent *local;
02577     //char      buff[MAXHOSTNAMELEN]="\0";
02578     //struct sockaddr addr;
02579     //char *colon;
02580 
02581     /* not for armagetron
02582        if (COM_CheckParm ("-noudp"))
02583        return -1;
02584     */
02585 
02586     // determine my name & address
02587     //int myAddr = 0;
02588     //int hostnameres = gethostname(buff, MAXHOSTNAMELEN);
02589     //if ( 0 == hostnameres )
02590     //{
02591     //   local = gethostbyname(buff);
02592     //   if ( local )
02593     //   {
02594     //        myAddr = *reinterpret_cast<int *>(local->h_addr_list[0]);
02595     //   }
02596     //   else
02597     //    {
02598     //        Con_Printf ("ANET_Init: Unable to determine IP adress.\n");
02599     //    }
02600     //}
02601     //else
02602     //{
02603     //    Con_Printf ("ANET_Init: Unable to determine hostname.\n");
02604     // }
02605 
02606     // fallback: use loopback
02607     //if ( myAddr == 0 )
02608     //{
02609     //    myAddr = inet_addr("127.0.0.1");
02610     //}
02611 
02612     //tString hostname;
02613 
02614     // if the armagetron hostname isn't set, set it to the clamped machine name
02615     //if (strcmp(hostname, "UNNAMED") == 0 && buff[0] && hostnameres == 0 )
02616     //{
02617     //    buff[15] = 0;
02618     //    hostname=buff;
02619     //}
02620 
02621     //ANET_GetSocketAddr (controlSocket_, &addr);
02622     //my_tcpip_address=ANET_AddrToString (&addr);
02623     //colon = strrchr (my_tcpip_address, ':');
02624     //if (colon)
02625     //    *colon = 0;
02626 
02627     //  Con_Printf("UDP Initialized\n");
02628     //tcpipAvailable = true;

Here is the call graph for this function:

void nBasicNetworkSystem::Shutdown ( void   ) 

shuts donw the network

Definition at line 2697 of file nSocket.cpp.

References nSocket::Close(), controlSocket_, nSocketListener::Listen(), and listener_.

Referenced by main(), and ~nBasicNetworkSystem().

02700 {
02701     // stop listening
02702     listener_.Listen(false);
02703 
02704     // close the control socket

Here is the call graph for this function:

Here is the caller graph for this function:

bool nBasicNetworkSystem::Select ( REAL  dt  ) 

waits the specified time for data to arrive on the sockets

Parameters:
dt the time in seconds to wait at max
Returns:
true if data came in

Definition at line 2641 of file nSocket.cpp.

References controlSocket_, nSocket::GetSocket(), nSocketListener::GetSockets(), listener_, max(), NULL, tRecorder::PlaybackStrict(), tRecorder::Record(), section, and tDelay().

Referenced by main(), sg_HostGame(), update_settings(), and gNetIdler::Wait().

02644 {
02645     int retval = 0;
02646     static char const * section = "NETSELECT";
02647     if ( !tRecorder::PlaybackStrict( section, retval ) )
02648     {
02649         if ( controlSocket_.GetSocket() < 0 )
02650         {
02651             tDelay( int( dt * 1000000 ) );
02652             return false;
02653         }
02654 
02655         fd_set rfds; // set of sockets to wathc
02656         struct timeval tv; // time value to pass to select()
02657 
02658         FD_ZERO( &rfds );
02659 
02660         // watch the control socket
02661         FD_SET( controlSocket_.GetSocket(), &rfds );
02662         // con << "Watching " << controlSocket_.GetSocket();
02663 
02664         int max = controlSocket_.GetSocket();
02665 
02666         // watch listening sockets
02667         for( nSocketListener::SocketArray::const_iterator iter = listener_.GetSockets().begin(); iter != listener_.GetSockets().end(); ++iter )
02668         {
02669             FD_SET( (*iter).GetSocket(), &rfds );
02670             if ( (*iter).GetSocket() > max )
02671                 max = (*iter).GetSocket();
02672             // con << ", " << (*iter).GetSocket();
02673         }
02674 
02675         // set time
02676         tv.tv_sec  = static_cast< long int >( dt );
02677         tv.tv_usec = static_cast< long int >( (dt-tv.tv_sec)*1000000 );
02678 
02679         // delegate to system select
02680         retval = select(max+1, &rfds, NULL, NULL, &tv);
02681     }
02682     tRecorder::Record( section, retval );
02683 
02684     // con << " : " << retval << "\n";
02685 
02686     // return result

Here is the call graph for this function:

Here is the caller graph for this function:

nSocketListener & nBasicNetworkSystem::AccessListener ( void   ) 

Accesses listening sockets.

Returns:
listening sockets as a modifiable reference

Definition at line 923 of file nSocket.cpp.

References listener_.

Referenced by sg_HostGame(), and sn_Listen().

00926 {

Here is the caller graph for this function:

nBasicNetworkSystem& nBasicNetworkSystem::SetListener ( nSocketListener const &  listener  ) 

Sets listening sockets.

nSocketListener const & nBasicNetworkSystem::GetListener ( void   )  const

Gets listening sockets.

Returns:
listening sockets

Definition at line 871 of file nSocket.cpp.

References listener_.

Referenced by nServerInfo::TellMasterAboutMe().

00874 {

Here is the caller graph for this function:

nSocket const & nBasicNetworkSystem::GetControlSocket ( void   )  const

Gets network control socket.

Returns:
network control socket

Definition at line 938 of file nSocket.cpp.

References controlSocket_.

00941 {

nBasicNetworkSystem& nBasicNetworkSystem::operator= ( const nBasicNetworkSystem &   )  [private]

nSocket & nBasicNetworkSystem::AccessControlSocket ( void   )  [private]

Accesses network control socket.

Returns:
network control socket as a modifiable reference

Definition at line 990 of file nSocket.cpp.

References controlSocket_.

00993 {


Member Data Documentation

nSocketListener nBasicNetworkSystem::listener_ [private]

listening sockets

Definition at line 242 of file nSocket.h.

Referenced by AccessListener(), GetListener(), Select(), and Shutdown().

nSocket nBasicNetworkSystem::controlSocket_ [private]

network control socket

Definition at line 243 of file nSocket.h.

Referenced by AccessControlSocket(), GetControlSocket(), Init(), Select(), and Shutdown().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:47:07 2008 for Armagetron Advanced by  doxygen 1.5.4