Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
sese::net::Socket类 参考

Native Socket更多...

#include <Socket.h>

类 sese::net::Socket 继承关系图:
sese::io::Stream sese::io::PeekableStream sese::io::Closeable sese::io::InputStream sese::io::OutputStream sese::security::SecuritySocket

Public 类型

enum class  Type { TCP = SOCK_STREAM , UDP = SOCK_DGRAM }
 套接字类型 更多...
 
enum class  Family { IPv4 = AF_INET , IPv6 = AF_INET6 }
 协议族 更多...
 
enum class  ShutdownMode { READ = SHUT_RD , WRITE = SHUT_WR , BOTH = SHUT_RDWR }
 断开模式 更多...
 
using Ptr = std::shared_ptr<Socket>
 
- Public 类型 继承自 sese::io::Stream
typedef std::shared_ptr< StreamPtr
 
- Public 类型 继承自 sese::io::InputStream
typedef std::shared_ptr< InputStreamPtr
 
- Public 类型 继承自 sese::io::OutputStream
typedef std::shared_ptr< OutputStreamPtr
 
- Public 类型 继承自 sese::io::PeekableStream
typedef std::shared_ptr< PeekableStreamPtr
 

Public 成员函数

 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_tgetRawSocket () const
 
const Address::PtrgetAddress () const
 
- Public 成员函数 继承自 sese::io::InputStream
virtual ~InputStream () noexcept=default
 
- Public 成员函数 继承自 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 成员函数 继承自 sese::io::PeekableStream
virtual ~PeekableStream ()=default
 
- Public 成员函数 继承自 sese::io::Closeable
virtual ~Closeable ()=default
 

静态 Public 成员函数

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 属性

socket_t handle {}
 
Address::Ptr address
 

详细描述

Native Socket

成员类型定义说明

◆ Ptr

using sese::net::Socket::Ptr = std::shared_ptr<Socket>

成员枚举类型说明

◆ Family

enum class sese::net::Socket::Family
strong

协议族

枚举值
IPv4 

IPv4

IPv6 

IPv6

◆ ShutdownMode

断开模式

枚举值
READ 
WRITE 
BOTH 

◆ Type

enum class sese::net::Socket::Type
strong

套接字类型

枚举值
TCP 

TCP 套接字

UDP 

UDP 套接字

构造及析构函数说明

◆ Socket() [1/2]

Socket::Socket ( Family family,
Type type,
int32_t protocol = IPPROTO_IP )
noexcept

◆ Socket() [2/2]

Socket::Socket ( socket_t handle,
Address::Ptr address )
noexcept

◆ ~Socket()

Socket::~Socket ( )
overridenoexcept

成员函数说明

◆ accept() [1/2]

Socket::Ptr Socket::accept ( ) const
nodiscardvirtual

◆ accept() [2/2]

sese::socket_t sese::net::Socket::accept ( socket_t socket,
sockaddr * addr = nullptr,
socklen_t * len = nullptr )
staticnoexcept

◆ bind() [1/2]

int32_t Socket::bind ( Address::Ptr address)
virtualnoexcept

◆ bind() [2/2]

int sese::net::Socket::bind ( socket_t socket,
const sockaddr * addr,
socklen_t addr_len )
staticnoexcept

◆ close() [1/2]

◆ close() [2/2]

void sese::net::Socket::close ( socket_t socket)
staticnoexcept

引用了 close().

◆ connect() [1/2]

int32_t Socket::connect ( Address::Ptr address)
virtualnoexcept

◆ connect() [2/2]

int sese::net::Socket::connect ( socket_t socket,
const sockaddr * addr,
socklen_t addr_len )
staticnoexcept

◆ getAddress()

const Address::Ptr & sese::net::Socket::getAddress ( ) const
inlinenodiscard

◆ getRawSocket()

const socket_t & sese::net::Socket::getRawSocket ( ) const
inlinenodiscard

◆ listen() [1/2]

int32_t Socket::listen ( int32_t backlog) const
virtualnoexcept

◆ listen() [2/2]

int sese::net::Socket::listen ( socket_t socket,
int backlog )
staticnoexcept

◆ peek()

int64_t Socket::peek ( void * buffer,
size_t length )
overridevirtual

仅读取内容,不步进

参数
buffer缓存
length缓存大小
返回
实际读取大小

实现了 sese::io::PeekableStream.

引用了 handle.

◆ read() [1/2]

int64_t sese::net::Socket::read ( socket_t socket,
void * buffer,
size_t len,
int flags )
staticnoexcept

◆ read() [2/2]

int64_t Socket::read ( void * buffer,
size_t length )
overridevirtual

TCP 接收字节

参数
buffer缓存
length缓存大小
返回
实际接收字节数

实现了 sese::io::InputStream.

引用了 handle.

被这些函数引用 sese::iocp::v1::IOCPService::read() , 以及 sese::service::TcpTransporter::read().

◆ readInt16()

int64_t sese::net::Socket::readInt16 ( int16_t & value)
inline

引用了 FromBigEndian16() , 以及 R.

◆ readInt32()

int64_t sese::net::Socket::readInt32 ( int32_t & value)
inline

◆ readInt64()

int64_t sese::net::Socket::readInt64 ( int64_t & value)
inline

◆ readUint16()

int64_t sese::net::Socket::readUint16 ( uint16_t & value)
inline

◆ readUint32()

int64_t sese::net::Socket::readUint32 ( uint32_t & value)
inline

◆ readUint64()

int64_t sese::net::Socket::readUint64 ( uint64_t & value)
inline

◆ recv()

int64_t Socket::recv ( void * buffer,
size_t length,
const IPAddress::Ptr & from,
int32_t flags ) const

UDP 接收字节

参数
buffer缓存
length缓存大小
from来源地址
flags标志
返回
实际接收字节数

引用了 sese::net::Address::getRawAddress(), sese::net::Address::getRawAddressLength() , 以及 handle.

◆ send()

int64_t Socket::send ( void * buffer,
size_t length,
const IPAddress::Ptr & to,
int32_t flags ) const

UDP 发送字节

参数
buffer缓存
length缓存大小
to目标地址
flags标志
返回
实际发送字节数

引用了 sese::net::Address::getRawAddress(), sese::net::Address::getRawAddressLength() , 以及 handle.

◆ setNonblocking() [1/2]

◆ setNonblocking() [2/2]

int sese::net::Socket::setNonblocking ( socket_t socket)
staticnoexcept

◆ shutdown() [1/2]

int32_t Socket::shutdown ( ShutdownMode mode) const
virtual

sese::security::SecuritySocket 重载.

引用了 handle.

◆ shutdown() [2/2]

int sese::net::Socket::shutdown ( sese::socket_t socket,
ShutdownMode mode )
staticnoexcept

◆ socket()

sese::socket_t sese::net::Socket::socket ( int family,
int type,
int protocol )
staticnoexcept

◆ trunc()

int64_t Socket::trunc ( size_t length)
overridevirtual

仅步进,不读取内容

参数
length步进大小
返回
实际步进大小

实现了 sese::io::PeekableStream.

引用了 handle.

◆ write() [1/2]

int64_t Socket::write ( const void * buffer,
size_t length )
overridevirtual

TCP 发送字节

参数
buffer缓存
length缓存大小
返回
实际发送字节数

实现了 sese::io::OutputStream.

引用了 handle.

被这些函数引用 sese::iocp::v1::IOCPService::write() , 以及 sese::service::TcpTransporter::write().

◆ write() [2/2]

int64_t sese::net::Socket::write ( socket_t socket,
const void * buffer,
size_t len,
int flags )
staticnoexcept

◆ writeInt16()

int64_t sese::net::Socket::writeInt16 ( int16_t value)
inline

引用了 ToBigEndian16() , 以及 W.

◆ writeInt32()

int64_t sese::net::Socket::writeInt32 ( int32_t value)
inline

◆ writeInt64()

int64_t sese::net::Socket::writeInt64 ( int64_t value)
inline

◆ writeUint16()

int64_t sese::net::Socket::writeUint16 ( uint16_t value)
inline

◆ writeUint32()

int64_t sese::net::Socket::writeUint32 ( uint32_t value)
inline

◆ writeUint64()

int64_t sese::net::Socket::writeUint64 ( uint64_t value)
inline

类成员变量说明

◆ address

Address::Ptr sese::net::Socket::address
private

被这些函数引用 accept().

◆ handle

socket_t sese::net::Socket::handle {}
private

该类的文档由以下文件生成: