]> git.sesse.net Git - cubemap/blobdiff - acceptor.h
Support multiple listening sockets. Actually mostly because it makes the code somewha...
[cubemap] / acceptor.h
index 5cd579da11381f731aa9d5d46dcda3a3f9113301..caa46474ce48d83185244cc2e977c155ce882e1b 100644 (file)
@@ -1,26 +1,28 @@
 #ifndef _ACCEPTOR_H
 #define _ACCEPTOR_H
 
+#include "thread.h"
+
 int create_server_socket(int port);
 
+class AcceptorProto;
+
 // A thread that accepts new connections on a given socket,
 // and hands them off to the server pool.
-class AcceptorThread {
+class Acceptor : public Thread {
 public:
-       AcceptorThread(int server_sock);
-       void run();
-       void stop();
+       Acceptor(int server_sock, int port);
 
-private:
-       // Recovers the this pointer, and hands over control to do_work().
-       static void *do_work_thunk(void *arg);
+       // Serialization/deserialization.
+       Acceptor(const AcceptorProto &serialized);
+       AcceptorProto serialize() const;
 
-       void do_work();
+       void close_socket();
 
-       int server_sock;
+private:
+       virtual void do_work();
 
-       pthread_t worker_thread;
-       volatile bool should_stop;
+       int server_sock, port;
 };
 
 #endif  // !defined(_ACCEPTOR_H)