sptk2 logo
SPTK Home Page
Public Member Functions | List of all members
sptk::UDPSocket Class Reference

#include <UDPSocket.h>

Inheritance diagram for sptk::UDPSocket:
sptk::BaseSocket

Public Member Functions

 UDPSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET)
 
 ~UDPSocket () override=default
 
size_t read (uint8_t *buffer, size_t size, sockaddr_in *from=nullptr) override
 
size_t read (Buffer &buffer, size_t size, sockaddr_in *from=nullptr) override
 
size_t read (String &buffer, size_t size, sockaddr_in *from=nullptr) override
 
- Public Member Functions inherited from sptk::BaseSocket
SOCKET fd () const
 
void open_addr (OpenMode openMode=OpenMode::CREATE, const sockaddr_in *addr=nullptr, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
 
 BaseSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0)
 
 BaseSocket (const BaseSocket &other)=delete
 
 BaseSocket (BaseSocket &&other) noexcept=default
 
virtual ~BaseSocket ()
 Destructor.
 
BaseSocketoperator= (const BaseSocket &other)=delete
 
BaseSocketoperator= (BaseSocket &&other) noexcept=default
 
void blockingMode (bool blocking)
 
virtual size_t socketBytes ()
 
virtual void attach (SOCKET socketHandle, bool accept)
 
virtual SOCKET detach ()
 
void host (const Host &host)
 
const Hosthost () const
 
void open (const Host &host=Host(), OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0))
 
void open (const struct sockaddr_in &address, OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0))
 
void bind (const char *address, uint32_t portNumber)
 
void listen (uint16_t portNumber=0)
 
virtual void close () noexcept
 
bool active () const
 
int32_t control (int flag, const uint32_t *check) const
 
void setOption (int level, int option, int value) const
 
void getOption (int level, int option, int &value) const
 
virtual size_t recv (uint8_t *buffer, size_t len)
 
virtual size_t send (const uint8_t *buffer, size_t len)
 
virtual size_t read (uint8_t *buffer, size_t size, sockaddr_in *from)
 
virtual size_t read (uint8_t *buffer, size_t size)
 
virtual size_t read (Buffer &buffer, size_t size, sockaddr_in *from)
 
size_t read (Buffer &buffer, size_t size)
 
virtual size_t read (String &buffer, size_t size, sockaddr_in *from)
 
size_t read (String &buffer, size_t size)
 
virtual size_t write (const uint8_t *buffer, size_t size, const sockaddr_in *peer)
 
size_t write (const uint8_t *buffer, size_t size)
 
virtual size_t write (const Buffer &buffer, const sockaddr_in *peer)
 
size_t write (const Buffer &buffer)
 
virtual size_t write (const String &buffer, const sockaddr_in *peer)
 
size_t write (const String &buffer)
 
virtual bool readyToRead (std::chrono::milliseconds timeout)
 
virtual bool readyToWrite (std::chrono::milliseconds timeout)
 
bool blockingMode () const
 Return current blocking mode state. More...
 

Additional Inherited Members

- Public Types inherited from sptk::BaseSocket
enum class  OpenMode : uint8_t { CREATE , CONNECT , BIND }
 
- Protected Member Functions inherited from sptk::BaseSocket
void setSocketFD (SOCKET socket)
 
int32_t domain () const
 
int32_t type () const
 
int32_t protocol () const
 
virtual void _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS)
 
virtual void _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS)
 

Detailed Description

UDP Socket

Sends and receives data using UDP protocol. Not buffered. Doesn't use CSocket timeout settings in read and write operations by default.

Constructor & Destructor Documentation

◆ UDPSocket()

sptk::UDPSocket::UDPSocket ( SOCKET_ADDRESS_FAMILY  domain = AF_INET)
explicit

Constructor

Parameters
domainSOCKET_ADDRESS_FAMILY, socket domain type

◆ ~UDPSocket()

sptk::UDPSocket::~UDPSocket ( )
overridedefault

Destructor

Member Function Documentation

◆ read() [1/3]

size_t sptk::UDPSocket::read ( Buffer buffer,
size_t  size,
sockaddr_in *  from = nullptr 
)
overridevirtual

Reads data from the socket

Parameters
bufferThe memory buffer
sizeThe number of bytes to read
fromAn optional structure for source address
Returns
the number of bytes read from the socket

Reimplemented from sptk::BaseSocket.

◆ read() [2/3]

size_t sptk::UDPSocket::read ( String buffer,
size_t  size,
sockaddr_in *  from = nullptr 
)
overridevirtual

Reads data from the socket

Parameters
bufferThe memory buffer
sizeThe number of bytes to read
fromAn optional structure for source address
Returns
the number of bytes read from the socket

Reimplemented from sptk::BaseSocket.

◆ read() [3/3]

size_t sptk::UDPSocket::read ( uint8_t *  buffer,
size_t  size,
sockaddr_in *  from = nullptr 
)
overridevirtual

Reads data from the socket

Parameters
bufferThe memory buffer
sizeThe number of bytes to read
fromAn optional structure for source address
Returns
the number of bytes read from the socket

Reimplemented from sptk::BaseSocket.


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

Fri Oct 14 2022 09:58:47: SPTK 5.4.1