+ int rv_max = 0;
+ iovec* iovecs = new iovec[bufcount];
+ for(int i=0; i < bufcount; i++)
+ {
+ iovecs[i].iov_base = const_cast<char*>(sendq[i].data());
+ iovecs[i].iov_len = sendq[i].length();
+ rv_max += sendq[i].length();
+ }
+ int rv = writev(fd, iovecs, bufcount);
+ delete[] iovecs;
+
+ if (rv == (int)sendq_len)
+ {
+ // it's our lucky day, everything got written out. Fast cleanup.
+ // This won't ever happen if the number of buffers got capped.
+ sendq_len = 0;
+ sendq.clear();
+ }
+ else if (rv > 0)
+ {
+ // Partial write. Clean out strings from the sendq
+ if (rv < rv_max)
+ {
+ // it's going to block now
+ eventChange = FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK;
+ }
+ sendq_len -= rv;
+ while (rv > 0 && !sendq.empty())