32 #include <sys/types.h>
36 bool GNet::Socket::setNonBlock()
38 int mode = ::fcntl( m_socket.
fd() , F_GETFL ) ;
42 int rc = ::fcntl( m_socket.
fd() , F_SETFL , mode | O_NONBLOCK ) ;
46 int GNet::Socket::reason()
52 void GNet::Socket::doClose()
54 ::close( m_socket.fd() ) ;
58 bool GNet::Socket::error(
int rc )
63 bool GNet::Socket::sizeError( ssize_t size )
70 return m_reason == EWOULDBLOCK || m_reason == EAGAIN || m_reason == EINTR ;
75 return m_reason == EINPROGRESS ;
80 return m_reason == EMSGSIZE ;
83 void GNet::Socket::setFault()
90 return bind( address ,
NoThrow() ) ;
93 void GNet::Socket::setOptionReuse()
95 setOption( SOL_SOCKET ,
"so_reuseaddr" , SO_REUSEADDR , 1 ) ;
98 void GNet::Socket::setOptionExclusive()
103 void GNet::Socket::setOptionPureV6(
bool active )
105 #if GCONFIG_HAVE_IPV6
107 setOption( IPPROTO_IPV6 ,
"ipv6_v6only" , IPV6_V6ONLY , 1 ) ;
110 throw SocketError(
"cannot set socket option for pure ipv6" ) ;
114 bool GNet::Socket::setOptionPureV6(
bool active , NoThrow )
116 #if GCONFIG_HAVE_IPV6
117 return active ? setOption( IPPROTO_IPV6 ,
"ipv6_v6only" , IPV6_V6ONLY , 1 , NoThrow() ) : true ;
123 bool GNet::Socket::setOptionImp(
int level ,
int op ,
const void * arg , socklen_t n )
125 int rc = ::setsockopt( m_socket.fd() , level , op , arg , n ) ;
129 std::string GNet::Socket::reasonStringImp(
int e )
131 return G::Process::strerror( e ) ;
bool canBindHint(const Address &address)
Returns true if the socket can probably be bound with the given address.
static Descriptor invalid()
Returns an invalid descriptor.
virtual bool eWouldBlock()
Returns true if the previous socket operation failed because the socket would have blocked...
The GNet::Address class encapsulates a TCP/UDP transport address.
bool eMsgSize()
Returns true if the previous socket operation failed with the EMSGSIZE error status.
SOCKET fd() const
Returns the low-level descriptor.
bool eInProgress()
Returns true if the previous socket operation failed with the EINPROGRESS error status.
Overload discriminator class for GNet::Socket.