Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ss::basic_socket Class Reference

Socket class wraps up the C socket interface. More...

#include <basic_socket.h>

List of all members.

Public Types

typedef sockets_base::socket_type descriptor_t
 This is the type of a socket descriptor on the system.

Public Member Functions

 basic_socket ()
 Default constructor.
 basic_socket (int __family, int __style, int __protocol=0)
 Constructor.
 basic_socket (descriptor_t __sd)
 Constructor for an existing socket descriptor.
 ~basic_socket ()
void bind (sockaddr const *__addr, socklen_t __size)
 Bind socket to local address.
void connect (sockaddr const *__addr, socklen_t __size)
 Connect socket to remote address.
void listen (int __backlog=5)
 Listen to incoming connections.
descriptor_t accept ()
 Accept incoming connection.
int receive (char *__s, size_t __n, int __flags=0)
 Receive data on connected socket.
int receive (char *__s, size_t __n, sockaddr *__addr, socklen_t *__size, int __flags=0)
 Receive data on connectionless socket.
int send (const char *__s, size_t __n, int __flags=0)
 Send data on connected socket.
int send (const char *__s, size_t __n, sockaddr const *__addr, socklen_t __size, int __flags=0)
 Send data on connectionless socket.
void set_option (int __level, int __option, char const *__value, socklen_t __size)
 Set socket option.
void get_option (int __level, int __option, char *__value, socklen_t *__size) const
 Get socket option.
void shutdown (int __mode=sockets_base::rw)
 Shut the socket down.
void peer_address (sockaddr *__name, socklen_t *__size) const
 Peer address.
void socket_address (sockaddr *__name, socklen_t *__size) const
 Socket address.
descriptor_t descriptor () const
 Socket descriptor.

Friends

class basic_socketbuf


Detailed Description

Socket class wraps up the C socket interface.

This class implements "resource acquisition is initialization" for socket descriptors.

The purpose of this class is to merely wrap the C socket API (effectively, to wrap the socket descriptor). Thus, it's member function prototypes follow closely those of the C API, and no error treatment other than the trivial is done.

The only big departure from the C API is the fact that error conditions intercepted are thrown as socket_exception objects containing the error code from std::errno. Thus, almost all functions now return void.

Also, the return type of the accept method is basic_socket, instead of the descriptor type.

All I/O operations are considered non-const operations; setsockopt is also considered non-const for obvious reasons. getsockopt, getpeername, getsockname, and all "properties" are considered const operations.

Definition at line 57 of file basic_socket.h.


Member Typedef Documentation

typedef sockets_base::socket_type ss::basic_socket::descriptor_t
 

This is the type of a socket descriptor on the system.

This is usually int, but don't count on it unless you're Unix-only.

Definition at line 66 of file basic_socket.h.


Constructor & Destructor Documentation

ss::basic_socket::basic_socket  ) 
 

Default constructor.

Socket's constructor wraps the socket() system call, which allocates a socket descriptor in the system for this process. This constructor will create a socket of default family and style, currently sockets_base::inet and sockets_base::stream.

ss::basic_socket::basic_socket int  __family,
int  __style,
int  __protocol = 0
 

Constructor.

Parameters:
__family Socket's address family.
__style Socket's communication style.
__protocol Socket's communication protocol.
Socket's constructor wraps the socket() system call, which allocates a socket descriptor in the system for this process.

Constructs socket of specified family, style and protocol. We usually use a default protocol.

ss::basic_socket::basic_socket descriptor_t  __sd  ) 
 

Constructor for an existing socket descriptor.

Parameters:
__sd Socket descriptor.
This constructor does no call socket(), and just associates itself with the specified socket descriptor.

basic_socket takes ownership of the descriptor, and will close it at destruction time.

Particularly useful with basic_socket::accept().

ss::basic_socket::~basic_socket  ) 
 

Destructor.


Member Function Documentation

descriptor_t ss::basic_socket::accept  ) 
 

Accept incoming connection.

Returns:
Descriptor for connected socket.
Accepts an incoming connection on a listening socket, and returns a socket descriptor connected to that peer ready for I/O.

Referenced by ss::basic_listener< _CharT, _Traits >::accept().

void ss::basic_socket::bind sockaddr const *  __addr,
socklen_t  __size
 

Bind socket to local address.

Parameters:
__addr Pointer to buffer containing addres to bind to.
__size Size of address buffer.
This will set the local address, which is usually only important in preparation for a listen().

Referenced by ss::basic_listener< _CharT, _Traits >::bind().

void ss::basic_socket::connect sockaddr const *  __addr,
socklen_t  __size
 

Connect socket to remote address.

Parameters:
__addr Pointer to buffer containing address to connect to.
__size Size of address buffer.
This will attempt to connect at a remote (listening) socket bound to the specified address. This is only truly meaningful for stream sockets.

Referenced by ss::basic_socketbuf< char_type, traits_type >::connect().

descriptor_t ss::basic_socket::descriptor  )  const [inline]
 

Socket descriptor.

Returns:
Socket descriptor.

Definition at line 287 of file basic_socket.h.

void ss::basic_socket::get_option int  __level,
int  __option,
char *  __value,
socklen_t *  __size
const
 

Get socket option.

Parameters:
__level Option level.
__option Option code.
__value Pointer to buffer to store option value.
__size Pointer to socklen_t to store option value size.
This function obtains a socket option value with getsockopt().

void ss::basic_socket::listen int  __backlog = 5  ) 
 

Listen to incoming connections.

Parameters:
__backlog (can be safely left on default).
Puts socket in a listening state, so it can accept connections.

This is the opposite of connect(), so to speak, and is only truly meaningful for stream sockets.

Referenced by ss::basic_listener< _CharT, _Traits >::listen().

void ss::basic_socket::peer_address sockaddr *  __name,
socklen_t *  __size
const
 

Peer address.

Parameters:
__name Peer address.
__size Size of address structure.

int ss::basic_socket::receive char *  __s,
size_t  __n,
sockaddr *  __addr,
socklen_t *  __size,
int  __flags = 0
 

Receive data on connectionless socket.

Parameters:
__s Pointer to input buffer.
__n Size of input buffer.
__addr Pointer to buffer to store sender address.
__size Size of address buffer.
__flags I/O flags.
Returns:
Number of bytes received.
This function is only truly meaningful with connectionless sockets.

int ss::basic_socket::receive char *  __s,
size_t  __n,
int  __flags = 0
 

Receive data on connected socket.

Parameters:
__s Pointer to input buffer.
__n Size of input buffer.
__flags I/O flags.
Returns:
Number of bytes received.

Referenced by ss::basic_socketbuf< char_type, traits_type >::showmanyc(), and ss::basic_socketbuf< char_type, traits_type >::underflow().

int ss::basic_socket::send const char *  __s,
size_t  __n,
sockaddr const *  __addr,
socklen_t  __size,
int  __flags = 0
 

Send data on connectionless socket.

Parameters:
__s Pointer to buffer containing data to send.
__n Size of data buffer.
__addr Pointer to buffer containing address to send to.
__size Size of the address buffer.
__flags I/O flags.
Returns:
Number of bytes sent.
This function is only truly meaningful with connectionless sockets.

int ss::basic_socket::send const char *  __s,
size_t  __n,
int  __flags = 0
 

Send data on connected socket.

Parameters:
__s Pointer to buffer containing data to send.
__n Size of data buffer.
__flags I/O flags.
Returns:
Number of bytes sent.

Referenced by ss::basic_socketbuf< char_type, traits_type >::overflow().

void ss::basic_socket::set_option int  __level,
int  __option,
char const *  __value,
socklen_t  __size
 

Set socket option.

Parameters:
__level Option level.
__option Option code.
__value Pointer to buffer with option value.
__size Size of option value.
This function sets a socket option with setsockopt().

void ss::basic_socket::shutdown int  __mode = sockets_base::rw  ) 
 

Shut the socket down.

Parameters:
__mode Mode.
This will close the connection with the peer for sending, receiving or both.

Referenced by ss::basic_socketbuf< char_type, traits_type >::shutdown().

void ss::basic_socket::socket_address sockaddr *  __name,
socklen_t *  __size
const
 

Socket address.

Parameters:
__name socket address.
__size Size of adsress structure.


The documentation for this class was generated from the following file:
Generated on Sat May 21 21:25:50 2005 for Socket Streams Library by  doxygen 1.4.3