- }
- catch (CoreException& modexcept)
- {
- ServerInstance->Logs->Log("SOCKET", DEBUG,"%s threw an exception: %s",
- modexcept.GetSource(), modexcept.GetReason());
- }
- }
- else
- {
- // 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)
- {
- // Partial write. Clean out strings from the sendq
- sendq_len -= rv;
- while (rv > 0 && !sendq.empty())