40 class SocketProtocol ;
42 class DatagramSocket ;
54 G_EXCEPTION( SocketError ,
"socket error" ) ;
55 G_EXCEPTION_CLASS( SocketCreateError ,
"socket create error" ) ;
56 G_EXCEPTION_CLASS( SocketBindError ,
"socket bind error" ) ;
57 G_EXCEPTION_CLASS( SocketTooMany ,
"socket accept error" ) ;
58 using size_type = G::ReadWrite::size_type ;
59 using ssize_type = G::ReadWrite::ssize_type ;
65 static bool supports( Address::Family ,
int type ,
int protocol ) ;
73 SOCKET
fd() const noexcept override ;
130 std::
string reason() const ;
148 SocketBase( const
Raw & ,
int domain ,
int type ,
int protocol ) ;
151 ssize_type
writeImp( const
char * buf , size_type len ) ;
156 static
bool error(
int rc ) ;
160 static
bool sizeError( ssize_type size ) ;
177 static std::
string reasonString(
int ) ;
178 bool create(
int ,
int ,
int ) ;
179 bool prepare(
bool ) ;
180 void drop() noexcept ;
181 void destroy() noexcept ;
182 void unlink() noexcept ;
183 bool setNonBlocking() ;
188 void operator=( const
SocketBase & ) = delete ;
208 Address getLocalAddress()
const ;
211 std::pair<bool,Address> getPeerAddress()
const ;
219 bool bind(
const Address & , std::nothrow_t ) ;
222 static std::string canBindHint(
const Address & address ,
bool stream_socket =
true ) ;
228 unsigned long getBoundScopeId()
const ;
234 bool connect(
const Address & addr ,
bool *done =
nullptr ) ;
249 void listen(
int backlog = 1 ) ;
254 void shutdown(
int how = 1 ) ;
271 void operator=(
const Socket & ) = delete ;
272 void operator=(
Socket && ) = delete ;
275 Socket( Address::Family ,
int type ,
int protocol ) ;
277 std::pair<bool,Address> getLocalAddress( std::nothrow_t )
const ;
278 void setOption(
int ,
const char * ,
int ,
int ) ;
279 bool setOption(
int ,
const char * ,
int ,
int , std::nothrow_t ) ;
280 bool setOptionImp(
int ,
int ,
const void * , socklen_t ) ;
281 void setOptionsOnBind( Address::Family ) ;
282 void setOptionsOnConnect( Address::Family ) ;
283 void setOptionLingerImp(
int ,
int ) ;
284 void setOptionNoLinger() ;
285 void setOptionReuse() ;
286 void setOptionExclusive() ;
287 void setOptionPureV6() ;
288 bool setOptionPureV6( std::nothrow_t ) ;
289 void setOptionKeepAlive() ;
292 unsigned long m_bound_scope_id{0UL} ;
302 std::shared_ptr<StreamSocket> socket_ptr ;
313 using size_type = Socket::size_type ;
314 using ssize_type = Socket::ssize_type ;
318 static bool supports( Address::Family ) ;
333 ssize_type
read(
char * buffer , size_type buffer_length )
override ;
336 ssize_type
write(
const char * buf , size_type len )
override ;
352 void setOptionsOnCreate( Address::Family ,
bool listener ) ;
353 void setOptionsOnAccept( Address::Family ) ;
365 ssize_type
read(
char * buffer , size_type len )
override ;
368 ssize_type
write(
const char * buffer , size_type len )
override ;
371 ssize_type readfrom(
char * buffer , size_type len ,
Address & src ) ;
376 ssize_type writeto(
const char * buffer , size_type len ,
const Address & dst ) ;
399 RawSocket(
int domain ,
int type ,
int protocol ) ;
402 ssize_type
read(
char * buffer , size_type buffer_length )
override ;
405 ssize_type
write(
const char * buf , size_type len )
override ;
412 void operator=(
const RawSocket & ) = delete ;
413 void operator=(
RawSocket && ) = delete ;
A class which is used to return a new()ed socket to calling code, together with associated address in...
The GNet::Address class encapsulates a TCP/UDP transport address.
static Address defaultAddress()
Returns a default address, being the IPv4 wildcard address with a zero port number.
A derivation of GNet::Socket for a datagram socket.
A class that encapsulates a network socket file descriptor and an associated windows event handle.
A base class for classes that handle asynchronous events from the event loop.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A derivation of GNet::SocketBase for a raw socket, typically of type AF_NETLINK or PF_ROUTE.
A socket base class that holds a non-blocking socket file descriptor and interfaces to the event loop...
bool eNotConn() const
Returns true if the previous socket operation failed with the ENOTCONN error status,...
bool eInProgress() const
Returns true if the previous socket operation failed with the EINPROGRESS error status.
~SocketBase() override
Destructor.
std::string reason() const
Returns the reason for the previous error.
SOCKET fd() const noexcept override
Returns the socket file descriptor.
void clearReason()
Clears the saved errno.
std::string asString() const
Returns the socket handle as a string.
void dropReadHandler() noexcept
Reverses addReadHandler().
void addOtherHandler(EventHandler &, ExceptionSink)
Adds this socket to the event source list so that the given handler receives exception events.
static bool error(int rc)
Returns true if the given return code indicates an error.
bool eMsgSize() const
Returns true if the previous socket operation failed with the EMSGSIZE error status.
bool isFamily(Address::Family) const
Returns true if the socket family is as given.
void addReadHandler(EventHandler &, ExceptionSink)
Adds this socket to the event source list so that the given handler receives read events.
static bool sizeError(ssize_type size)
Returns true if the given write() return value indicates an error.
static bool supports(Address::Family, int type, int protocol)
Returns true if sockets can be created with the given parameters.
void addWriteHandler(EventHandler &, ExceptionSink)
Adds this socket to the event source list so that the given handler receives write events when flow c...
void dropOtherHandler() noexcept
Reverses addOtherHandler().
ssize_type writeImp(const char *buf, size_type len)
Writes to the socket.
bool eWouldBlock() const override
Returns true if the previous socket operation failed because the socket would have blocked.
bool eTooMany() const
Returns true if the previous socket operation failed with the EMFILE error status,...
void dropWriteHandler() noexcept
Reverses addWriteHandler().
void saveReason()
Saves the current errno following error()/sizeError().
An internet-protocol socket class.
A derivation of GNet::Socket for a stream socket.
An abstract interface for reading and writing from a non-blocking i/o channel.
virtual ssize_type write(const char *buf, size_type len)=0
Sends data.
virtual ssize_type read(char *buffer, size_type buffer_length)=0
Reads data.
Overload discriminator class for GNet::SocketBase.
Overload discriminator class for GNet::SocketBase.
Overload discriminator class for GNet::StreamSocket.