#include <utility>
#include <vector>
+#include "log.h"
#include "markpool.h"
#include "mutexlock.h"
#include "parse.h"
process_queued_data();
for (int i = 0; i < nfds; ++i) {
- int fd = events[i].data.fd;
- assert(clients.count(fd) != 0);
- Client *client = &clients[fd];
+ Client *client = reinterpret_cast<Client *>(events[i].data.u64);
if (events[i].events & (EPOLLERR | EPOLLRDHUP | EPOLLHUP)) {
close_client(client);
// Start listening on data from this socket.
epoll_event ev;
ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP;
- ev.data.u64 = 0; // Keep Valgrind happy.
- ev.data.fd = sock;
+ ev.data.u64 = reinterpret_cast<uint64_t>(&clients[sock]);
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_ADD)");
exit(1);
ev.events = EPOLLOUT | EPOLLET | EPOLLRDHUP;
}
ev.data.u64 = 0; // Keep Valgrind happy.
- ev.data.fd = client.sock();
+ ev.data.u64 = reinterpret_cast<uint64_t>(client_ptr);
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, client.sock(), &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_ADD)");
exit(1);
switch (status) {
case RP_OUT_OF_SPACE:
- fprintf(stderr, "WARNING: fd %d sent overlong request!\n", client->sock);
+ log(WARNING, "fd %d sent overlong request!", client->sock);
close_client(client);
return;
case RP_NOT_FINISHED_YET:
// See if there's more data for us.
goto read_request_again;
case RP_EXTRA_DATA:
- fprintf(stderr, "WARNING: fd %d had junk data after request!\n", client->sock);
+ log(WARNING, "fd %d had junk data after request!", client->sock);
close_client(client);
return;
case RP_FINISHED:
return;
}
if (bytes_to_send > stream->backlog_size) {
- fprintf(stderr, "WARNING: fd %d lost %lld bytes, maybe too slow connection\n",
+ log(WARNING, "fd %d lost %lld bytes, maybe too slow connection",
client->sock,
(long long int)(bytes_to_send - stream->backlog_size));
client->stream_pos = stream->bytes_received - stream->backlog_size;
+ client->bytes_lost += bytes_to_send - stream->backlog_size;
+ ++client->num_loss_events;
bytes_to_send = stream->backlog_size;
}
return;
}
client->stream_pos += ret;
+ client->bytes_sent += ret;
if (client->stream_pos == stream->bytes_received) {
// We don't have any more data for this client, so put it to sleep.
// This is postcondition #3.
stream->put_client_to_sleep(client);
- } else if (more_data) {
+ } else if (more_data && size_t(ret) == bytes_to_send) {
goto sending_data_again;
}
break;
epoll_event ev;
ev.events = EPOLLOUT | EPOLLET | EPOLLRDHUP;
- ev.data.u64 = 0; // Keep Valgrind happy.
- ev.data.fd = client->sock;
+ ev.data.u64 = reinterpret_cast<uint64_t>(client);
if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, client->sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_MOD)");
epoll_event ev;
ev.events = EPOLLOUT | EPOLLET | EPOLLRDHUP;
- ev.data.u64 = 0; // Keep Valgrind happy.
- ev.data.fd = client->sock;
+ ev.data.u64 = reinterpret_cast<uint64_t>(client);
if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, client->sock, &ev) == -1) {
perror("epoll_ctl(EPOLL_CTL_MOD)");