- int err = errno;
- if (err == EAGAIN)
- return "";
- else
- return NULL;
- }
-}
-
-/*
- * 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)
-{
- /* Append the data to the back of the queue ready for writing */
- outbuffer.push_back(data);
+ // don't even try if we are known to be blocking
+ if (GetEventMask() & FD_WRITE_WILL_BLOCK)
+ return;
+ // start out optimistic - we won't need to write any more
+ int eventChange = FD_WANT_EDGE_WRITE;
+ while (error.empty() && !sendq.empty() && eventChange == FD_WANT_EDGE_WRITE)
+ {
+ // Prepare a writev() call to write all buffers efficiently
+ int bufcount = sendq.size();