#include <vector>
#include <string>
#include <map>
+#include <algorithm>
#include "metacube.h"
#include "server.h"
}
// 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),
break;
}
default:
- // TODO
assert(false);
}
}
perror("epoll_ctl(EPOLL_CTL_DEL)");
exit(1);
}
+
+ // This client could be sleeping, so we'll need to fix that. (Argh, O(n).)
+ vector<int>::iterator new_end =
+ remove(sleeping_clients.begin(), sleeping_clients.end(), client->sock);
+ sleeping_clients.erase(new_end, sleeping_clients.end());
// Bye-bye!
close(client->sock);