mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Always use non-blocking sockets
This commit is contained in:
@@ -92,6 +92,16 @@ class CoreExport Socket : public Flags<SocketFlag, 1>
|
||||
*/
|
||||
int GetSock() const;
|
||||
|
||||
/** Mark a socket as blockig
|
||||
* @return true if the socket is now blocking
|
||||
*/
|
||||
bool SetBlocking();
|
||||
|
||||
/** Mark a socket as non-blocking
|
||||
* @return true if the socket is now non-blocking
|
||||
*/
|
||||
bool SetNonBlocking();
|
||||
|
||||
/** Check if this socket is IPv6
|
||||
* @return true or false
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,8 @@ class SSLSocket : public ClientSocket
|
||||
public:
|
||||
SSLSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6)
|
||||
{
|
||||
this->SetBlocking();
|
||||
|
||||
sslsock = SSL_new(ctx);
|
||||
|
||||
if (!sslsock)
|
||||
@@ -41,6 +43,8 @@ class SSLSocket : public ClientSocket
|
||||
SSL_connect(sslsock);
|
||||
|
||||
UplinkSock = this;
|
||||
|
||||
this->SetNonBlocking();
|
||||
}
|
||||
|
||||
~SSLSocket()
|
||||
|
||||
@@ -65,6 +65,34 @@ int Socket::GetSock() const
|
||||
return sock;
|
||||
}
|
||||
|
||||
/** Mark a socket as blockig
|
||||
* @return true if the socket is now blocking
|
||||
*/
|
||||
bool Socket::SetBlocking()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
unsigned long opt = 0;
|
||||
return !ioctlsocket(this->GetSock(), FIONBIO, &opt);
|
||||
#else
|
||||
int flags = fcntl(this->GetSock(), F_GETFL, 0);
|
||||
return !fcntl(this->GetSock(), F_SETFL, flags & ~O_NONBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Mark a socket as non-blocking
|
||||
* @return true if the socket is now non-blocking
|
||||
*/
|
||||
bool Socket::SetNonBlocking()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
unsigned long opt = 0;
|
||||
return !ioctlsocket(this->GetSock(), FIONBIO, &opt);
|
||||
#else
|
||||
int flags = fcntl(this->GetSock(), F_GETFL, 0);
|
||||
return !fcntl(this->GetSock(), F_SETFL, flags | O_NONBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Check if this socket is IPv6
|
||||
* @return true or false
|
||||
*/
|
||||
@@ -305,6 +333,8 @@ ClientSocket::ClientSocket(const std::string &nTargetHost, int nPort, const std:
|
||||
throw SocketException("Error connecting to server: " + std::string(strerror(errno)));
|
||||
}
|
||||
}
|
||||
|
||||
this->SetNonBlocking();
|
||||
}
|
||||
|
||||
/** Default destructor
|
||||
@@ -375,6 +405,8 @@ ListenSocket::ListenSocket(const std::string &bindip, int port) : Socket(0, (bin
|
||||
{
|
||||
throw SocketException("Unable to listen: " + std::string(strerror(errno)));
|
||||
}
|
||||
|
||||
this->SetNonBlocking();
|
||||
}
|
||||
|
||||
/** Destructor
|
||||
|
||||
Reference in New Issue
Block a user