-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathacceptor.h
More file actions
37 lines (27 loc) · 717 Bytes
/
acceptor.h
File metadata and controls
37 lines (27 loc) · 717 Bytes
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
#ifndef ACCEPTOR_H
#define ACCEPTOR_H
#include "core.h"
#include "simple_task.h"
#include "socket_address.h"
#include "file_descriptor.h"
class simple_acceptor : public simple_task {
public:
simple_acceptor(const socket_address &);
void operator()();
virtual void on_error();
virtual void on_accept(int, const socket_address &) = 0;
};
template <class T>
class acceptor : public simple_acceptor {
public:
acceptor(const socket_address &addr)
: simple_acceptor(addr)
{ }
void on_accept(int fd, const socket_address &addr) {
file_descriptor::keepalive(fd);
file_descriptor tfd(fd);
core::instance().own(new T(static_cast<int>(tfd)));
tfd.release();
}
};
#endif//ACCEPTOR_H