File: acceptor.h

package info (click to toggle)
cubemap 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 428 kB
  • sloc: cpp: 4,431; sh: 114; perl: 102; makefile: 60
file content (38 lines) | stat: -rw-r--r-- 800 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _ACCEPTOR_H
#define _ACCEPTOR_H

#include <netinet/in.h>

#include "thread.h"

enum SocketType {
	TCP_SOCKET,
	UDP_SOCKET,
};
int create_server_socket(const sockaddr_in6 &addr, SocketType socket_type);

class AcceptorProto;

sockaddr_in6 create_any_address(int port);
sockaddr_in6 extract_address_from_acceptor_proto(const AcceptorProto &proto);

// A thread that accepts new connections on a given socket,
// and hands them off to the server pool.
class Acceptor : public Thread {
public:
	Acceptor(int server_sock, const sockaddr_in6 &addr);

	// Serialization/deserialization.
	Acceptor(const AcceptorProto &serialized);
	AcceptorProto serialize() const;

	void close_socket();

private:
	virtual void do_work();

	int server_sock;
	sockaddr_in6 addr;
};

#endif  // !defined(_ACCEPTOR_H)