Wrapper class around lwip implementation of a socket. More...

#include <mn_basic_socket.hpp>

+ Inheritance diagram for mn::net::basic_ip_socket:

Public Types

using handle_type = int
 

Public Member Functions

 basic_ip_socket (const handle_type &hndl) noexcept
 construtor from a raw handle More...
 
 basic_ip_socket (const address_family &fam, const socket_type &type, const protocol_type &protocol) noexcept
 construtor create the socket More...
 
 basic_ip_socket (const basic_ip_socket &other) noexcept
 copy construtor More...
 
virtual ~basic_ip_socket () noexcept
 deconstrutor, close the socket More...
 
virtual bool open ()
 Open the socket - only used when the socket not initialized. More...
 
virtual void close ()
 
virtual int available ()
 Returns the number of bytes available that can be read without causing the socket to block. More...
 
virtual void reset (const handle_type &hnd=MNTHREAD_NET_INVALID_SOCKET, bool bClosed=false)
 Reset the socket. More...
 
virtual bool initialized ()
 If the socket initialized. More...
 
int get_last_error (bool poolLast=true)
 Get the saved copy of the last lwip error code. More...
 
int get_handle ()
 Get the raw socket handle. More...
 
virtual basic_ip_socketget_copy ()=0
 Get a copy of the socket wrapper (abstarct) More...
 
basic_ip_socketoperator= (const basic_ip_socket &other)
 
virtual void swap (basic_ip_socket &rhs) noexcept
 
void shutdown (const socket_shutdown_type &cmd)
 send shutdown More...
 
bool poll (const unsigned long &timeout, int mode)
 poll the socket More...
 
void set_reuse_address (bool flag)
 Set the option socket_option_name::reuse_addr. More...
 
void set_rause_port (bool flag)
 Set the option socket_option_name::reuse_port. More...
 
void set_linger (bool on, int seconds)
 Set the option socket_option_name::linger. More...
 
void set_no_delay (bool flag)
 Set the option socket_option_name::tcp_nodelay. More...
 
void set_keep_alive (bool flag)
 Set the option socket_option_name::keepalive. More...
 
void set_oob_inline (bool flag)
 Set the option socket_option_name::oob_inline. More...
 
void set_blocking (bool flag)
 Set the socket for bloking. More...
 
void set_nocheak (bool value)
 Set the option socket_option_name::no_check. More...
 
void set_send_buffer_size (int value)
 Set the size of the send buffer. More...
 
void set_recive_buffer_size (int value)
 Set the size of the recive buffer. More...
 
void set_send_timeout (int value)
 Set the option socket_option_name::send_timeout. More...
 
void set_recive_timeout (int value)
 Set the option socket_option_name::recive_timeout. More...
 
bool get_reuse_address ()
 Get the value of the option socket_option_name::reuse_addr. More...
 
bool get_rause_port ()
 Get the value of the option socket_option_name::reuse_port. More...
 
void get_linger (bool &on, int &seconds)
 Get the value of the option socket_option_name::linger. More...
 
bool get_no_delay ()
 Get the value of the option socket_option_name::no_delay. More...
 
bool get_keep_alive ()
 Get the value of the option socket_option_name::keepalive. More...
 
bool get_oob_inline ()
 Get the value of the option socket_option_name::oob_inline. More...
 
bool get_nocheak ()
 Get the value of the option socket_option_name::no_check. More...
 
bool get_blocking ()
 Is the socket blocking enabled. More...
 
int get_send_buffer_size ()
 Get the size of the send buffer. More...
 
int get_recive_buffer_size ()
 Get the size of the recive buffer. More...
 
int get_send_timeout ()
 Set the option socket_option_name::send_timeout. More...
 
int get_recive_timeout ()
 Set the option socket_option_name::recive_timeout. More...
 
int set_options (const socket_option_level &opt, const socket_option_name &name, int value)
 Sets the socket option specified by level and option to the given integer value. More...
 
int set_options (const socket_option_level &opt, const socket_option_name &name, unsigned int value)
 Sets the socket option specified by level and option to the given integer value. More...
 
int set_options (const socket_option_level &opt, const socket_option_name &name, basic_ip4_address value)
 Sets the socket option specified by level and option to the given integer value. More...
 
int set_options (const socket_option_level &opt, const socket_option_name &name, basic_ip6_address value)
 Sets the socket option specified by level and option to the given integer value. More...
 
int set_options (const socket_option_level &opt, const socket_option_name &name, bool value)
 Set a given option, version for boolen values. More...
 
int set_options (const socket_option_level &opt, const socket_option_name &name, void *value, uint32_t size)
 Set a given option, version for data. More...
 
int get_option_int (const socket_option_level &opt, const socket_option_name &name)
 Get a interger value of a given option. More...
 
bool get_option_bool (const socket_option_level &opt, const socket_option_name &name)
 Get a booles value of a given option. More...
 
int get_option_raw (const socket_option_level &opt, const socket_option_name &name, void *value, uint32_t size)
 Get a buffer value of a given option. More...
 
int ioctl (const ioctl_request_type &request, int &arg)
 A wrapper for the ioctl system call. More...
 
int ioctl (const ioctl_request_type &request, void *arg)
 A wrapper for the ioctl system call. More...
 
int set_fcntl (int arg)
 A wrapper for the fcntl system call. More...
 
int get_fcntl ()
 A wrapper for the fcntl system call. More...
 

Protected Member Functions

virtual bool open (const address_family &fam, const socket_type &type, const protocol_type &protocol)
 Open the socket - only used when the socket not initialized. More...
 

Protected Attributes

handle_type m_iHandle
 Reference to the underlying socket handle for this socket. More...
 
address_family m_eFam
 A saved / cached copy of the address family type of this socket. More...
 
socket_type m_eType
 A saved / cached copy of the socket type of this socket. More...
 
protocol_type m_eProtocol
 A saved / cached copy of the protocal type of this socket. More...
 
bool m_bBlocked
 A saved / cached copy of a blocked flag. More...
 

Detailed Description

Wrapper class around lwip implementation of a socket.

Note
To use this, you need to subclass it. All of your ip sockets should be derived from the basic_ip_socket class. Then implement the virtual get_copy function.
Author
Amber-Sophia Schröck

Member Typedef Documentation

◆ handle_type

Constructor & Destructor Documentation

◆ basic_ip_socket() [1/3]

mn::net::basic_ip_socket::basic_ip_socket ( const handle_type hndl)
explicitnoexcept

construtor from a raw handle

Parameters
hndlThe raw handle

◆ basic_ip_socket() [2/3]

mn::net::basic_ip_socket::basic_ip_socket ( const address_family fam,
const socket_type type,
const protocol_type protocol 
)
noexcept

construtor create the socket

Parameters
famThe address family for the creating socket
typeThe type for the creating socket
protocolThe protocol for the creating socket

◆ basic_ip_socket() [3/3]

mn::net::basic_ip_socket::basic_ip_socket ( const basic_ip_socket other)
noexcept

copy construtor

◆ ~basic_ip_socket()

mn::net::basic_ip_socket::~basic_ip_socket ( )
virtualnoexcept

deconstrutor, close the socket

Member Function Documentation

◆ available()

int mn::net::basic_ip_socket::available ( )
virtual

Returns the number of bytes available that can be read without causing the socket to block.

Returns
The number of bytes are available in the buffer.

◆ close()

virtual void mn::net::basic_ip_socket::close ( )
inlinevirtual

Close and destroy the socket

◆ get_blocking()

bool mn::net::basic_ip_socket::get_blocking ( )
inline

Is the socket blocking enabled.

Returns
If true then blocking and if false when not

◆ get_copy()

virtual basic_ip_socket* mn::net::basic_ip_socket::get_copy ( )
pure virtual

Get a copy of the socket wrapper (abstarct)

Returns
The copy

Implemented in mn::net::basic_raw_ip6_socket, mn::net::basic_raw_ip4_socket, mn::net::basic_ip6_socket, and mn::net::basic_ip4_socket.

◆ get_fcntl()

int mn::net::basic_ip_socket::get_fcntl ( )

A wrapper for the fcntl system call.

◆ get_handle()

int mn::net::basic_ip_socket::get_handle ( )
inline

Get the raw socket handle.

Returns
The raw socket handle.

◆ get_keep_alive()

bool mn::net::basic_ip_socket::get_keep_alive ( )

Get the value of the option socket_option_name::keepalive.

Returns
The value of the option socket_option_name::keepalive

◆ get_last_error()

int mn::net::basic_ip_socket::get_last_error ( bool  poolLast = true)

Get the saved copy of the last lwip error code.

Note
Attentions the error codes are decode in raw socket type, not in ERR_XX_XXXX error types
Parameters
poolLastIf this flag true then get the last error from the Socket API, if false then get the last saved error from m_iLastError
Returns
The saved copy of the last lwip error code

◆ get_linger()

void mn::net::basic_ip_socket::get_linger ( bool &  on,
int &  seconds 
)

Get the value of the option socket_option_name::linger.

Parameters
[out]onif true then is the option enable and false when not
[out]secondsThe setted seconds

◆ get_no_delay()

bool mn::net::basic_ip_socket::get_no_delay ( )

Get the value of the option socket_option_name::no_delay.

Returns
The value of the option socket_option_name::no_delay

◆ get_nocheak()

bool mn::net::basic_ip_socket::get_nocheak ( )

Get the value of the option socket_option_name::no_check.

Returns
If true then Is the socket set as blocked and if false when not

◆ get_oob_inline()

bool mn::net::basic_ip_socket::get_oob_inline ( )

Get the value of the option socket_option_name::oob_inline.

Returns
The value of the option socket_option_name::oob_inline

◆ get_option_bool()

bool mn::net::basic_ip_socket::get_option_bool ( const socket_option_level opt,
const socket_option_name name 
)

Get a booles value of a given option.

Parameters
optThe socket option level
nameThe name of the option
Returns
The a boolen value of a given option

◆ get_option_int()

int mn::net::basic_ip_socket::get_option_int ( const socket_option_level opt,
const socket_option_name name 
)

Get a interger value of a given option.

Parameters
optThe socket option level
nameThe name of the option
Returns
The a interger value of a given option

◆ get_option_raw()

int mn::net::basic_ip_socket::get_option_raw ( const socket_option_level opt,
const socket_option_name name,
void *  value,
uint32_t  size 
)

Get a buffer value of a given option.

Parameters
optThe socket option level
nameThe name of the option
[out]valueContains the return of the given options, null when error
sizeThe size of the value

◆ get_rause_port()

bool mn::net::basic_ip_socket::get_rause_port ( )

Get the value of the option socket_option_name::reuse_port.

Returns
The value of the option socket_option_name::reuse_port

◆ get_recive_buffer_size()

int mn::net::basic_ip_socket::get_recive_buffer_size ( )

Get the size of the recive buffer.

Returns
The size of the buffer in bytes

◆ get_recive_timeout()

int mn::net::basic_ip_socket::get_recive_timeout ( )

Set the option socket_option_name::recive_timeout.

Returns
The millis for the option in millis

◆ get_reuse_address()

bool mn::net::basic_ip_socket::get_reuse_address ( )

Get the value of the option socket_option_name::reuse_addr.

Returns
The value of the option socket_option_name::reuse_addr

◆ get_send_buffer_size()

int mn::net::basic_ip_socket::get_send_buffer_size ( )

Get the size of the send buffer.

Returns
The size of the buffer in bytes

◆ get_send_timeout()

int mn::net::basic_ip_socket::get_send_timeout ( )

Set the option socket_option_name::send_timeout.

Returns
The millis for the option in millis

◆ initialized()

bool mn::net::basic_ip_socket::initialized ( )
virtual

If the socket initialized.

Returns
  • True: The socket is initialized
  • False: If not

◆ ioctl() [1/2]

int mn::net::basic_ip_socket::ioctl ( const ioctl_request_type request,
int &  arg 
)

A wrapper for the ioctl system call.

◆ ioctl() [2/2]

int mn::net::basic_ip_socket::ioctl ( const ioctl_request_type request,
void *  arg 
)

A wrapper for the ioctl system call.

◆ open() [1/2]

bool mn::net::basic_ip_socket::open ( )
virtual

Open the socket - only used when the socket not initialized.

Returns
  • True The socket are created
  • False If not

◆ open() [2/2]

bool mn::net::basic_ip_socket::open ( const address_family fam,
const socket_type type,
const protocol_type protocol 
)
protectedvirtual

Open the socket - only used when the socket not initialized.

Parameters
famThe address family for the creating socket
typeThe type for the creating socket
protocolThe protocol for the creating socket
Returns
  • True The socket are created
  • False If not

◆ operator=()

basic_ip_socket & mn::net::basic_ip_socket::operator= ( const basic_ip_socket other)

◆ poll()

bool mn::net::basic_ip_socket::poll ( const unsigned long &  timeout,
int  mode 
)

poll the socket

Parameters
timeoutHow many micros to poll
modepoll mode
Returns
  • true: on success
  • false: if not success

◆ reset()

void mn::net::basic_ip_socket::reset ( const handle_type hnd = MNTHREAD_NET_INVALID_SOCKET,
bool  bClosed = false 
)
virtual

Reset the socket.

Parameters
hndThe new raw socket handle
bClosedIf true and socket initialized then close this socket, after this will set the new handle

◆ set_blocking()

void mn::net::basic_ip_socket::set_blocking ( bool  flag)

Set the socket for bloking.

Parameters
flagIf true then blocking and if false when not

◆ set_fcntl()

int mn::net::basic_ip_socket::set_fcntl ( int  arg)

A wrapper for the fcntl system call.

◆ set_keep_alive()

void mn::net::basic_ip_socket::set_keep_alive ( bool  flag)

Set the option socket_option_name::keepalive.

Parameters
flagif true then enable the option and false when not

◆ set_linger()

void mn::net::basic_ip_socket::set_linger ( bool  on,
int  seconds 
)

Set the option socket_option_name::linger.

Parameters
onif true then enable the option and false when not
secondsSet the seconds are to wait

◆ set_no_delay()

void mn::net::basic_ip_socket::set_no_delay ( bool  flag)

Set the option socket_option_name::tcp_nodelay.

Parameters
flagif true then enable the option and false when not

◆ set_nocheak()

void mn::net::basic_ip_socket::set_nocheak ( bool  value)

Set the option socket_option_name::no_check.

Parameters
flagif true then enable the option and false when not

◆ set_oob_inline()

void mn::net::basic_ip_socket::set_oob_inline ( bool  flag)

Set the option socket_option_name::oob_inline.

Parameters
flagif true then enable the option and false when not

◆ set_options() [1/6]

int mn::net::basic_ip_socket::set_options ( const socket_option_level opt,
const socket_option_name name,
basic_ip4_address  value 
)

Sets the socket option specified by level and option to the given integer value.

Parameters
optThe socket option level
nameThe name of the option
valueThe value for the option
Returns
The socket error code. If 0 then sucess

◆ set_options() [2/6]

int mn::net::basic_ip_socket::set_options ( const socket_option_level opt,
const socket_option_name name,
basic_ip6_address  value 
)

Sets the socket option specified by level and option to the given integer value.

Parameters
optThe socket option level
nameThe name of the option
valueThe value for the option
Returns
The socket error code. If 0 then sucess

◆ set_options() [3/6]

int mn::net::basic_ip_socket::set_options ( const socket_option_level opt,
const socket_option_name name,
bool  value 
)

Set a given option, version for boolen values.

Parameters
optThe socket option level
nameThe name of the option
valueThe value for the option
Returns
The socket error code. If 0 then sucess

◆ set_options() [4/6]

int mn::net::basic_ip_socket::set_options ( const socket_option_level opt,
const socket_option_name name,
int  value 
)

Sets the socket option specified by level and option to the given integer value.

Parameters
optThe socket option level
nameThe name of the option
valueThe value for the option
Returns
The socket error code. If 0 then sucess

◆ set_options() [5/6]

int mn::net::basic_ip_socket::set_options ( const socket_option_level opt,
const socket_option_name name,
unsigned int  value 
)

Sets the socket option specified by level and option to the given integer value.

Parameters
optThe socket option level
nameThe name of the option
valueThe value for the option
Returns
The socket error code. If 0 then sucess

◆ set_options() [6/6]

int mn::net::basic_ip_socket::set_options ( const socket_option_level opt,
const socket_option_name name,
void *  value,
uint32_t  size 
)

Set a given option, version for data.

Parameters
optThe socket option level
nameThe name of the option
valueThe pointer of data for the option
sizeThe size of the pointer
Returns
The socket error code. If 0 then sucess

◆ set_rause_port()

void mn::net::basic_ip_socket::set_rause_port ( bool  flag)

Set the option socket_option_name::reuse_port.

Parameters
flagif true then enable the option and false when not

◆ set_recive_buffer_size()

void mn::net::basic_ip_socket::set_recive_buffer_size ( int  value)

Set the size of the recive buffer.

Parameters
valueThe size of the buffer in bytes

◆ set_recive_timeout()

void mn::net::basic_ip_socket::set_recive_timeout ( int  value)

Set the option socket_option_name::recive_timeout.

Parameters
valueThe value for the option in millis

◆ set_reuse_address()

void mn::net::basic_ip_socket::set_reuse_address ( bool  flag)

Set the option socket_option_name::reuse_addr.

Parameters
flagif true then enable the option and false when not

◆ set_send_buffer_size()

void mn::net::basic_ip_socket::set_send_buffer_size ( int  value)

Set the size of the send buffer.

Parameters
valueThe size of the buffer in bytes

◆ set_send_timeout()

void mn::net::basic_ip_socket::set_send_timeout ( int  value)

Set the option socket_option_name::send_timeout.

Parameters
valueThe value for the option in millis

◆ shutdown()

void mn::net::basic_ip_socket::shutdown ( const socket_shutdown_type cmd)

send shutdown

Parameters
cmdThe type of shutdown

◆ swap()

virtual void mn::net::basic_ip_socket::swap ( basic_ip_socket rhs)
inlinevirtualnoexcept

Member Data Documentation

◆ m_bBlocked

bool mn::net::basic_ip_socket::m_bBlocked
protected

A saved / cached copy of a blocked flag.

◆ m_eFam

address_family mn::net::basic_ip_socket::m_eFam
protected

A saved / cached copy of the address family type of this socket.

◆ m_eProtocol

protocol_type mn::net::basic_ip_socket::m_eProtocol
protected

A saved / cached copy of the protocal type of this socket.

◆ m_eType

socket_type mn::net::basic_ip_socket::m_eType
protected

A saved / cached copy of the socket type of this socket.

◆ m_iHandle

handle_type mn::net::basic_ip_socket::m_iHandle
protected

Reference to the underlying socket handle for this socket.

Note
Can be obtained from get_handle().

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