#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <signal.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include "acceptor.h"
#include "serverpool.h"
+#include "state.pb.h"
using namespace std;
return server_sock;
}
+
+Acceptor::Acceptor(int server_sock, int port)
+ : server_sock(server_sock),
+ port(port)
+{
+}
+
+Acceptor::Acceptor(const AcceptorProto &serialized)
+ : server_sock(serialized.server_sock()),
+ port(serialized.port())
+{
+}
+
+AcceptorProto Acceptor::serialize() const
+{
+ AcceptorProto serialized;
+ serialized.set_server_sock(server_sock);
+ serialized.set_port(port);
+ return serialized;
+}
+
+void Acceptor::close_socket()
+{
+ int ret;
+ do {
+ ret = close(server_sock);
+ } while (ret == -1 && errno == EINTR);
+
+ if (ret == -1) {
+ perror("close");
+ }
+}
-void *acceptor_thread_run(void *arg)
+void Acceptor::do_work()
{
- int server_sock = int(intptr_t(arg));
while (!hupped) {
// Since we are non-blocking, we need to wait for the right state first.
// Wait up to 50 ms, then check hupped.
// Pick a server, round-robin, and hand over the socket to it.
servers->add_client(sock);
}
- return NULL;
}