#include <socket.h>
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) |
SocketAddress * | getLocalSocketAddress () const |
SocketAddress * | getRemoteSocketAddress () const |
Protected Member Functions | |
Socket (int af, int type) | |
Protected Attributes | |
int | m_fd |
int | m_af |
int | m_type |
void * | m_buf_dirty |
Definition at line 16 of file socket.h.
n2nc::net::Socket::Socket | ( | int | af, | |
int | type | |||
) | [protected] |
Register a new socket based on address family and type.
Definition at line 6 of file socket.cpp.
References m_fd.
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().
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().
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.
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.
Definition at line 87 of file socket.cpp.
References m_fd.
Referenced by n2nc::PacketManager::recv(), n2nc::FilterAdapter::recv(), and recvCheck().
int n2nc::net::Socket::close | ( | ) | [virtual] |
int n2nc::net::Socket::bind | ( | SocketAddress & | addr | ) | [virtual] |
Bind the socket to addr
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().
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 | ( | ) |
int n2nc::net::Socket::getType | ( | ) |
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().
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().
bool n2nc::net::Socket::getSockOpt | ( | int | optname, | |
int | level = SOL_SOCKET | |||
) |
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.
int n2nc::net::Socket::m_fd [protected] |
save some context switch but led memory
Definition at line 62 of file socket.h.
Referenced by n2nc::net::TcpSocket::accept(), bind(), close(), getFD(), getLocalSocketAddress(), getRemoteSocketAddress(), getSockOpt(), open(), recv(), recvCheck(), send(), n2nc::net::TcpSocket::setListen(), setSockOpt(), and Socket().