NAbstractSocket Class Reference

NAbstractSocket class provides an abstraction to manipulate sockets. More...

Inheritance diagram for NAbstractSocket:

NIODevice NObject NTcpSocket NTcpSocket

List of all members.

Public Types

enum  SocketType { Unknown = -1, TcpSocket, UdpSocket }
 Defines the socket type. Currently only TcpSockets are supported. More...

Public Member Functions

 NAbstractSocket (void)
 Constructs an abstract socket object.
 NAbstractSocket (const NHostAddress &host)
 Constructs an abstract socket object.
 NAbstractSocket (const NHostAddress &host, nuint16 port)
 Constructs an abstract socket object.
 NAbstractSocket (const NString &host, nuint16 port)
 Constructs an abstract socket object.
virtual ~NAbstractSocket (void)
 Destroys an abstract socket object closing the related connection.
virtual void setHost (const NHostAddress &host)
 Sets the host to connect to/listen.
virtual void setHost (const NString &host)
 Sets the host to connect to/listen.
NHostAddress getHost (void) const
 Gets the host to connect to/listen.
virtual void setPort (nuint16 port)
 Sets the port to connect to/listen.
nuint16 getPort (void) const
 Gets the port to connect to/listen.
void setTimeout (nuint16 timeout)
 Sets the timeout for reading data.
nuint16 getTimeout (void) const
 Gets the timeout for reading data.
void setMaxPendingConnections (nint32 max)
 Sets the max number of pending connections.
nint32 getMaxPendingConnections (void) const
 Gets the max number of pending connections.
virtual void setSocketOptions (nint32 opt)
 Sets socket options.
virtual void open (void)=0
 Open the socket.
void open (Mode mode)
 Open the Socket.
virtual void closeDevice (void)=0
 Closes the socket.
virtual void disconnectFromHost (void)=0
 Disconnects from the remote host.
virtual void execListen (void)=0
 Starts listening.
virtual void connectToHost (void)=0
 Connects to a host.
virtual nint32 read (NDataStream *buffer)=0
 Reads data from the socket.
virtual nint32 read (NDataStream *buffer, nuint32 bytes)=0
 Reads data from the socket.
virtual nint32 readLine (NDataStream *buffer)=0
 Reads a line from the socket.
virtual nint32 write (const NDataStream &data, nuint32 bytes)=0
 Writes data to the socket.
virtual nint32 writeLine (const NDataStream &data, nuint32 bytes)=0
 Writes a line of data to the socket.

Static Public Attributes

static const nint32 DEFAULT_SOCK_OPTS = 0
 Default options.
static const nint32 REUSE_ADDRESS = SO_REUSEADDR
 Allow the reuse of local address.
static const nint32 KEEPALIVE = SO_KEEPALIVE
 Enable sending of keep-alive messages.

Protected Attributes

NHostAddress m_host
nuint16 m_port
nuint16 m_timeout
nint32 m_opt
nint32 m_maxPendingConn


Detailed Description

NAbstractSocket class provides an abstraction to manipulate sockets.

Definition at line 48 of file nabstractsocket.h.


Member Enumeration Documentation

enum SocketType

Defines the socket type. Currently only TcpSockets are supported.

Enumerator:
Unknown  Unknown socket type
TcpSocket  TCP Socket Type
UdpSocket  UDP socket type (not implemented)

Definition at line 54 of file nabstractsocket.h.


Constructor & Destructor Documentation

NAbstractSocket ( const NHostAddress host  ) 

Constructs an abstract socket object.

Parameters:
host Host to connect to/listen

Definition at line 39 of file nabstractsocket.cpp.

References m_host, and NHostAddress::toString().

NAbstractSocket ( const NHostAddress host,
nuint16  port 
)

Constructs an abstract socket object.

Parameters:
host Host to connect to/listen
port Port to connect to/listen

Definition at line 50 of file nabstractsocket.cpp.

References m_host, and NHostAddress::toString().

NAbstractSocket ( const NString host,
nuint16  port 
)

Constructs an abstract socket object.

Parameters:
host Host to connect to/listen
port Port to connect to/listen

Definition at line 60 of file nabstractsocket.cpp.


Member Function Documentation

void setHost ( const NHostAddress host  )  [virtual]

Sets the host to connect to/listen.

Parameters:
host Hostname or IP to connect to/listen

Definition at line 75 of file nabstractsocket.cpp.

References m_host.

void setHost ( const NString host  )  [virtual]

Sets the host to connect to/listen.

Parameters:
host Hostname or IP to connect to/listen

Definition at line 80 of file nabstractsocket.cpp.

References m_host.

NHostAddress getHost ( void   )  const

Gets the host to connect to/listen.

Returns:
The host to connect to/listen

Definition at line 85 of file nabstractsocket.cpp.

References m_host.

void setPort ( nuint16  port  )  [virtual]

Sets the port to connect to/listen.

Parameters:
port Port to connect to/listen

Definition at line 90 of file nabstractsocket.cpp.

References m_port.

Referenced by NTcpSocket::setPort().

nuint16 getPort ( void   )  const

Gets the port to connect to/listen.

Returns:
The port to connect to/listen

Definition at line 95 of file nabstractsocket.cpp.

References m_port.

void setTimeout ( nuint16  timeout  ) 

Sets the timeout for reading data.

Parameters:
timeout Max time, in seconds, that the object will wait for a response

Definition at line 100 of file nabstractsocket.cpp.

References m_timeout.

nuint16 getTimeout ( void   )  const

Gets the timeout for reading data.

Returns:
The max time, in seconds

Definition at line 105 of file nabstractsocket.cpp.

References m_timeout.

void setMaxPendingConnections ( nint32  max  ) 

Sets the max number of pending connections.

Parameters:
max The max number of pending connections
Note:
By default uses 5

Definition at line 114 of file nabstractsocket.cpp.

References m_maxPendingConn.

nint32 getMaxPendingConnections ( void   )  const

Gets the max number of pending connections.

Returns:
The max number of pending connections

Definition at line 119 of file nabstractsocket.cpp.

References m_maxPendingConn.

void open ( Mode  mode  )  [inline, virtual]

Open the Socket.

Parameters:
mode Openning mode (ignored)
Note:
For a socket 'mode' is ignored, so it's the same as calling open()

Implements NIODevice.

Definition at line 173 of file nabstractsocket.h.

References NIODevice::open().

virtual nint32 read ( NDataStream buffer  )  [pure virtual]

Reads data from the socket.

Parameters:
buffer Buffer to save the received data
Returns:
The number of bytes read

Implements NIODevice.

Implemented in NTcpSocket, and NTcpSocket.

virtual nint32 read ( NDataStream buffer,
nuint32  bytes 
) [pure virtual]

Reads data from the socket.

Parameters:
buffer Buffer to save the received data
bytes Max number of bytes to read
Returns:
The number of bytes read

Implements NIODevice.

Implemented in NTcpSocket, and NTcpSocket.

virtual nint32 readLine ( NDataStream buffer  )  [pure virtual]

Reads a line from the socket.

Parameters:
buffer Buffer to save the received data
Returns:
The number of bytes read

Implements NIODevice.

Implemented in NTcpSocket, and NTcpSocket.

virtual nint32 write ( const NDataStream data,
nuint32  bytes 
) [pure virtual]

Writes data to the socket.

Parameters:
data Data to be written to the socket
bytes Max number of bytes to write to the socket
Returns:
The amount of bytes written

Implements NIODevice.

Implemented in NTcpSocket, and NTcpSocket.

virtual nint32 writeLine ( const NDataStream data,
nuint32  bytes 
) [pure virtual]

Writes a line of data to the socket.

Parameters:
data Data to be written to the socket
bytes Max number of bytes to write to the socket
Returns:
The amount of bytes written
Note:
It's not needed to append a carriage return/line feed at the end of the data. The object will do that for you. If you don't want this behaviour, use write() instead.

Implemented in NTcpSocket, and NTcpSocket.


Member Data Documentation

NHostAddress m_host [protected]

Hostname

Definition at line 239 of file nabstractsocket.h.

Referenced by NTcpSocket::connectToHost(), NTcpSocket::execListen(), getHost(), NAbstractSocket(), NTcpSocket::read(), NTcpSocket::readLine(), setHost(), and NTcpSocket::waitForConnected().

nuint16 m_port [protected]

Port

Definition at line 240 of file nabstractsocket.h.

Referenced by NTcpSocket::connectToHost(), NTcpSocket::execListen(), getPort(), NTcpSocket::setPort(), setPort(), and NTcpSocket::waitForConnected().

nuint16 m_timeout [protected]

Time out, in seconds

Definition at line 242 of file nabstractsocket.h.

Referenced by getTimeout(), NTcpSocket::read(), NTcpSocket::readLine(), setTimeout(), and NTcpSocket::waitForConnected().

nint32 m_opt [protected]

Socket options

Definition at line 243 of file nabstractsocket.h.

Referenced by NTcpSocket::setSocketOptions(), and setSocketOptions().

nint32 m_maxPendingConn [protected]

Maximum number of pending connections

Definition at line 244 of file nabstractsocket.h.

Referenced by NTcpSocket::execListen(), getMaxPendingConnections(), and setMaxPendingConnections().


The documentation for this class was generated from the following files:
Generated on Wed Mar 5 23:10:36 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4