X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspsocket.cpp;h=d4e7e93e7013b31702c0c7c5c9ecab8ba1d56fe2;hb=e078fae142238765f279b50c309f22a5a0761ce4;hp=c6fcf8fd65ba863a9e35992612796b4750f42d61;hpb=6953371f7133223ea85e815530320715bae43cc6;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index c6fcf8fd6..d4e7e93e7 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -363,7 +363,8 @@ void BufferedSocket::Close() { try { - Instance->Config->GetIOHook(this)->OnRawSocketClose(this->fd); + if (this->state != I_LISTENING) + Instance->Config->GetIOHook(this)->OnRawSocketClose(this->fd); } catch (CoreException& modexcept) { @@ -391,6 +392,7 @@ const char* BufferedSocket::Read() return NULL; int n = 0; + char *ReadBuffer = Instance->GetReadBuffer(); if (this->IsIOHooked) { @@ -398,7 +400,7 @@ const char* BufferedSocket::Read() int MOD_RESULT = 0; try { - MOD_RESULT = Instance->Config->GetIOHook(this)->OnRawSocketRead(this->fd,this->ibuf,sizeof(this->ibuf),result2); + MOD_RESULT = Instance->Config->GetIOHook(this)->OnRawSocketRead(this->fd, ReadBuffer, sizeof(ReadBuffer) - 1,result2); } catch (CoreException& modexcept) { @@ -416,13 +418,19 @@ const char* BufferedSocket::Read() } else { - n = recv(this->fd,this->ibuf,sizeof(this->ibuf),0); + n = recv(this->fd, ReadBuffer, sizeof(ReadBuffer) - 1, 0); } - if ((n > 0) && (n <= (int)sizeof(this->ibuf))) + /* + * This used to do some silly bounds checking instead of just passing bufsize - 1 to recv. + * Not only does that make absolutely no sense, but it could potentially result in a read buffer's worth + * of data being thrown into the bit bucket for no good reason, which is just *stupid*.. do things correctly now. + * --w00t (july 2, 2008) + */ + if (n > 0) { - ibuf[n] = 0; - return ibuf; + ReadBuffer[n] = 0; + return ReadBuffer; } else { @@ -434,17 +442,25 @@ const char* BufferedSocket::Read() } } -// There are two possible outcomes to this function. -// It will either write all of the data, or an undefined amount. -// If an undefined amount is written the connection has failed -// and should be aborted. -int BufferedSocket::Write(const std::string &data) +/* + * This function formerly tried to flush write buffer each call. + * While admirable in attempting to get the data out to wherever + * it is going, on a full socket, it's just going to syscall write() and + * EAGAIN constantly, instead of waiting in the SE to know if it can write + * which will chew a bit of CPU. + * + * So, now this function returns void (take note) and just adds to the sendq. + * + * It'll get written at a determinate point when the socketengine tells us it can write. + * -- w00t (april 1, 2008) + */ +void BufferedSocket::Write(const std::string &data) { - /* Try and append the data to the back of the queue, and send it on its way - */ + /* Append the data to the back of the queue ready for writing */ outbuffer.push_back(data); + + /* Mark ourselves as wanting write */ this->Instance->SE->WantWrite(this); - return (!this->FlushWriteBuffer()); } bool BufferedSocket::FlushWriteBuffer()