BioInt  1.02.00
BioInt: An integrative biological object-oriented application framework and interpreter
BioSocket Struct Reference

#include <BioSocketBase.h>

List of all members.

Public Types

enum  format { pf_unspec = PF_UNSPEC, pf_unix = PF_UNIX, pf_inet = PF_INET, pf_max = PF_MAX }
 Address format specifications, for the create() member. More...
enum  type {
  sock_stream = SOCK_STREAM, sock_dgram = SOCK_DGRAM, sock_raw = SOCK_RAW, sock_rdm = SOCK_RDM,
  sock_seqpacket = SOCK_SEQPACKET
}
 Type specification for the create() method. More...
enum  protocol {
  proto_ip = IPPROTO_IP, proto_icmp = IPPROTO_ICMP, proto_tcp = IPPROTO_TCP, proto_pup = IPPROTO_PUP,
  proto_udp = IPPROTO_UDP, proto_idp = IPPROTO_IDP, proto_raw = IPPROTO_RAW, proto_max = IPPROTO_MAX
}
 Protocol to be used on this socket. More...
enum  { invalid_socket = INVALID_SOCKET }
enum  msgflag { msg_none = 0, msg_oob = MSG_OOB, msg_peek = MSG_PEEK, msg_dontroute = MSG_DONTROUTE }
 Flags to use with recv/send methods. More...
enum  shuthow { shut_recv = 0, shut_send = 1, shut_both = 2 }
 Flags for the shutdown() method. More...
enum  errors {
  socket_error = SOCKET_ERROR, eintr = WSAEINTR, ebadf = WSAEBADF, eacces = WSAEACCES,
  efault = WSAEFAULT, einval = WSAEINVAL, emfile = WSAEMFILE, ewouldblock = WSAEWOULDBLOCK,
  einprogress = WSAEINPROGRESS, ealready = WSAEALREADY, enotsock = WSAENOTSOCK, edestaddrreq = WSAEDESTADDRREQ,
  emsgsize = WSAEMSGSIZE, eprototype = WSAEPROTOTYPE, enoprotoopt = WSAENOPROTOOPT, eprotonosupport = WSAEPROTONOSUPPORT,
  esocktnotsupport = WSAESOCKTNOSUPPORT, eopnotsupp = WSAEOPNOTSUPP, epfnosupport = WSAEPFNOSUPPORT, afnosupport = WSAEAFNOSUPPORT,
  eaddrinuse = WSAEADDRINUSE, eaddrnotavail = WSAEADDRNOTAVAIL, enetdown = WSAENETDOWN, enetunreach = WSAENETUNREACH,
  enetreset = WSAENETRESET, econnaborted = WSAECONNABORTED, econnreset = WSAECONNRESET, enobufs = WSAENOBUFS,
  eisconn = WSAEISCONN, enotconn = WSAENOTCONN, eshutdown = WSAESHUTDOWN, etoomanyrefs = WSAETOOMANYREFS,
  etimedout = WSAETIMEDOUT, econnrefused = WSAECONNREFUSED, eloop = WSAELOOP, enametoolong = WSAENAMETOOLONG,
  ehostdown = WSAEHOSTDOWN, ehostunreach = WSAEHOSTUNREACH, host_not_found = WSAHOST_NOT_FOUND, try_again = WSATRY_AGAIN,
  no_recovery = WSANO_RECOVERY, no_data = WSANO_DATA
}
 Errors that may be set by the different socklibpp::sock operations. More...
enum  ioctl_cmd { fionbio = FIONBIO, fionread = FIONREAD, siocatmark = SIOCATMARK }
 Flags to use in the sock::ioctl method. More...
enum  mode { passive, active }
 Flags to use in the convenience constructor. More...
enum  optlevel { sol_socket = SOL_SOCKET, ipproto_tcp = IPPROTO_TCP }
 Levels of socket options for the getsockopt/setsockopt methods. More...
enum  optname {
  so_acceptconn = SO_ACCEPTCONN, so_broadcast = SO_BROADCAST, so_debug = SO_DEBUG, so_dontroute = SO_DONTROUTE,
  so_error = SO_ERROR, so_keepalive = SO_KEEPALIVE, so_linger = SO_LINGER, so_oobinline = SO_OOBINLINE,
  so_rcvbuf = SO_RCVBUF, so_reuseaddr = SO_REUSEADDR, so_sndbuf = SO_SNDBUF, so_type = SO_TYPE,
  tcp_nodelay = TCP_NODELAY
}
 Option names for the getsockopt/setsockopt methods. More...
enum  selectstate { readable = 1, writable = 2, exceptable = 4 }
 select() results More...

Public Member Functions

 BioSocket () throw ()
 Default constructor.
 BioSocket (socket_type fd_) throw ()
 Constructor that uses an already created socket descriptor.
 BioSocket (format, type, protocol=proto_ip) throw ()
 Constructs and allocates a new socket.
BioSocket accept () throw ()
 Accept incomming connections in a listening socket.
BioSocket accept (BioSocketAddress &) throw ()
 Accepts incomming connections in a listening socket and stores the accepted address.
bool bind (const BioSocketAddress &) throw ()
 Bind the socket to a specific address.
bool close () throw ()
 Close the socket, releasing the resources used by it.
bool connect (const BioSocketAddress &) throw ()
 Create a connection to the specified address.
bool peername (BioSocketAddress &) const throw ()
 Get the address of the peer at which the socket is connected.
bool sockname (BioSocketAddress &) throw ()
 Get the local address of the socket.
bool getsockopt (optlevel, optname, int &) const throw ()
 Retrieve a socket option.
bool getsockopt (optlevel, optname, bool &) const throw ()
 Retrieve a socket option.
bool ioctl (ioctl_cmd, unsigned long &) throw ()
 Control the mode of a socket.
bool listen (int=3) throw ()
 Put the socket in passive (listen) mode for incomming connections.
int recv (char *, int, msgflag=msg_none) throw ()
 Receive data from a socket.
int recvfrom (BioSocketAddress &, char *, int, msgflag=msg_none) throw ()
 Receive a datagram and store the source address.
bool can_read (long=0, long=0) const throw ()
 Check if the socket has data to be read.
bool wait_read (long &, long &) const throw ()
 Wait until data can be read.
bool wait_read () const throw ()
 Wait until data can be read.
bool can_write (int=0, int=0) throw ()
 Check if the socket can be written to.
bool can_except (int=0, int=0) throw ()
 Checks for the presence of out-of-band data or if any exceptional error conditions.
unsigned select (int=0, int=0) throw ()
 Do a normal select(), returning the state of the socket.
int send (const char *, int, msgflag=msg_none) throw ()
 Send data on a connected socket.
int sendto (const BioSocketAddress &, const char *, int, msgflag=msg_none) throw ()
 Send data to a specific destination.
bool setsockopt (optlevel, optname, int) throw ()
 Set a socket option.
bool shutdown (shuthow) throw ()
 Disable sends and/or receives on a socket.
bool create (format, type, protocol=proto_ip) throw ()
 Create a new socket.
bool socket (format fmt, type tp, protocol pr=proto_ip) throw ()
 Synonym for create()
bool sendall (const char *, int, msgflag=msg_none) throw ()
 Send all data.
bool recvall (char *, int, msgflag=msg_none) throw ()
 Recv all data.
bool block (bool) throw ()
 Set the blocking mode.
bool reuseaddr () const throw ()
 Query if it can reuse the addr.
bool reuseaddr (bool) throw ()
 Set the reuse addr option.
int sendbuf () const throw ()
 Get the size of the internal send buffer.
void sendbuf (int) throw ()
 Set the size of the internal send buffer.
int recvbuf () const throw ()
 Get the size of the internal recv buffer.
void recvbuf (int) throw ()
 Set the size of the internal recv buffer.

Public Attributes

socket_type fd
 The descriptor of this socket.
int error
 The error code of the last operation performed.

Member Enumeration Documentation

anonymous enum
Enumerator:
invalid_socket 

An invalid socket.

Errors that may be set by the different socklibpp::sock operations.

Enumerator:
socket_error 

Error value used as result for some functions.

eintr 
ebadf 
eacces 
efault 
einval 
emfile 
ewouldblock 

The requested operation would block, try again later.

einprogress 
ealready 
enotsock 
edestaddrreq 
emsgsize 
eprototype 
enoprotoopt 
eprotonosupport 
esocktnotsupport 
eopnotsupp 
epfnosupport 
afnosupport 
eaddrinuse 
eaddrnotavail 
enetdown 
enetunreach 
enetreset 
econnaborted 
econnreset 
enobufs 
eisconn 
enotconn 
eshutdown 
etoomanyrefs 
etimedout 
econnrefused 
eloop 
enametoolong 
ehostdown 
ehostunreach 
host_not_found 
try_again 
no_recovery 
no_data 

Address format specifications, for the create() member.

Enumerator:
pf_unspec 

Unspecified.

pf_unix 

Unix pipes.

pf_inet 

IPv4 format.

pf_max 

not used

Flags to use in the sock::ioctl method.

Enumerator:
fionbio 

Enable or disable non-blocking mode on the socket.

fionread 

Determine the amount of data which can be read atomically from socket.

siocatmark 

Determine whether or not all out-of-band data has been read.

Flags to use in the convenience constructor.

Enumerator:
passive 

Create a sock_stream socket and put it in listen mode.

active 

Create a sock_stream socket and connect it.

Flags to use with recv/send methods.

Enumerator:
msg_none 

Default.

msg_oob 

send/recv out-of-band data (sock_stream only).

msg_peek 

Peek at the incoming data.

msg_dontroute 

Should not be subject to routing.

Levels of socket options for the getsockopt/setsockopt methods.

Enumerator:
sol_socket 
ipproto_tcp 

Option names for the getsockopt/setsockopt methods.

Enumerator:
so_acceptconn 

(bool) Socket is listen()ing.

so_broadcast 

(bool) Socket is configured for the transmission of broadcast messages.

so_debug 

(bool) Debugging is enabled.

so_dontroute 

(bool) Routing is disabled.

so_error 

(int) Retrieve error status and clear.

so_keepalive 

(bool Keepalives are being sent.

so_linger 

(struct linger *) Returns the current linger options.

so_oobinline 

(bool) Out-of-band data is being received in the normal data stream.

so_rcvbuf 

(int) Buffer size for receives

so_reuseaddr 

(bool) The socket may be bound to an address which is already in use.

so_sndbuf 

(int) Buffer size for sends

so_type 

(int) The type of the socket (e.g. sock_stream).

tcp_nodelay 

(bool) Disables the Nagle algorithm for send coalescing.

Protocol to be used on this socket.

Enumerator:
proto_ip 

Default protocol for the specified socket type.

proto_icmp 

ICMP.

proto_tcp 

TCP.

proto_pup 

PUP.

proto_udp 

UDP.

proto_idp 

IDP.

proto_raw 

RAW.

proto_max 

not used

select() results

Enumerator:
readable 

there is data waiting to be read

writable 

socket can be written to without blocking

exceptable 

there is an exceptional event pending

Flags for the shutdown() method.

Enumerator:
shut_recv 

Disallows further recv() calls.

shut_send 

Disallows further send() calls.

shut_both 

Disallows both send() and recv() calls.

Type specification for the create() method.

Enumerator:
sock_stream 

Stream sockets (TCP)

sock_dgram 

Datagram sockets.

sock_raw 

Raw sockets.

sock_rdm 
sock_seqpacket 

Constructor & Destructor Documentation

BioSocket::BioSocket ( ) throw () [inline]

Default constructor.

It doesn't allocate resources for a socket, you have to call create() to actually allocate a socket.

See also:
create()
BioSocket::BioSocket ( socket_type  fd_) throw () [inline]

Constructor that uses an already created socket descriptor.

Parameters:
_fda socket_type descriptor.
BioSocket::BioSocket ( format  ,
type  ,
protocol  = proto_ip 
) throw ()

Constructs and allocates a new socket.


Member Function Documentation

Accept incomming connections in a listening socket.

Accepts incomming connections in a listening socket and stores the accepted address.

bool BioSocket::bind ( const BioSocketAddress ) throw ()

Bind the socket to a specific address.

bool BioSocket::block ( bool  ) throw ()

Set the blocking mode.

bool BioSocket::can_except ( int  = 0,
int  = 0 
) throw ()

Checks for the presence of out-of-band data or if any exceptional error conditions.

bool BioSocket::can_read ( long  = 0,
long  = 0 
) const throw ()

Check if the socket has data to be read.

Here is the caller graph for this function:

bool BioSocket::can_write ( int  = 0,
int  = 0 
) throw ()

Check if the socket can be written to.

Here is the caller graph for this function:

bool BioSocket::close ( ) throw ()

Close the socket, releasing the resources used by it.

Here is the caller graph for this function:

bool BioSocket::connect ( const BioSocketAddress ) throw ()

Create a connection to the specified address.

Here is the caller graph for this function:

bool BioSocket::create ( format  ,
type  ,
protocol  = proto_ip 
) throw ()

Create a new socket.

Here is the caller graph for this function:

bool BioSocket::getsockopt ( optlevel  ,
optname  ,
int &   
) const throw ()

Retrieve a socket option.

bool BioSocket::getsockopt ( optlevel  ,
optname  ,
bool &   
) const throw ()

Retrieve a socket option.

bool BioSocket::ioctl ( ioctl_cmd  ,
unsigned long &   
) throw ()

Control the mode of a socket.

Here is the caller graph for this function:

bool BioSocket::listen ( int  = 3) throw ()

Put the socket in passive (listen) mode for incomming connections.

bool BioSocket::peername ( BioSocketAddress ) const throw ()

Get the address of the peer at which the socket is connected.

Here is the caller graph for this function:

int BioSocket::recv ( char *  ,
int  ,
msgflag  = msg_none 
) throw ()

Receive data from a socket.

Here is the caller graph for this function:

bool BioSocket::recvall ( char *  ,
int  ,
msgflag  = msg_none 
) throw ()

Recv all data.

int BioSocket::recvbuf ( ) const throw ()

Get the size of the internal recv buffer.

void BioSocket::recvbuf ( int  ) throw ()

Set the size of the internal recv buffer.

int BioSocket::recvfrom ( BioSocketAddress ,
char *  ,
int  ,
msgflag  = msg_none 
) throw ()

Receive a datagram and store the source address.

bool BioSocket::reuseaddr ( ) const throw ()

Query if it can reuse the addr.

bool BioSocket::reuseaddr ( bool  ) throw ()

Set the reuse addr option.

unsigned BioSocket::select ( int  = 0,
int  = 0 
) throw ()

Do a normal select(), returning the state of the socket.

int BioSocket::send ( const char *  ,
int  ,
msgflag  = msg_none 
) throw ()

Send data on a connected socket.

Here is the caller graph for this function:

bool BioSocket::sendall ( const char *  ,
int  ,
msgflag  = msg_none 
) throw ()

Send all data.

int BioSocket::sendbuf ( ) const throw ()

Get the size of the internal send buffer.

void BioSocket::sendbuf ( int  ) throw ()

Set the size of the internal send buffer.

int BioSocket::sendto ( const BioSocketAddress ,
const char *  ,
int  ,
msgflag  = msg_none 
) throw ()

Send data to a specific destination.

bool BioSocket::setsockopt ( optlevel  ,
optname  ,
int   
) throw ()

Set a socket option.

bool BioSocket::shutdown ( shuthow  ) throw ()

Disable sends and/or receives on a socket.

bool BioSocket::socket ( format  fmt,
type  tp,
protocol  pr = proto_ip 
) throw () [inline]

Synonym for create()

Here is the call graph for this function:

bool BioSocket::sockname ( BioSocketAddress ) throw ()

Get the local address of the socket.

bool BioSocket::wait_read ( long &  ,
long &   
) const throw ()

Wait until data can be read.

bool BioSocket::wait_read ( ) const throw ()

Wait until data can be read.


Member Data Documentation

int BioSocket::error [mutable]

The error code of the last operation performed.

If no error ocurred in the last operation, the value is zero.

Note:
For some operations this is the only way to detect if an error ocurred. e.g. accept()

The descriptor of this socket.

This usually have the size of an int, but may be signed or unsigned depending on the platform. You should never use < or > to compare it with any other value. The only useful value to compare is socklibpp::sock::invalid_socket, and you should always test using == or !=.


The documentation for this struct was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines