#ifndef _ACCEPTOR_H
#define _ACCEPTOR_H
-int create_server_socket(int port);
+#include "thread.h"
+
+enum SocketType {
+ TCP_SOCKET,
+ UDP_SOCKET,
+};
+int create_server_socket(int port, SocketType socket_type);
+
+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)