Sese Framework
2.3.0
A cross-platform framework
|
#include <Socket.h>
Public Types | |
enum class | Type { TCP = SOCK_STREAM , UDP = SOCK_DGRAM } |
Socket type. More... | |
enum class | Family { IPv4 = AF_INET , IPv6 = AF_INET6 } |
Address family. More... | |
enum class | ShutdownMode { READ = SHUT_RD , WRITE = SHUT_WR , BOTH = SHUT_RDWR } |
Shutdown mode. More... | |
using | Ptr = std::shared_ptr<Socket> |
Public Types inherited from sese::io::Stream | |
typedef std::shared_ptr< Stream > | Ptr |
Public Types inherited from sese::io::InputStream | |
typedef std::shared_ptr< InputStream > | Ptr |
Public Types inherited from sese::io::OutputStream | |
typedef std::shared_ptr< OutputStream > | Ptr |
Public Types inherited from sese::io::PeekableStream | |
typedef std::shared_ptr< PeekableStream > | Ptr |
Public Member Functions | |
Socket (Family family, Type type, int32_t protocol=IPPROTO_IP) noexcept | |
Socket (socket_t handle, Address::Ptr address) noexcept | |
~Socket () noexcept override | |
virtual int32_t | bind (Address::Ptr address) noexcept |
virtual int32_t | connect (Address::Ptr address) noexcept |
virtual int32_t | listen (int32_t backlog) const noexcept |
virtual Socket::Ptr | accept () const |
virtual int32_t | shutdown (ShutdownMode mode) const |
bool | setNonblocking () const noexcept |
int64_t | read (void *buffer, size_t length) override |
int64_t | write (const void *buffer, size_t length) override |
int64_t | send (void *buffer, size_t length, const IPAddress::Ptr &to, int32_t flags) const |
int64_t | recv (void *buffer, size_t length, const IPAddress::Ptr &from, int32_t flags) const |
int64_t | peek (void *buffer, size_t length) override |
int64_t | trunc (size_t length) override |
int64_t | writeInt16 (int16_t value) |
int64_t | writeInt32 (int32_t value) |
int64_t | writeInt64 (int64_t value) |
int64_t | writeUint16 (uint16_t value) |
int64_t | writeUint32 (uint32_t value) |
int64_t | writeUint64 (uint64_t value) |
int64_t | readInt16 (int16_t &value) |
int64_t | readInt32 (int32_t &value) |
int64_t | readInt64 (int64_t &value) |
int64_t | readUint16 (uint16_t &value) |
int64_t | readUint32 (uint32_t &value) |
int64_t | readUint64 (uint64_t &value) |
void | close () override |
const socket_t & | getRawSocket () const |
const Address::Ptr & | getAddress () const |
Public Member Functions inherited from sese::io::InputStream | |
virtual | ~InputStream () noexcept=default |
Public Member Functions inherited from sese::io::OutputStream | |
virtual | ~OutputStream () noexcept=default |
int64_t | write (const std::string_view &buffer) |
int64_t | write (const text::StringView &buffer) |
template<typename T > | |
int64_t | write (std::vector< T > &buffer) |
template<typename T , size_t N> | |
int64_t | write (std::array< T, N > &buffer) |
Public Member Functions inherited from sese::io::PeekableStream | |
virtual | ~PeekableStream ()=default |
Public Member Functions inherited from sese::io::Closeable | |
virtual | ~Closeable ()=default |
Static Public Member Functions | |
static socket_t | socket (int family, int type, int protocol) noexcept |
static int | bind (socket_t socket, const sockaddr *addr, socklen_t addr_len) noexcept |
static socket_t | accept (socket_t socket, sockaddr *addr=nullptr, socklen_t *len=nullptr) noexcept |
static int | connect (socket_t socket, const sockaddr *addr, socklen_t addr_len) noexcept |
static int64_t | write (socket_t socket, const void *buffer, size_t len, int flags) noexcept |
static int64_t | read (socket_t socket, void *buffer, size_t len, int flags) noexcept |
static int | listen (socket_t socket, int backlog) noexcept |
static int | setNonblocking (socket_t socket) noexcept |
static void | close (socket_t socket) noexcept |
static int | shutdown (socket_t socket, ShutdownMode mode) noexcept |
Private Attributes | |
socket_t | handle {} |
Address::Ptr | address |
Native Socket class.
using sese::net::Socket::Ptr = std::shared_ptr<Socket> |
|
strong |
Address family.
Enumerator | |
---|---|
IPv4 | IPv4. |
IPv6 | IPv6. |
|
strong |
|
strong |
Socket type.
Enumerator | |
---|---|
TCP | TCP socket. |
UDP | UDP socket. |
|
noexcept |
|
overridenoexcept |
|
nodiscardvirtual |
Reimplemented in sese::security::SecuritySocket.
References accept(), address, sese::net::Address::create(), sese::net::Address::getRawAddress(), handle, and MAKE_SHARED_PRIVATE.
Referenced by accept().
|
staticnoexcept |
|
virtualnoexcept |
|
staticnoexcept |
|
overridevirtual |
Implements sese::io::Closeable.
References close(), and handle.
Referenced by sese::security::SecuritySocket::accept(), sese::_windows::iocp::v1::NativeIOCPServer::acceptThreadProc(), close(), sese::_windows::iocp::v1::NativeIOCPServer::init(), sese::service::SystemBalanceLoader::init(), sese::_windows::iocp::v1::NativeIOCPServer::initConnectEx(), sese::iocp::v1::IOCPService::onAccept(), sese::service::TcpTransporter::onAccept(), sese::service::TcpTransporter::onClose(), sese::service::TcpTransporter::onRead(), sese::service::TcpTransporter::onTimeout(), sese::service::TcpTransporter::onWrite(), sese::_windows::iocp::v1::NativeIOCPServer::releaseContext(), sese::iocp::v1::IOCPService::releaseContext(), sese::_windows::iocp::v1::NativeIOCPServer::shutdown(), sese::service::SystemBalanceLoader::stop(), sese::service::UserBalanceLoader::stop(), sese::iocp::v1::IOCPService::~IOCPService(), sese::service::SystemBalanceLoader::~SystemBalanceLoader(), sese::service::TcpTransporter::~TcpTransporter(), and sese::service::UserBalanceLoader::~UserBalanceLoader().
|
virtualnoexcept |
Reimplemented in sese::security::SecuritySocket.
References EALREADY, EINPROGRESS, EISCONN, EWOULDBLOCK, sese::net::getNetworkError(), and sese::sleep().
|
staticnoexcept |
|
inlinenodiscard |
|
inlinenodiscard |
Referenced by sese::security::SecuritySocket::accept().
|
virtualnoexcept |
|
staticnoexcept |
|
overridevirtual |
Read content without stepping
buffer | Buffer |
length | Buffer size |
Implements sese::io::PeekableStream.
References handle.
|
staticnoexcept |
|
overridevirtual |
TCP receive bytes
buffer | Buffer |
length | Buffer size |
Implements sese::io::InputStream.
References handle.
Referenced by sese::iocp::v1::IOCPService::read(), and sese::service::TcpTransporter::read().
|
inline |
References FromBigEndian16(), and R.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
int64_t Socket::recv | ( | void * | buffer, |
size_t | length, | ||
const IPAddress::Ptr & | from, | ||
int32_t | flags ) const |
UDP receive bytes
buffer | Buffer |
length | Buffer size |
from | Source address |
flags | Flags |
References sese::net::Address::getRawAddress(), sese::net::Address::getRawAddressLength(), and handle.
int64_t Socket::send | ( | void * | buffer, |
size_t | length, | ||
const IPAddress::Ptr & | to, | ||
int32_t | flags ) const |
UDP send bytes
buffer | Buffer |
length | Buffer size |
to | Destination address |
flags | Flags |
References sese::net::Address::getRawAddress(), sese::net::Address::getRawAddressLength(), and handle.
|
noexcept |
References handle.
Referenced by sese::_windows::iocp::v1::NativeIOCPServer::acceptThreadProc(), sese::_windows::iocp::v1::NativeIOCPServer::init(), sese::service::SystemBalanceLoader::init(), sese::iocp::v1::IOCPService::onAccept(), sese::service::TcpTransporter::onAccept(), sese::_windows::iocp::v1::NativeIOCPServer::postConnect(), and sese::iocp::v1::IOCPServer::postConnect().
|
staticnoexcept |
|
virtual |
Reimplemented in sese::security::SecuritySocket.
References handle.
|
staticnoexcept |
|
staticnoexcept |
|
overridevirtual |
Step only, without reading content
length | Step size |
Implements sese::io::PeekableStream.
References handle.
|
overridevirtual |
TCP send bytes
buffer | Buffer |
length | Buffer size |
Implements sese::io::OutputStream.
References handle.
Referenced by sese::iocp::v1::IOCPService::write(), and sese::service::TcpTransporter::write().
|
staticnoexcept |
|
inline |
References ToBigEndian16(), and W.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
Referenced by accept().
|
private |
Referenced by accept(), close(), peek(), read(), recv(), send(), setNonblocking(), shutdown(), trunc(), and write().