Implement writev(). Working reflector!
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Apr 2013 16:13:55 +0000 (18:13 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Apr 2013 16:13:55 +0000 (18:13 +0200)
server.cpp

index b914b2e..da721e7 100644 (file)
@@ -220,10 +220,18 @@ void Server::process_client(Client *client)
                }
 
                // See if we need to split across the circular buffer.
-               int ret;
+               ssize_t ret;
                if ((client->bytes_sent % BACKLOG_SIZE) + bytes_to_send > BACKLOG_SIZE) {
-                       // TODO: writev
-                       assert(false);
+                       size_t bytes_first_part = BACKLOG_SIZE - (client->bytes_sent % BACKLOG_SIZE);
+
+                       iovec iov[2];
+                       iov[0].iov_base = const_cast<char *>(stream.data + (client->bytes_sent % BACKLOG_SIZE));
+                       iov[0].iov_len = bytes_first_part;
+
+                       iov[1].iov_base = const_cast<char *>(stream.data);
+                       iov[1].iov_len = bytes_to_send - bytes_first_part;
+
+                       ret = writev(client->sock, iov, 2);
                } else {
                        ret = write(client->sock,
                                    stream.data + (client->bytes_sent % BACKLOG_SIZE),