Public Types | Public Member Functions | Private Attributes

claw::net::basic_socket_stream< CharT, Traits > Class Template Reference

A class to use any socket as a classic standard stream. More...

#include <socket_stream.hpp>

List of all members.

Public Types

typedef CharT char_type
typedef Traits traits_type
typedef traits_type::int_type int_type
typedef traits_type::pos_type pos_type
typedef traits_type::off_type off_type
typedef basic_socketbuf
< char_type, traits_type
buffer_type

Public Member Functions

 basic_socket_stream (int read_delay=-1)
 Constructor.
 basic_socket_stream (const char *address, int port, int read_delay=-1)
 Constructor.
 ~basic_socket_stream ()
 Destructor.
buffer_typerdbuf () const
 Get the buffer.
bool is_open () const
 Tell if the stream 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.
void open (const char *address, int port)
 Connect the socket to an address.
void open (int fd)
 Link the socket to a file descriptor.
void close ()
 Close the connection.

Private Attributes

buffer_type m_buffer
 The buffer used for operations.

Detailed Description

template<typename CharT, typename Traits = std::char_traits<CharT>>
class claw::net::basic_socket_stream< CharT, Traits >

A class to use any socket as a classic standard stream.

Author:
Julien Jorge

Definition at line 45 of file socket_stream.hpp.


Member Typedef Documentation

template<typename CharT, typename Traits = std::char_traits<CharT>>
typedef basic_socketbuf<char_type, traits_type> claw::net::basic_socket_stream< CharT, Traits >::buffer_type

Definition at line 54 of file socket_stream.hpp.

template<typename CharT, typename Traits = std::char_traits<CharT>>
typedef CharT claw::net::basic_socket_stream< CharT, Traits >::char_type

Definition at line 48 of file socket_stream.hpp.

template<typename CharT, typename Traits = std::char_traits<CharT>>
typedef traits_type::int_type claw::net::basic_socket_stream< CharT, Traits >::int_type

Definition at line 50 of file socket_stream.hpp.

template<typename CharT, typename Traits = std::char_traits<CharT>>
typedef traits_type::off_type claw::net::basic_socket_stream< CharT, Traits >::off_type

Definition at line 52 of file socket_stream.hpp.

template<typename CharT, typename Traits = std::char_traits<CharT>>
typedef traits_type::pos_type claw::net::basic_socket_stream< CharT, Traits >::pos_type

Definition at line 51 of file socket_stream.hpp.

template<typename CharT, typename Traits = std::char_traits<CharT>>
typedef Traits claw::net::basic_socket_stream< CharT, Traits >::traits_type

Definition at line 49 of file socket_stream.hpp.


Constructor & Destructor Documentation

template<typename CharT , typename Traits >
claw::net::basic_socket_stream< CharT, Traits >::basic_socket_stream ( int  read_delay = -1 ) [explicit]

Constructor.

Parameters:
read_delayNumber of second to wait before considering nothing will come in the socket. Negative values mean infinity.

Definition at line 39 of file socket_stream.tpp.

  : m_buffer(read_delay)
{
  init(&m_buffer);
} // basic_socket_stream::basic_socket_stream()
template<typename CharT , typename Traits >
claw::net::basic_socket_stream< CharT, Traits >::basic_socket_stream ( const char *  address,
int  port,
int  read_delay = -1 
)

Constructor.

Parameters:
addressThe address to which we will connect.
portThe port number to use for the connection.
read_delayNumber of second to wait before considering nothing will come in the socket. Negative values mean infinity.

Definition at line 55 of file socket_stream.tpp.

  : m_buffer(read_delay)
{
  init(&m_buffer);
  open(address, port);
} // basic_socket_stream::basic_socket_stream()
template<typename CharT , typename Traits >
claw::net::basic_socket_stream< CharT, Traits >::~basic_socket_stream (  )

Destructor.

Definition at line 67 of file socket_stream.tpp.

{
  // nothing to do
} // basic_socket_stream::~basic_socket_stream()

Member Function Documentation

template<typename CharT , typename Traits >
void claw::net::basic_socket_stream< CharT, Traits >::close (  )

Close the connection.

Definition at line 142 of file socket_stream.tpp.

{
  if ( !m_buffer.close() )
    this->setstate(std::ios_base::failbit);
} // basic_socket_stream::close()
template<typename CharT , typename Traits >
bool claw::net::basic_socket_stream< CharT, Traits >::is_open (  ) const

Tell if the stream is open.

Definition at line 88 of file socket_stream.tpp.

{
  return m_buffer.is_open();
} // basic_socket_stream::is_open()
template<typename CharT , typename Traits >
void claw::net::basic_socket_stream< CharT, Traits >::open ( int  fd )

Link the socket to a file descriptor.

Parameters:
fdThe file descriptor.
Remarks:
This method should be only called by claw::net::socket_server.

Definition at line 129 of file socket_stream.tpp.

{
  if ( !m_buffer.open(fd) )
    this->setstate(std::ios_base::failbit);
  else
    this->clear();
} // basic_socket_stream::open()
template<typename CharT , typename Traits >
void claw::net::basic_socket_stream< CharT, Traits >::open ( const char *  address,
int  port 
)

Connect the socket to an address.

Parameters:
addressThe address to which we will connect.
portThe port number to use for the connection.

Definition at line 114 of file socket_stream.tpp.

{
  if ( !m_buffer.open(address, port) )
    this->setstate(std::ios_base::failbit);
  else
    this->clear();
} // basic_socket_stream::open()
template<typename CharT , typename Traits >
claw::net::basic_socket_stream< CharT, Traits >::buffer_type * claw::net::basic_socket_stream< CharT, Traits >::rdbuf (  ) const

Get the buffer.

Definition at line 78 of file socket_stream.tpp.

{
  return const_cast<buffer_type*>(&m_buffer);
} // basic_socket_stream::rdbuf()
template<typename CharT , typename Traits >
void claw::net::basic_socket_stream< 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 101 of file socket_stream.tpp.

{
  m_buffer.set_read_time_limit(read_limit);
} // // basic_socket_stream::set_read_time_limit()

Member Data Documentation

template<typename CharT, typename Traits = std::char_traits<CharT>>
buffer_type claw::net::basic_socket_stream< CharT, Traits >::m_buffer [private]

The buffer used for operations.

Definition at line 73 of file socket_stream.hpp.


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