Claw  1.7.3
Public Types | Public Member Functions | Protected Member Functions | List of all members
claw::net::basic_socketbuf< CharT, Traits > Class Template Reference

Socket buffer to be used with std::basic_stream, for easy socket reading and writing. More...

#include <basic_socketbuf.hpp>

Inheritance diagram for claw::net::basic_socketbuf< CharT, Traits >:
claw::net::basic_socket basic_streambuf

Public Types

typedef CharT char_type
 The type of the characters in the stream.
typedef Traits traits_type
 The traits carry some informations about the char_type.
typedef traits_type::int_type int_type
 The type used to represent integers.
typedef traits_type::pos_type pos_type
 The type used to represent a position in the stream.
typedef traits_type::off_type off_type
 The type used to represent a delta in the positions.
typedef basic_socketbuf
< char_type, traits_type
self_type
 The type of this implementation.

Public Member Functions

 basic_socketbuf (int read_limit=-1)
 Constructor.
virtual ~basic_socketbuf ()
 Destructor.
self_typeopen (const std::string &addr, int port)
 Initialise the socket.
self_typeopen (socket_traits::descriptor d)
 Link the socket to a file descriptor.
self_typeclose ()
 Close the socket.
bool is_open () const
 Tell if the socket is open.
void set_read_time_limit (int read_limit)
 Set the number of second to wait before considering nothing will come in the socket.

Protected Member Functions

virtual int sync ()
 Write the buffered data in the socket.
virtual int_type underflow ()
 Fill the input buffer.
virtual int_type overflow (int_type c=traits_type::eof())
 Synchronize the output buffer (ie. write in the socket).

Additional Inherited Members

- Private Member Functions inherited from claw::net::basic_socket
 basic_socket ()
 Constructor.
basic_socketopen ()
 Open the socket.
basic_socketclose ()
 Close the socket.
bool is_open () const
 Tell if the socket is open.

Detailed Description

template<typename CharT, typename Traits>
class claw::net::basic_socketbuf< CharT, Traits >

Socket buffer to be used with std::basic_stream, for easy socket reading and writing.

Author
Julien Jorge

Definition at line 48 of file basic_socketbuf.hpp.

Constructor & Destructor Documentation

template<typename CharT , typename Traits >
claw::net::basic_socketbuf< CharT, Traits >::basic_socketbuf ( int  read_limit = -1)

Constructor.

Parameters
read_limitNumber of second to wait before considering nothing will come in the socket. Negative values mean infinity.
Postcondition
is_open() == false;

Definition at line 44 of file basic_socketbuf.tpp.

Member Function Documentation

template<typename CharT , typename Traits >
claw::net::basic_socketbuf< CharT, Traits >::self_type * claw::net::basic_socketbuf< CharT, Traits >::close ( )

Close the socket.

Postcondition
is_open() == false;

Definition at line 130 of file basic_socketbuf.tpp.

References claw::net::basic_socket::close().

template<typename CharT , typename Traits >
claw::net::basic_socketbuf< CharT, Traits >::self_type * claw::net::basic_socketbuf< CharT, Traits >::open ( const std::string &  address,
int  port 
)

Initialise the socket.

Parameters
addressAddress to open.
portThe port to connect to.
Returns
this if everything works fine, NULL otherwise.

Definition at line 72 of file basic_socketbuf.tpp.

References claw::net::basic_socket::open().

template<typename CharT , typename Traits >
claw::net::basic_socketbuf< CharT, Traits >::self_type * claw::net::basic_socketbuf< CharT, Traits >::open ( socket_traits::descriptor  d)

Link the socket to a file descriptor.

Parameters
dThe file descriptor.
Returns
this if everything works fine, NULL otherwise.
Remarks
This method should be only called by claw::net::basic_*socket_stream.
If this socket was open and fd is valid, the socket will be closed before that d will be assigned.

Definition at line 99 of file basic_socketbuf.tpp.

References claw::socket_traits_unix::is_open().

template<typename CharT , typename Traits >
claw::net::basic_socketbuf< CharT, Traits >::int_type claw::net::basic_socketbuf< CharT, Traits >::overflow ( int_type  c = traits_type::eof())
protectedvirtual

Synchronize the output buffer (ie. write in the socket).

Parameters
c

Definition at line 234 of file basic_socketbuf.tpp.

References CLAW_PRECOND.

template<typename CharT , typename Traits >
void claw::net::basic_socketbuf< CharT, Traits >::set_read_time_limit ( int  read_limit)

Set the number of second to wait before considering nothing will come in the socket.

Parameters
read_limitThe number of seconds. Negative values mean infinity.

Definition at line 156 of file basic_socketbuf.tpp.

template<typename CharT , typename Traits >
int claw::net::basic_socketbuf< CharT, Traits >::sync ( )
protectedvirtual

Write the buffered data in the socket.

Precondition
is_open()

Definition at line 167 of file basic_socketbuf.tpp.

References CLAW_PRECOND.

template<typename CharT , typename Traits >
claw::net::basic_socketbuf< CharT, Traits >::int_type claw::net::basic_socketbuf< CharT, Traits >::underflow ( )
protectedvirtual

Fill the input buffer.

Precondition
is_open() && gptr() != NULL
Returns
The next symbol to be read ( *gptr() ) if there is data coming from the socket, traits::eof() otherwise.

Definition at line 197 of file basic_socketbuf.tpp.

References CLAW_PRECOND, and claw::socket_traits_unix::select_read().


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