summaryrefslogtreecommitdiff
path: root/src/sockets.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-12-13 06:12:56 -0500
committerAdam <Adam@anope.org>2012-12-13 06:12:56 -0500
commitc1077faa281c5635f85b892e605e23bd6c8fcc3b (patch)
tree213b5f87a19f182e1efd6110f03ff10d5b10ebf6 /src/sockets.cpp
parent76ba147c22944b67e8522cd2bb7b6e1bae498ced (diff)
Optimize much of the database code and serialize code.
Diffstat (limited to 'src/sockets.cpp')
-rw-r--r--src/sockets.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 6aadb7802..3dd3e67b3 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -419,7 +419,7 @@ Socket::Socket(int s, bool i, int type)
this->sock = socket(this->ipv6 ? AF_INET6 : AF_INET, type, 0);
else
this->sock = s;
- this->SetNonBlocking();
+ this->SetBlocking(false);
SocketEngine::Sockets[this->sock] = this;
SocketEngine::Change(this, true, SF_READABLE);
}
@@ -443,16 +443,13 @@ bool Socket::IsIPv6() const
return ipv6;
}
-bool Socket::SetBlocking()
+bool Socket::SetBlocking(bool state)
{
int flags = fcntl(this->GetFD(), F_GETFL, 0);
- return !fcntl(this->GetFD(), F_SETFL, flags & ~O_NONBLOCK);
-}
-
-bool Socket::SetNonBlocking()
-{
- int flags = fcntl(this->GetFD(), F_GETFL, 0);
- return !fcntl(this->GetFD(), F_SETFL, flags | O_NONBLOCK);
+ if (state)
+ return !fcntl(this->GetFD(), F_SETFL, flags & ~O_NONBLOCK);
+ else
+ return !fcntl(this->GetFD(), F_SETFL, flags | O_NONBLOCK);
}
void Socket::Bind(const Anope::string &ip, int port)
@@ -481,7 +478,7 @@ void Socket::ProcessError()
ListenSocket::ListenSocket(const Anope::string &bindip, int port, bool i)
{
- this->SetNonBlocking();
+ this->SetBlocking(false);
const char op = 1;
setsockopt(this->GetFD(), SOL_SOCKET, SO_REUSEADDR, &op, sizeof(op));