30 #include <sys/types.h>
34 bool GNet::Socket::create(
int domain ,
int type ,
int protocol )
36 m_socket = Descriptor( ::socket(domain,type,protocol) ) ;
45 bool GNet::Socket::prepare(
bool accepted )
47 static bool first = true ;
62 void GNet::Socket::destroy()
64 ::close( m_socket.fd() ) ;
67 bool GNet::Socket::error(
int rc )
72 void GNet::Socket::saveReason()
75 m_reason_string = reasonString( m_reason ) ;
78 bool GNet::Socket::setNonBlock()
80 int mode = ::fcntl( m_socket.fd() , F_GETFL ) ;
84 int rc = ::fcntl( m_socket.fd() , F_SETFL , mode | O_NONBLOCK ) ;
88 bool GNet::Socket::sizeError( ssize_t size )
95 return m_reason == EWOULDBLOCK || m_reason == EAGAIN || m_reason == EINTR ;
100 return m_reason == EINPROGRESS ;
105 return m_reason == EMSGSIZE ;
110 return bind( address ,
NoThrow() ) ;
113 void GNet::Socket::setOptionReuse()
115 setOption( SOL_SOCKET ,
"so_reuseaddr" , SO_REUSEADDR , 1 ) ;
118 void GNet::Socket::setOptionExclusive()
123 void GNet::Socket::setOptionPureV6(
bool active )
125 #if GCONFIG_HAVE_IPV6
127 setOption( IPPROTO_IPV6 ,
"ipv6_v6only" , IPV6_V6ONLY , 1 ) ;
130 throw SocketError(
"cannot set socket option for pure ipv6" ) ;
134 bool GNet::Socket::setOptionPureV6(
bool active , NoThrow )
136 #if GCONFIG_HAVE_IPV6
137 return active ? setOption( IPPROTO_IPV6 ,
"ipv6_v6only" , IPV6_V6ONLY , 1 , NoThrow() ) : true ;
143 bool GNet::Socket::setOptionImp(
int level ,
int op ,
const void * arg , socklen_t n )
145 int rc = ::setsockopt( m_socket.fd() , level , op , arg , n ) ;
149 std::string GNet::Socket::reasonString(
int e )
bool canBindHint(const Address &address)
Returns true if the socket can probably be bound with the given address.
static Descriptor invalid()
Returns a descriptor with an invalid socket part and a zero handle.
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.
static std::string lower(const std::string &s)
Returns a copy of 's' in which all Latin-1 uppercase characters have been replaced by lowercase chara...
bool eInProgress()
Returns true if the previous socket operation failed with the EINPROGRESS error status.
static void init()
An optional early-initialisation function. May be called more than once.
virtual bool eWouldBlock() override
Returns true if the previous socket operation failed because the socket would have blocked...
Overload discriminator class for GNet::Socket.