summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */