- this->Instance->Log(DEBUG,"Write error on socket: %s",strerror(errno));
- this->OnError(I_ERR_WRITE);
- this->state = I_ERROR;
- this->Instance->SE->DelFd(this);
- this->Close();
- return true;
+ /* Send a line */
+ int result = Instance->SE->Send(this, outbuffer[0].c_str(), outbuffer[0].length(), 0);
+
+ if (result > 0)
+ {
+ if ((unsigned int)result >= outbuffer[0].length())
+ {
+ /* The whole block was written (usually a line)
+ * Pop the block off the front of the queue,
+ * dont set errno, because we are clear of errors
+ * and want to try and write the next block too.
+ */
+ outbuffer.pop_front();
+ }
+ else
+ {
+ std::string temp = outbuffer[0].substr(result);
+ outbuffer[0] = temp;
+ /* We didnt get the whole line out. arses.
+ * Try again next time, i guess. Set errno,
+ * because we shouldnt be writing any more now,
+ * until the socketengine says its safe to do so.
+ */
+ errno = EAGAIN;
+ }
+ }
+ else if (result == 0)
+ {
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ return true;
+ }
+ else if ((result == -1) && (errno != EAGAIN))
+ {
+ this->OnError(I_ERR_WRITE);
+ this->state = I_ERROR;
+ this->Instance->SE->DelFd(this);
+ this->Close();
+ return true;
+ }