summaryrefslogtreecommitdiff
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
parentd8ac63cd83293ab07659932d5ee6b83d7570bb57 (diff)
Extract code that reads data into a recvq from StreamSocket::DoRead() into ReadToRecvQ()
-rw-r--r--include/inspsocket.h6
-rw-r--r--src/inspsocket.cpp16
2 files changed, 19 insertions, 3 deletions
diff --git a/include/inspsocket.h b/include/inspsocket.h
index 7b913ec56..0c5f3b3af 100644
--- a/include/inspsocket.h
+++ b/include/inspsocket.h
@@ -234,6 +234,12 @@ class CoreExport StreamSocket : public EventHandler
*/
void FlushSendQ(SendQueue& sq);
+ /** Read incoming data into a receive queue.
+ * @param rq Receive queue to put incoming data into
+ * @return < 0 on error or close, 0 if no new data is ready (but the socket is still connected), > 0 if data was read from the socket and put into the recvq
+ */
+ int ReadToRecvQ(std::string& rq);
+
protected:
std::string recvq;
public:
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 */