- // Prepare a writev() call to write all buffers efficiently
- int bufcount = sendq.size();
-
- // cap the number of buffers at IOV_MAX
- if (bufcount > IOV_MAX)
- bufcount = IOV_MAX;
-
- 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();
- }
- int rv = writev(fd, iovecs, bufcount);
- delete[] iovecs;
- if (rv == (int)sendq_len)
- {
- // it's our lucky day, everything got written out. Fast cleanup.
- sendq_len = 0;
- sendq.clear();
- }
- else if (rv > 0)
+ // 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_len && eventChange == FD_WANT_EDGE_WRITE)