Created:
Mon Jun 30 23:33:30 UTC 2008
diff --git a/ext/ed.cpp b/ext/ed.cpp
index 135cb2d..b885d8b 100644
--- a/ext/ed.cpp
+++ b/ext/ed.cpp
@@ -581,9 +581,10 @@ void ConnectionDescriptor::_WriteOutboundData()
}
LastIo = gCurrentLoopTime;
- char output_buffer [16 * 1024];
+ // char output_buffer [16 * 1024];
size_t nbytes = 0;
+ /*
while ((OutboundPages.size() > 0) && (nbytes < sizeof(output_buffer))) {
OutboundPage *op = &(OutboundPages[0]);
if ((nbytes + op->Length - op->Offset) < sizeof (output_buffer)) {
@@ -599,6 +600,17 @@ void ConnectionDescriptor::_WriteOutboundData()
nbytes += len;
}
}
+ */
+
+ int iovcnt = OutboundPages.size();
+ struct iovec iov[ iovcnt ];
+
+ for(int i = 0; i < iovcnt; i++){
+ OutboundPage *op = &(OutboundPages[i]);
+ iov[i].iov_base = (void *)(op->Buffer + op->Offset);
+ iov[i].iov_len = op->Length - op->Offset;
+ nbytes += (op->Length - op->Offset);
+ }
// We should never have gotten here if there were no data to write,
// so assert that as a sanity check.
@@ -607,10 +619,24 @@ void ConnectionDescriptor::_WriteOutboundData()
assert (nbytes > 0);
assert (GetSocket() != INVALID_SOCKET);
- int bytes_written = send (GetSocket(), output_buffer, nbytes, 0);
+ // int bytes_written = send (GetSocket(), output_buffer, nbytes, 0);
+ int bytes_written = writev(GetSocket(), iov, iovcnt);
if (bytes_written > 0) {
OutboundDataSize -= bytes_written;
+
+ int sent = bytes_written;
+ for(int i = 0; i < iovcnt; i++) {
+ if (iov[i].iov_len <= sent) {
+ OutboundPages.pop_front();
+ sent -= iov[i].iov_len;
+ } else {
+ OutboundPage *op = &(OutboundPages[i]);
+ op->Offset += sent;
+ }
+ }
+
+ /*
if ((size_t)bytes_written < nbytes) {
int len = nbytes - bytes_written;
char *buffer = (char*) malloc (len + 1);
@@ -620,6 +646,7 @@ void ConnectionDescriptor::_WriteOutboundData()
buffer [len] = 0;
OutboundPages.push_front (OutboundPage (buffer, len));
}
+ */
#ifdef HAVE_EPOLL
EpollEvent.events = (EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0));
diff --git a/ext/project.h b/ext/project.h
index 8fe0f63..4fe9e9d 100644
--- a/ext/project.h
+++ b/ext/project.h
@@ -44,6 +44,7 @@ See the file COPYING for complete licensing information.
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
+#include <sys/uio.h>
#include <sys/un.h>
#include <sys/resource.h>
#include <sys/wait.h>