summaryrefslogtreecommitdiff
path: root/src/inspsocket.cpp
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-08-08 14:37:22 +0200
committerAttila Molnar <attilamolnar@hush.com>2016-08-08 14:37:22 +0200
commit6466e3093a4e5e996f2c9f3c4fd9f6eb1ac0e7b9 (patch)
tree7d871126e909b12675a8335923af3b01e51c1f3a /src/inspsocket.cpp
parentd8ac63cd83293ab07659932d5ee6b83d7570bb57 (diff)
Extract code that reads data into a recvq from StreamSocket::DoRead() into ReadToRecvQ()
Diffstat (limited to 'src/inspsocket.cpp')
-rw-r--r--src/inspsocket.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 629fa8019..f6ca53164 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -151,39 +151,49 @@ void StreamSocket::DoRead()
}
else
{
+ ReadToRecvQ(recvq);
+ }
+}
+
+int StreamSocket::ReadToRecvQ(std::string& rq)
+{
char* ReadBuffer = ServerInstance->GetReadBuffer();
int n = SocketEngine::Recv(this, ReadBuffer, ServerInstance->Config->NetBufferSize, 0);
if (n == ServerInstance->Config->NetBufferSize)
{
SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ);
- recvq.append(ReadBuffer, n);
+ rq.append(ReadBuffer, n);
OnDataReady();
}
else if (n > 0)
{
SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ);
- recvq.append(ReadBuffer, n);
+ rq.append(ReadBuffer, n);
OnDataReady();
}
else if (n == 0)
{
error = "Connection closed";
SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE);
+ return -1;
}
else if (SocketEngine::IgnoreError())
{
SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_READ_WILL_BLOCK);
+ return 0;
}
else if (errno == EINTR)
{
SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ);
+ return 0;
}
else
{
error = SocketEngine::LastError();
SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE);
+ return -1;
}
- }
+ return n;
}
/* Don't try to prepare huge blobs of data to send to a blocked socket */