n2nc::net::Socket Class Reference

The socket abstaction class. More...

#include <socket.h>

Inheritance diagram for n2nc::net::Socket:

Inheritance graph
[legend]

List of all members.

Public Types

typedef int fd_t

Public Member Functions

virtual int open (SocketAddress &addr)
virtual int send (void *buf, size_t len)
virtual size_t recvCheck ()
virtual int recv (void *buf, size_t len)
virtual int close ()
virtual int bind (SocketAddress &addr)
virtual bool isConnected ()
int getAddressFamily ()
int getType ()
fd_t getFD () const
int setSockOpt (int optname, bool value, int level=SOL_SOCKET)
bool getSockOpt (int optname, int level=SOL_SOCKET)
SocketAddressgetLocalSocketAddress () const
SocketAddressgetRemoteSocketAddress () const

Protected Member Functions

 Socket (int af, int type)

Protected Attributes

int m_fd
int m_af
int m_type
void * m_buf_dirty


Detailed Description

The socket abstaction class.

Author:
fabsoft <fabsoft@gmail.com>
Examples:

socket_ex.cpp.

Definition at line 16 of file socket.h.


Constructor & Destructor Documentation

n2nc::net::Socket::Socket ( int  af,
int  type 
) [protected]

Register a new socket based on address family and type.

Note:
Use the derived class Constructor

Definition at line 6 of file socket.cpp.

References m_fd.


Member Function Documentation

int n2nc::net::Socket::open ( SocketAddress addr  )  [virtual]

Opens a connection to a remote peer service defined in addr. Once using open() function this Socket will be treated as connection-oriented socket and by the way this is mandatory on TcpSocket (SOCK_STREAM type). NOTE: most functions returns native values.

Definition at line 60 of file socket.cpp.

References n2nc::net::SocketAddress::getRawSockAddr(), n2nc::net::SocketAddress::getRawSockAddrLen(), and m_fd.

Referenced by ThreadTest::entry_point().

Here is the call graph for this function:

Here is the caller graph for this function:

int n2nc::net::Socket::send ( void *  buf,
size_t  len 
) [virtual]

Send data buf to remote peer

Reimplemented in n2nc::FilterAdapter, and n2nc::PacketManager.

Definition at line 68 of file socket.cpp.

References m_fd.

Referenced by ThreadTest::entry_point(), n2nc::PacketManager::send(), and n2nc::FilterAdapter::send().

Here is the caller graph for this function:

size_t n2nc::net::Socket::recvCheck (  )  [virtual]

Check wheter the socket has Received data.Return the lenght of data in the kernel buffer

Definition at line 77 of file socket.cpp.

References m_fd, and recv().

Here is the call graph for this function:

int n2nc::net::Socket::recv ( void *  buf,
size_t  len 
) [virtual]

Receive len leght data from remote peer and store it to buf

Reimplemented in n2nc::FilterAdapter, and n2nc::PacketManager.

Examples:
socket_ex.cpp.

Definition at line 87 of file socket.cpp.

References m_fd.

Referenced by n2nc::PacketManager::recv(), n2nc::FilterAdapter::recv(), and recvCheck().

Here is the caller graph for this function:

int n2nc::net::Socket::close (  )  [virtual]

Closes the socket

Definition at line 95 of file socket.cpp.

References m_fd.

int n2nc::net::Socket::bind ( SocketAddress addr  )  [virtual]

Bind the socket to addr

Examples:
socket_ex.cpp.

Definition at line 51 of file socket.cpp.

References n2nc::net::SocketAddress::getRawSockAddr(), n2nc::net::SocketAddress::getRawSockAddrLen(), m_fd, and setSockOpt().

Referenced by n2nc::Server::listen().

Here is the call graph for this function:

Here is the caller graph for this function:

bool n2nc::net::Socket::isConnected (  )  [virtual]

Checks if the socket is connected

Definition at line 161 of file socket.cpp.

int n2nc::net::Socket::getAddressFamily (  ) 

Returns:
the address family in OS defined format

Definition at line 31 of file socket.cpp.

int n2nc::net::Socket::getType (  ) 

Returns:
the type in OS defined format

Definition at line 105 of file socket.cpp.

int n2nc::net::Socket::getFD (  )  const

return the OS defined format file description (HANDLE in win32)

Definition at line 36 of file socket.cpp.

References m_fd.

Referenced by n2nc::net::SocketEventsHandler::add(), and n2nc::net::SocketEventsHandler::del().

Here is the caller graph for this function:

int n2nc::net::Socket::setSockOpt ( int  optname,
bool  value,
int  level = SOL_SOCKET 
)

sets boolean socket option for now, boolean options only

Definition at line 40 of file socket.cpp.

References m_fd.

Referenced by bind(), and n2nc::net::TcpSocket::setListen().

Here is the caller graph for this function:

bool n2nc::net::Socket::getSockOpt ( int  optname,
int  level = SOL_SOCKET 
)

gets a boolean socket option

Definition at line 45 of file socket.cpp.

References m_fd.

SocketAddress * n2nc::net::Socket::getLocalSocketAddress (  )  const

gets the sockaddr (new) associated to local endpoint

Definition at line 110 of file socket.cpp.

References m_fd.

SocketAddress * n2nc::net::Socket::getRemoteSocketAddress (  )  const

gets the sockaddr (new) associated to remote endpoint

Definition at line 135 of file socket.cpp.

References m_fd.


Member Data Documentation

int n2nc::net::Socket::m_fd [protected]


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

Generated on Mon Oct 6 19:32:48 2008 for n2nc by  doxygen 1.5.5