+ // Prepare a writev() call to write all buffers efficiently
+ int bufcount = sq.size();
+
+ // cap the number of buffers at MYIOV_MAX
+ if (bufcount > MYIOV_MAX)
+ {
+ bufcount = MYIOV_MAX;
+ }
+
+ int rv_max = 0;
+ int rv;
+ {
+ SocketEngine::IOVector iovecs[MYIOV_MAX];
+ size_t j = 0;
+ for (SendQueue::const_iterator i = sq.begin(), end = i+bufcount; i != end; ++i, j++)
+ {
+ const SendQueue::Element& elem = *i;
+ iovecs[j].iov_base = const_cast<char*>(elem.data());
+ iovecs[j].iov_len = elem.length();
+ rv_max += iovecs[j].iov_len;
+ }
+ rv = SocketEngine::WriteV(this, iovecs, bufcount);
+ }
+
+ if (rv == (int)sq.bytes())
+ {
+ // it's our lucky day, everything got written out. Fast cleanup.
+ // This won't ever happen if the number of buffers got capped.
+ sq.clear();
+ }
+ else if (rv > 0)