join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicStreamSocket< Protocol > Class Template Reference

basic stream socket class. More...

#include <socket.hpp>

Inheritance diagram for join::BasicStreamSocket< Protocol >:
Collaboration diagram for join::BasicStreamSocket< Protocol >:

Public Types

using Ptr = std::unique_ptr <BasicStreamSocket <Protocol>>
 
using Mode = typename BasicDatagramSocket <Protocol>::Mode
 
using Option = typename BasicDatagramSocket <Protocol>::Option
 
using State = typename BasicDatagramSocket <Protocol>::State
 
using Endpoint = typename Protocol::Endpoint
 
- Public Types inherited from join::BasicDatagramSocket< Protocol >
using Ptr = std::unique_ptr <BasicDatagramSocket <Protocol>>
 
using Mode = typename BasicSocket <Protocol>::Mode
 
using Option = typename BasicSocket <Protocol>::Option
 
using State = typename BasicSocket <Protocol>::State
 
using Endpoint = typename Protocol::Endpoint
 
- Public Types inherited from join::BasicSocket< Protocol >
enum  Mode { Blocking , NonBlocking }
 socket modes. More...
 
enum  Option {
  NoDelay , KeepAlive , KeepIdle , KeepIntvl ,
  KeepCount , SndBuffer , RcvBuffer , TimeStamp ,
  ReuseAddr , ReusePort , Broadcast , Ttl ,
  MulticastLoop , MulticastTtl , PathMtuDiscover , RcvError ,
  AuxData
}
 socket options. More...
 
enum  State {
  Connecting , Connected , Disconnecting , Disconnected ,
  Closed
}
 socket states. More...
 
using Ptr = std::unique_ptr <BasicSocket <Protocol>>
 
using Endpoint = typename Protocol::Endpoint
 

Public Member Functions

 BasicStreamSocket ()
 default constructor.
 
 BasicStreamSocket (Mode mode)
 create instance specifying the mode.
 
 BasicStreamSocket (const BasicStreamSocket &other)=delete
 copy constructor.
 
BasicStreamSocketoperator= (const BasicStreamSocket &other)=delete
 copy assignment operator.
 
 BasicStreamSocket (BasicStreamSocket &&other)
 move constructor.
 
BasicStreamSocketoperator= (BasicStreamSocket &&other)
 move assignment operator.
 
virtual ~BasicStreamSocket ()=default
 destroy the instance.
 
virtual bool waitConnected (int timeout=0)
 block until connected.
 
virtual int disconnect () override
 shutdown the connection.
 
virtual bool waitDisconnected (int timeout=0)
 wait until the connection as been shut down.
 
int readExactly (char *data, unsigned long size, int timeout=0)
 read data until size is reached or an error occurred.
 
int readExactly (std::string &data, unsigned long size, int timeout=0)
 read data until size is reached or an error occurred.
 
int writeExactly (const char *data, unsigned long size, int timeout=0)
 write data until size is reached or an error occurred.
 
virtual int setOption (Option option, int value) noexcept override
 set the given option to the given value.
 
virtual bool connecting () const noexcept
 check if the socket is connecting.
 
virtual bool connected () noexcept override
 check if the socket is connected.
 
- Public Member Functions inherited from join::BasicDatagramSocket< Protocol >
 BasicDatagramSocket (int ttl=60)
 Default constructor.
 
 BasicDatagramSocket (Mode mode, int ttl=60)
 Create instance specifying the mode.
 
 BasicDatagramSocket (const BasicDatagramSocket &other)=delete
 Copy constructor.
 
BasicDatagramSocketoperator= (const BasicDatagramSocket &other)=delete
 Copy assignment operator.
 
 BasicDatagramSocket (BasicDatagramSocket &&other)
 Move constructor.
 
BasicDatagramSocketoperator= (BasicDatagramSocket &&other)
 Move assignment operator.
 
virtual ~BasicDatagramSocket ()=default
 Destroy the instance.
 
virtual int open (const Protocol &protocol=Protocol()) noexcept override
 open socket using the given protocol.
 
virtual int bindToDevice (const std::string &device) noexcept
 assigns the specified device to the socket.
 
virtual int connect (const Endpoint &endpoint)
 make a connection to the given endpoint.
 
virtual void close () noexcept override
 close the socket handle.
 
virtual int read (char *data, unsigned long maxSize) noexcept override
 read data.
 
virtual int readFrom (char *data, unsigned long maxSize, Endpoint *endpoint=nullptr) noexcept
 read data on the socket.
 
virtual int write (const char *data, unsigned long maxSize) noexcept override
 write data.
 
virtual int writeTo (const char *data, unsigned long maxSize, const Endpoint &endpoint) noexcept
 write data on the socket.
 
const EndpointremoteEndpoint () const
 determine the remote endpoint associated with this socket.
 
int mtu () const
 get socket mtu.
 
int ttl () const
 returns the Time-To-Live value.
 
- Public Member Functions inherited from join::BasicSocket< Protocol >
 BasicSocket ()
 default constructor.
 
 BasicSocket (Mode mode)
 create socket instance specifying the mode.
 
 BasicSocket (const BasicSocket &other)=delete
 copy constructor.
 
BasicSocketoperator= (const BasicSocket &other)=delete
 copy assignment operator.
 
 BasicSocket (BasicSocket &&other)
 move constructor.
 
BasicSocketoperator= (BasicSocket &&other)
 move assignment operator.
 
virtual ~BasicSocket ()
 destroy the socket instance.
 
virtual int bind (const Endpoint &endpoint) noexcept
 assigns the specified endpoint to the socket.
 
virtual int canRead () const noexcept
 get the number of readable bytes.
 
virtual bool waitReadyRead (int timeout=0) const noexcept
 block until new data is available for reading.
 
virtual bool waitReadyWrite (int timeout=0) const noexcept
 block until at least one byte can be written.
 
void setMode (Mode mode) noexcept
 set the socket to the non-blocking or blocking mode.
 
Endpoint localEndpoint () const
 determine the local endpoint associated with this socket.
 
bool opened () const noexcept
 check if the socket is opened.
 
virtual bool encrypted () const noexcept
 check if the socket is secure.
 
int family () const noexcept
 get socket address family.
 
int type () const noexcept
 get the protocol communication semantic.
 
int protocol () const noexcept
 get socket protocol.
 
int handle () const noexcept override
 get socket native handle.
 
- Public Member Functions inherited from join::EventHandler
 EventHandler ()=default
 create instance.
 
virtual ~EventHandler ()=default
 destroy instance.
 

Friends

class BasicStreamAcceptor< Protocol >
 friendship with basic stream acceptor
 

Additional Inherited Members

- Static Public Member Functions inherited from join::BasicSocket< Protocol >
static uint16_t checksum (const uint16_t *data, size_t len, uint16_t current=0)
 get standard 1s complement checksum.
 
- Protected Member Functions inherited from join::BasicSocket< Protocol >
int wait (bool wantRead, bool wantWrite, int timeout) const noexcept
 wait for the socket handle to become ready.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onReceive ()
 method called when data are ready to be read on handle.
 
virtual void onClose ()
 method called when handle is closed.
 
virtual void onError ()
 method called when an error occured on handle.
 
- Protected Attributes inherited from join::BasicDatagramSocket< Protocol >
Endpoint _remote
 remote endpoint.
 
int _ttl = 60
 packet time to live.
 
- Protected Attributes inherited from join::BasicSocket< Protocol >
State _state = State::Closed
 socket state.
 
Mode _mode = Mode::NonBlocking
 socket mode.
 
int _handle = -1
 socket handle.
 
Protocol _protocol
 protocol.
 

Detailed Description

template<class Protocol>
class join::BasicStreamSocket< Protocol >

basic stream socket class.

Member Typedef Documentation

◆ Endpoint

template<class Protocol >
using join::BasicStreamSocket< Protocol >::Endpoint = typename Protocol::Endpoint

◆ Mode

template<class Protocol >
using join::BasicStreamSocket< Protocol >::Mode = typename BasicDatagramSocket <Protocol>::Mode

◆ Option

template<class Protocol >
using join::BasicStreamSocket< Protocol >::Option = typename BasicDatagramSocket <Protocol>::Option

◆ Ptr

template<class Protocol >
using join::BasicStreamSocket< Protocol >::Ptr = std::unique_ptr <BasicStreamSocket <Protocol>>

◆ State

template<class Protocol >
using join::BasicStreamSocket< Protocol >::State = typename BasicDatagramSocket <Protocol>::State

Constructor & Destructor Documentation

◆ BasicStreamSocket() [1/4]

template<class Protocol >
join::BasicStreamSocket< Protocol >::BasicStreamSocket ( )
inline

default constructor.

◆ BasicStreamSocket() [2/4]

template<class Protocol >
join::BasicStreamSocket< Protocol >::BasicStreamSocket ( Mode mode)
inline

create instance specifying the mode.

Parameters
modeSet the socket blocking mode.

◆ BasicStreamSocket() [3/4]

template<class Protocol >
join::BasicStreamSocket< Protocol >::BasicStreamSocket ( const BasicStreamSocket< Protocol > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicStreamSocket() [4/4]

template<class Protocol >
join::BasicStreamSocket< Protocol >::BasicStreamSocket ( BasicStreamSocket< Protocol > && other)
inline

move constructor.

Parameters
otherother object to move.

◆ ~BasicStreamSocket()

template<class Protocol >
virtual join::BasicStreamSocket< Protocol >::~BasicStreamSocket ( )
virtualdefault

destroy the instance.

Member Function Documentation

◆ connected()

template<class Protocol >
virtual bool join::BasicStreamSocket< Protocol >::connected ( )
inlineoverridevirtualnoexcept

check if the socket is connected.

Returns
true if connected, false otherwise.

Reimplemented from join::BasicDatagramSocket< Protocol >.

◆ connecting()

template<class Protocol >
virtual bool join::BasicStreamSocket< Protocol >::connecting ( ) const
inlinevirtualnoexcept

check if the socket is connecting.

Returns
true if connecting, false otherwise.

◆ disconnect()

template<class Protocol >
virtual int join::BasicStreamSocket< Protocol >::disconnect ( )
inlineoverridevirtual

shutdown the connection.

Returns
0 on success, -1 on failure.

Reimplemented from join::BasicDatagramSocket< Protocol >.

Reimplemented in join::BasicTlsSocket< Protocol >.

◆ operator=() [1/2]

template<class Protocol >
BasicStreamSocket & join::BasicStreamSocket< Protocol >::operator= ( BasicStreamSocket< Protocol > && other)
inline

move assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ operator=() [2/2]

template<class Protocol >
BasicStreamSocket & join::BasicStreamSocket< Protocol >::operator= ( const BasicStreamSocket< Protocol > & other)
delete

copy assignment operator.

Parameters
otherother object to assign.
Returns
assigned object.

◆ readExactly() [1/2]

template<class Protocol >
int join::BasicStreamSocket< Protocol >::readExactly ( char * data,
unsigned long size,
int timeout = 0 )
inline

read data until size is reached or an error occurred.

Parameters
databuffer used to store the data received.
sizenumber of bytes to read.
timeouttimeout in milliseconds.
Returns
0 on success, -1 on failure.

◆ readExactly() [2/2]

template<class Protocol >
int join::BasicStreamSocket< Protocol >::readExactly ( std::string & data,
unsigned long size,
int timeout = 0 )
inline

read data until size is reached or an error occurred.

Parameters
databuffer used to store the data received.
sizenumber of bytes to read.
timeouttimeout in milliseconds.
Returns
0 on success, -1 on failure.

◆ setOption()

template<class Protocol >
virtual int join::BasicStreamSocket< Protocol >::setOption ( Option option,
int value )
inlineoverridevirtualnoexcept

set the given option to the given value.

Parameters
optionsocket option.
valueoption value.
Returns
0 on success, -1 on failure.

Reimplemented from join::BasicDatagramSocket< Protocol >.

◆ waitConnected()

template<class Protocol >
virtual bool join::BasicStreamSocket< Protocol >::waitConnected ( int timeout = 0)
inlinevirtual

block until connected.

Parameters
timeouttimeout in milliseconds.
Returns
true if connected, false otherwise.

◆ waitDisconnected()

template<class Protocol >
virtual bool join::BasicStreamSocket< Protocol >::waitDisconnected ( int timeout = 0)
inlinevirtual

wait until the connection as been shut down.

Parameters
timeouttimeout in milliseconds. return true if the connection as been shut down, false otherwise.

◆ writeExactly()

template<class Protocol >
int join::BasicStreamSocket< Protocol >::writeExactly ( const char * data,
unsigned long size,
int timeout = 0 )
inline

write data until size is reached or an error occurred.

Parameters
datadata buffer to send.
sizenumber of bytes to write.
timeouttimeout in milliseconds.
Returns
0 on success, -1 on failure.

Friends And Related Symbol Documentation

◆ BasicStreamAcceptor< Protocol >

template<class Protocol >
friend class BasicStreamAcceptor< Protocol >
friend

friendship with basic stream acceptor


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