My Project
Public Member Functions | List of all members
NPL::CNPLNetServer Class Reference

Current NPL configuration settings. More...

#include <NPLNetServer.h>

Inheritance diagram for NPL::CNPLNetServer:

Public Member Functions

void start (const char *server=NULL, const char *port=NULL)
 start the server's io_service loop. More...
 
void stop ()
 Stop the server.
 
void Cleanup ()
 clean up all resources
 
CNPLDispatcherGetDispatcher ()
 NPLDispatcher serves as an interface between the low level socket interface and NPL message queues.
 
CNPLConnectionManagerGetConnectionManager ()
 get the connection object in this server
 
NPLConnection_ptr CreateConnection (NPLRuntimeAddress_ptr pAddress)
 Create a new connection with a remote server and immediately connect and start the connection. More...
 
void SetTCPKeepAlive (bool bEnable)
 System level Enable/disable SO_KEEPALIVE. More...
 
bool IsTCPKeepAliveEnabled ()
 whether SO_KEEPALIVE is enabled. More...
 
void SetKeepAlive (bool bEnable)
 enable application level keep alive. More...
 
bool IsKeepAliveEnabled ()
 
void EnableIdleTimeout (bool bEnable)
 Enable idle timeout. More...
 
bool IsIdleTimeoutEnabled ()
 
void SetIdleTimeoutPeriod (int nMilliseconds)
 how many milliseconds of inactivity to assume this connection should be timed out. More...
 
int GetIdleTimeoutPeriod ()
 
void EnableAnsiMode (bool bEnable)
 whether the first line of the NPL protocol is in ansi code page. More...
 
bool IsAnsiMode ()
 
int GetMaxPendingConnections () const
 queue size of the acceptor's queue. More...
 
void SetMaxPendingConnections (int val)
 
std::string GetExternalIP ()
 get extern IP address of this computer. More...
 
virtual const std::string & GetHostPort ()
 get the host port of this NPL runtime
 
virtual const std::string & GetHostIP ()
 get the host IP of this NPL runtime
 
virtual bool IsServerStarted ()
 whether the NPL runtime's http server is started. More...
 

Detailed Description

Current NPL configuration settings.

it just load from NPL XML config file.

Member Function Documentation

§ CreateConnection()

NPL::NPLConnection_ptr NPL::CNPLNetServer::CreateConnection ( NPLRuntimeAddress_ptr  pAddress)

Create a new connection with a remote server and immediately connect and start the connection.

[Thread Safe]

Parameters
pAddressthe target NPL runtime address to connect to.
Returns
The function returns immediately, so the returned connection may not have been connected or authenticated yet.

§ EnableAnsiMode()

void NPL::CNPLNetServer::EnableAnsiMode ( bool  bEnable)

whether the first line of the NPL protocol is in ansi code page.

because NPL protocol is compatible with HTTP protocol in ansi mode, some interception web cache servers may cache request even the port number is not 80, so client side applications are encouraged to disable ansi mode.

§ EnableIdleTimeout()

void NPL::CNPLNetServer::EnableIdleTimeout ( bool  bEnable)

Enable idle timeout.

This is the application level timeout setting. We will create a global timer which examines all send/receive time of all open connections, if a connection is inactive (idle for GetIdleTimeoutPeriod()) we will

  • if IsKeepAliveEnabled() is false, actively close the connection. This is the method used by HTTP, which is the only solution to detect broken connection without sending additional keep alive message.
  • if IsKeepAliveEnabled() is true, send an empty message to the other end (keep alive messages) to more accurately detect dead connections (see SetKeepAlive).

§ GetExternalIP()

std::string NPL::CNPLNetServer::GetExternalIP ( )

get extern IP address of this computer.

§ GetMaxPendingConnections()

int NPL::CNPLNetServer::GetMaxPendingConnections ( ) const

queue size of the acceptor's queue.

§ IsServerStarted()

bool NPL::CNPLNetServer::IsServerStarted ( )
virtual

whether the NPL runtime's http server is started.

§ IsTCPKeepAliveEnabled()

bool NPL::CNPLNetServer::IsTCPKeepAliveEnabled ( )

whether SO_KEEPALIVE is enabled.

Returns
bEnable: true to enable.

§ SetIdleTimeoutPeriod()

void NPL::CNPLNetServer::SetIdleTimeoutPeriod ( int  nMilliseconds)

how many milliseconds of inactivity to assume this connection should be timed out.

if 0 it is never timed out.

§ SetKeepAlive()

void NPL::CNPLNetServer::SetKeepAlive ( bool  bEnable)

enable application level keep alive.

we will use a global idle timer to detect if a connection has been inactive for GetIdleTimeoutPeriod(), if so, we may send the keep alive message.

Parameters
bEnableenable keep alive will automatically enable EnableIdleTimeout()

§ SetTCPKeepAlive()

void NPL::CNPLNetServer::SetTCPKeepAlive ( bool  bEnable)

System level Enable/disable SO_KEEPALIVE.

one needs set following values in linux procfs or windows registry in order to work as expected.

  • tcp_keepalive_intvl (integer; default: 75) The number of seconds between TCP keep-alive probes.
  • tcp_keepalive_probes (integer; default: 9) The maximum number of TCP keep-alive probes to send before giving up and killing the connection if no response is obtained from the other end.
  • tcp_keepalive_time (integer; default: 7200) The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are only sent when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours). An idle connection is terminated after approximately an additional 11 minutes (9 probes an interval of 75 seconds apart) when keep-alive is enabled. Note that underlying connection tracking mechanisms and application timeouts may be much shorter. Use the default system level TCP keep alive setting for this socket. Please see TCP keep alive for more information. It can be used to solve the "half-open connection". it is arguable whether to use protocol level keep alive or implement it in the application level.
    Parameters
    bEnabletrue to enable.

§ start()

void NPL::CNPLNetServer::start ( const char *  server = NULL,
const char *  port = NULL 
)

start the server's io_service loop.

This function returns immediately. it will spawn the accept and dispatcher thread.

Parameters
serverdefault to "127.0.0.1"
portdefault to "60001"

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