oasys::IPSocket Class Reference

#include <IPSocket.h>

Inheritance diagram for oasys::IPSocket:

oasys::Logger oasys::IOHandlerBase oasys::IPClient oasys::TCPServer oasys::TCPClient oasys::UDPClient oasys::TCPServerThread dtn::APIClient oasys::SMTPClient dtn::UDPConvergenceLayer::Receiver dtn::APIServer dtn::TCPConvergenceLayer::Listener dtntunnel::TCPTunnel::Listener oasys::SMTPServer

List of all members.


Detailed Description

IPSocket is a base class that wraps a network socket.

It is a base for TCPClient, TCPServer, and UDPSocket.

Definition at line 54 of file IPSocket.h.


Public Types

enum  state_t {
  INIT, LISTENING, CONNECTING, ESTABLISHED,
  RDCLOSED, WRCLOSED, CLOSED, FINI
}
 Socket State values. More...

Public Member Functions

 IPSocket (int socktype, const char *logbase)
 IPSocket (int socktype, int sock, in_addr_t remote_addr, u_int16_t remote_port, const char *logbase)
virtual ~IPSocket ()
void configure ()
 Set the socket parameters.
int async_connect_result ()
 In case connect() was called on a nonblocking socket and returned EINPROGRESS, this fn returns the errno result of the connect attempt.
virtual int poll_sockfd (int events, int *revents, int timeout_ms)
 Wrapper around poll() for this socket's fd.
state_t state ()
 Return the current state.
int fd ()
 The socket file descriptor.
in_addr_t local_addr ()
 The local address that the socket is bound to.
u_int16_t local_port ()
 The local port that the socket is bound to.
in_addr_t remote_addr ()
 The remote address that the socket is connected to.
u_int16_t remote_port ()
 The remote port that the socket is connected to.
void set_local_addr (in_addr_t addr)
 Set the local address that the socket is bound to.
void set_local_port (u_int16_t port)
 Set the local port that the socket is bound to.
void set_remote_addr (in_addr_t addr)
 Set the remote address that the socket is connected to.
void set_remote_port (u_int16_t port)
 Set the remote port that the socket is connected to.
void set_logfd (bool logfd)
 logfd can be set to false to disable the appending of the socket file descriptor
void init_socket ()
 Public for use with nonblocking semantics.
virtual int bind (in_addr_t local_addr, u_int16_t local_port)
 System call wrappers.
virtual int connect ()
 System call wrappers.
virtual int connect (in_addr_t remote_addr, u_int16_t remote_port)
 System call wrappers.
virtual int close ()
 System call wrappers.
virtual int shutdown (int how)
 System call wrappers.
virtual int send (const char *bp, size_t len, int flags)
 System call wrappers.
virtual int sendto (char *bp, size_t len, int flags, in_addr_t addr, u_int16_t port)
 System call wrappers.
virtual int sendmsg (const struct msghdr *msg, int flags)
 System call wrappers.
virtual int recv (char *bp, size_t len, int flags)
 System call wrappers.
virtual int recvfrom (char *bp, size_t len, int flags, in_addr_t *addr, u_int16_t *port)
 System call wrappers.
virtual int recvmsg (struct msghdr *msg, int flags)
 System call wrappers.

Public Attributes

struct
oasys::IPSocket::ip_socket_params 
params_
 Socket parameters are public fields that should be set after creating the socket but before the socket is used.

Protected Member Functions

void set_state (state_t state)
const char * statetoa (state_t state)
void get_local ()
void get_remote ()

Protected Attributes

int fd_
int socktype_
state_t state_
bool logfd_
in_addr_t local_addr_
u_int16_t local_port_
in_addr_t remote_addr_
u_int16_t remote_port_

Private Member Functions

 IPSocket (const IPSocket &)
 Prohibited constructor.

Classes

struct  ip_socket_params
 Socket parameters are public fields that should be set after creating the socket but before the socket is used. More...

Member Enumeration Documentation

enum oasys::IPSocket::state_t

Socket State values.

Enumerator:
INIT  initial state
LISTENING  server socket, called listen()
CONNECTING  client socket, called connect()
ESTABLISHED  connected socket, data can flow
RDCLOSED  shutdown(SHUT_RD) called, writing still enabled
WRCLOSED  shutdown(SHUT_WR) called, reading still enabled
CLOSED  shutdown called for both read and write
FINI  close() called on the socket

Definition at line 99 of file IPSocket.h.


Constructor & Destructor Documentation

oasys::IPSocket::IPSocket ( const IPSocket  )  [private]

Prohibited constructor.

oasys::IPSocket::IPSocket ( int  socktype,
const char *  logbase 
)

Definition at line 38 of file IPSocket.cc.

References fd_, INADDR_NONE, INIT, local_addr_, local_port_, logfd_, remote_addr_, remote_port_, socktype_, and state_.

oasys::IPSocket::IPSocket ( int  socktype,
int  sock,
in_addr_t  remote_addr,
u_int16_t  remote_port,
const char *  logbase 
)

Definition at line 51 of file IPSocket.cc.

References configure(), ESTABLISHED, fd_, INADDR_NONE, local_addr_, local_port_, remote_addr_, remote_port_, socktype_, and state_.

oasys::IPSocket::~IPSocket (  )  [virtual]

Definition at line 68 of file IPSocket.cc.

References close().


Member Function Documentation

void oasys::IPSocket::configure (  ) 

Set the socket parameters.

Definition at line 214 of file IPSocket.cc.

References oasys::IPSocket::ip_socket_params::broadcast_, errno, fd_, intoa, oasys::LOG_DEBUG, oasys::LOG_WARN, oasys::Logger::logf(), oasys::IPSocket::ip_socket_params::mcast_ttl_, oasys::IPSocket::ip_socket_params::multicast_, params_, oasys::IPSocket::ip_socket_params::recv_bufsize_, remote_addr_, oasys::IPSocket::ip_socket_params::reuseaddr_, oasys::IPSocket::ip_socket_params::reuseport_, oasys::IPSocket::ip_socket_params::send_bufsize_, socktype_, and oasys::IPSocket::ip_socket_params::tcp_nodelay_.

Referenced by init_socket(), and IPSocket().

int oasys::IPSocket::bind ( in_addr_t  local_addr,
u_int16_t  local_port 
) [virtual]

System call wrappers.

Definition at line 120 of file IPSocket.cc.

References errno, fd_, init_socket(), intoa, local_addr_, local_port_, oasys::LOG_DEBUG, oasys::LOG_ERR, and oasys::Logger::logf().

Referenced by oasys::TCPServerThread::bind_listen_start(), dtn::IPDiscovery::configure(), dtn::UDPConvergenceLayer::Sender::init(), dtn::UDPConvergenceLayer::interface_up(), dtn::TCPConvergenceLayer::interface_up(), and dtntunnel::UDPTunnel::Listener::run().

int oasys::IPSocket::connect (  )  [virtual]

System call wrappers.

Definition at line 146 of file IPSocket.cc.

References CONNECTING, errno, ESTABLISHED, fd_, init_socket(), intoa, log_debug, remote_addr_, remote_port_, set_state(), and state_.

Referenced by connect(), dtn::UDPConvergenceLayer::Sender::init(), dtn::UDPConvergenceLayer::interface_up(), dtntunnel::TCPTunnel::Connection::run(), and oasys::TCPClient::timeout_connect().

int oasys::IPSocket::connect ( in_addr_t  remote_addr,
u_int16_t  remote_port 
) [virtual]

System call wrappers.

Definition at line 205 of file IPSocket.cc.

References connect(), remote_addr_, and remote_port_.

int oasys::IPSocket::close (  )  [virtual]

System call wrappers.

Definition at line 321 of file IPSocket.cc.

References ASSERT, errno, fd_, FINI, INIT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), set_state(), state_, and statetoa().

Referenced by dtn::UDPConvergenceLayer::Receiver::run(), dtntunnel::TCPTunnel::Connection::run(), oasys::TCPServerThread::run(), and ~IPSocket().

int oasys::IPSocket::shutdown ( int  how  )  [virtual]

System call wrappers.

Definition at line 342 of file IPSocket.cc.

References ASSERT, CLOSED, errno, ESTABLISHED, fd_, FINI, INIT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), RDCLOSED, set_state(), state_, statetoa(), and WRCLOSED.

int oasys::IPSocket::send ( const char *  bp,
size_t  len,
int  flags 
) [virtual]

System call wrappers.

Definition at line 389 of file IPSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::send().

Referenced by oasys::RateLimitedSocket::send().

int oasys::IPSocket::sendto ( char *  bp,
size_t  len,
int  flags,
in_addr_t  addr,
u_int16_t  port 
) [virtual]

System call wrappers.

Definition at line 395 of file IPSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::sendto().

Referenced by dtntunnel::UDPTunnel::handle_bundle(), dtn::IPDiscovery::run(), and oasys::RateLimitedSocket::sendto().

int oasys::IPSocket::sendmsg ( const struct msghdr *  msg,
int  flags 
) [virtual]

System call wrappers.

Definition at line 409 of file IPSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::sendmsg().

int oasys::IPSocket::recv ( char *  bp,
size_t  len,
int  flags 
) [virtual]

System call wrappers.

Definition at line 415 of file IPSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::recv().

Referenced by dtntunnel::UDPTunnel::Listener::run().

int oasys::IPSocket::recvfrom ( char *  bp,
size_t  len,
int  flags,
in_addr_t *  addr,
u_int16_t *  port 
) [virtual]

System call wrappers.

Definition at line 422 of file IPSocket.cc.

References errno, fd_, oasys::IOHandlerBase::get_notifier(), oasys::IOINTR, oasys::LOG_ERR, oasys::Logger::logf(), oasys::Logger::logpath_, and oasys::IO::recvfrom().

Referenced by dtn::UDPConvergenceLayer::Receiver::run(), and dtn::IPDiscovery::run().

int oasys::IPSocket::recvmsg ( struct msghdr *  msg,
int  flags 
) [virtual]

System call wrappers.

Definition at line 448 of file IPSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::recvmsg().

int oasys::IPSocket::async_connect_result (  ) 

In case connect() was called on a nonblocking socket and returned EINPROGRESS, this fn returns the errno result of the connect attempt.

It also sets the socket state appropriately

Definition at line 185 of file IPSocket.cc.

References ASSERT, CONNECTING, errno, ESTABLISHED, fd_, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), set_state(), and state_.

int oasys::IPSocket::poll_sockfd ( int  events,
int *  revents,
int  timeout_ms 
) [virtual]

Wrapper around poll() for this socket's fd.

Definition at line 454 of file IPSocket.cc.

References fd_, oasys::IOHandlerBase::get_notifier(), oasys::Logger::logpath_, and oasys::IO::poll_single().

Referenced by dtn::IPDiscovery::run(), and oasys::TCPServer::timeout_accept().

state_t oasys::IPSocket::state (  )  [inline]

Return the current state.

Definition at line 113 of file IPSocket.h.

References state_.

Referenced by dtntunnel::TCPTunnel::Connection::run().

int oasys::IPSocket::fd (  )  [inline]

The socket file descriptor.

Definition at line 145 of file IPSocket.h.

References fd_.

Referenced by dtntunnel::TCPTunnel::Connection::run(), and oasys::TCPServerThread::run().

in_addr_t oasys::IPSocket::local_addr (  )  [inline]

The local address that the socket is bound to.

Definition at line 203 of file IPSocket.h.

References get_local(), INADDR_NONE, and local_addr_.

Referenced by dtn::TCPConvergenceLayer::dump_interface(), and dtn::APIClient::run().

u_int16_t oasys::IPSocket::local_port (  )  [inline]

The local port that the socket is bound to.

Definition at line 210 of file IPSocket.h.

References get_local(), and local_port_.

Referenced by dtn::TCPConvergenceLayer::dump_interface(), and dtn::APIClient::run().

in_addr_t oasys::IPSocket::remote_addr (  )  [inline]

The remote address that the socket is connected to.

Definition at line 217 of file IPSocket.h.

References get_remote(), INADDR_NONE, and remote_addr_.

Referenced by dtn::APIClient::run().

u_int16_t oasys::IPSocket::remote_port (  )  [inline]

The remote port that the socket is connected to.

Definition at line 224 of file IPSocket.h.

References get_remote(), and remote_port_.

Referenced by dtn::APIClient::run().

void oasys::IPSocket::set_local_addr ( in_addr_t  addr  )  [inline]

Set the local address that the socket is bound to.

Definition at line 231 of file IPSocket.h.

References local_addr_.

void oasys::IPSocket::set_local_port ( u_int16_t  port  )  [inline]

Set the local port that the socket is bound to.

Definition at line 237 of file IPSocket.h.

References local_port_.

void oasys::IPSocket::set_remote_addr ( in_addr_t  addr  )  [inline]

Set the remote address that the socket is connected to.

Definition at line 243 of file IPSocket.h.

References remote_addr_.

Referenced by dtn::IPDiscovery::configure().

void oasys::IPSocket::set_remote_port ( u_int16_t  port  )  [inline]

Set the remote port that the socket is connected to.

Definition at line 249 of file IPSocket.h.

References remote_port_.

void oasys::IPSocket::set_logfd ( bool  logfd  )  [inline]

logfd can be set to false to disable the appending of the socket file descriptor

Definition at line 178 of file IPSocket.h.

References logfd_.

Referenced by dtn::UDPConvergenceLayer::Sender::init().

void oasys::IPSocket::init_socket (  ) 

Public for use with nonblocking semantics.

Definition at line 74 of file IPSocket.cc.

References ASSERT, configure(), errno, fd_, FINI, INIT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), logfd_, oasys::Logger::logpath_appendf(), socktype_, and state_.

Referenced by bind(), connect(), oasys::TCPClient::TCPClient(), oasys::TCPClient::timeout_connect(), and dtntunnel::UDPTunnel::UDPTunnel().

void oasys::IPSocket::set_state ( state_t  state  )  [protected]

Definition at line 113 of file IPSocket.cc.

References oasys::LOG_DEBUG, oasys::Logger::logf(), state_, and statetoa().

Referenced by async_connect_result(), close(), connect(), oasys::TCPServer::listen(), shutdown(), and oasys::TCPClient::timeout_connect().

const char * oasys::IPSocket::statetoa ( state_t  state  )  [protected]

Definition at line 96 of file IPSocket.cc.

References ASSERT, CLOSED, CONNECTING, ESTABLISHED, FINI, INIT, LISTENING, RDCLOSED, and WRCLOSED.

Referenced by oasys::TCPServer::accept(), close(), set_state(), and shutdown().

void oasys::IPSocket::get_local (  )  [inline, protected]

Definition at line 255 of file IPSocket.h.

References fd_, local_addr_, and local_port_.

Referenced by local_addr(), and local_port().

void oasys::IPSocket::get_remote (  )  [inline, protected]

Definition at line 269 of file IPSocket.h.

References fd_, remote_addr_, and remote_port_.

Referenced by remote_addr(), and remote_port().


Member Data Documentation

struct oasys::IPSocket::ip_socket_params oasys::IPSocket::params_

Socket parameters are public fields that should be set after creating the socket but before the socket is used.

Reimplemented in dtn::UDPConvergenceLayer::Receiver.

Referenced by configure(), dtn::IPDiscovery::configure(), and oasys::TCPServer::TCPServer().

int oasys::IPSocket::fd_ [protected]

Definition at line 184 of file IPSocket.h.

Referenced by oasys::TCPServer::accept(), async_connect_result(), bind(), close(), configure(), connect(), fd(), get_local(), oasys::IPClient::get_nonblocking(), get_remote(), init_socket(), IPSocket(), oasys::TCPServer::listen(), poll_sockfd(), oasys::IPClient::read(), oasys::IPClient::readall(), oasys::IPClient::readv(), oasys::IPClient::readvall(), recv(), recvfrom(), recvmsg(), send(), sendmsg(), sendto(), oasys::IPClient::set_nonblocking(), shutdown(), oasys::TCPClient::TCPClient(), oasys::TCPClient::timeout_connect(), oasys::IPClient::timeout_read(), oasys::IPClient::timeout_readall(), oasys::IPClient::timeout_readv(), oasys::IPClient::timeout_readvall(), oasys::IPClient::timeout_write(), oasys::IPClient::timeout_writeall(), oasys::IPClient::timeout_writev(), oasys::IPClient::timeout_writevall(), oasys::IPClient::write(), oasys::IPClient::writeall(), oasys::IPClient::writev(), and oasys::IPClient::writevall().

int oasys::IPSocket::socktype_ [protected]

Definition at line 185 of file IPSocket.h.

Referenced by configure(), init_socket(), and IPSocket().

state_t oasys::IPSocket::state_ [protected]

Definition at line 186 of file IPSocket.h.

Referenced by oasys::TCPServer::accept(), async_connect_result(), close(), connect(), init_socket(), IPSocket(), set_state(), shutdown(), state(), and oasys::TCPClient::timeout_connect().

bool oasys::IPSocket::logfd_ [protected]

Definition at line 187 of file IPSocket.h.

Referenced by init_socket(), IPSocket(), dtn::TCPConvergenceLayer::Listener::Listener(), dtn::UDPConvergenceLayer::Receiver::Receiver(), and set_logfd().

in_addr_t oasys::IPSocket::local_addr_ [protected]

Reimplemented in dtn::APIServer.

Definition at line 189 of file IPSocket.h.

Referenced by bind(), get_local(), IPSocket(), local_addr(), and set_local_addr().

u_int16_t oasys::IPSocket::local_port_ [protected]

Reimplemented in dtn::APIServer.

Definition at line 190 of file IPSocket.h.

Referenced by bind(), get_local(), IPSocket(), local_port(), and set_local_port().

in_addr_t oasys::IPSocket::remote_addr_ [protected]

Reimplemented in dtntunnel::TCPTunnel::Listener.

Definition at line 191 of file IPSocket.h.

Referenced by configure(), connect(), get_remote(), IPSocket(), remote_addr(), and set_remote_addr().

u_int16_t oasys::IPSocket::remote_port_ [protected]

Reimplemented in dtntunnel::TCPTunnel::Listener.

Definition at line 192 of file IPSocket.h.

Referenced by connect(), get_remote(), IPSocket(), remote_port(), and set_remote_port().


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 08:43:52 2007 for DTN Reference Implementation by  doxygen 1.5.3