-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathasync_acceptor.hpp
64 lines (51 loc) · 1.73 KB
/
async_acceptor.hpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef ASYNC_ACCEPTOR_HPP
#define ASYNC_ACCEPTOR_HPP
#include "async_base.hpp"
#include "io_service.hpp"
#include "socket_handler.hpp"
#include "logging.hpp"
#include <iostream>
#include <memory>
/**
* @class AsyncAcceptor
* @author Michael Griffin
* @date 18/02/2018
* @file async_acceptor.hpp
* @brief Handles Async Socket Listener Jobs to IOService.
*/
class AsyncAcceptor
: public AsyncBase
{
public:
AsyncAcceptor(IOService& io_service, socket_handler_ptr socket_handler)
: AsyncBase(io_service, socket_handler)
{
}
~AsyncAcceptor()
{
m_log.write<Logging::DEBUG_LOG>("~AsyncAcceptor()");
}
/**
* @brief Async Listener Callback for IOService Work
* @param StringSequence - Host:Port
* @param Callback - return error code and handles to new session
*/
template <typename Protocol, typename Callback>
void asyncAccept(const Protocol &protocol, const Callback &callback)
{
// Place Holder is used for template parameters, string_seq is used in writes
// Where the Buffer Place Holder in the above method is used for reads.
// nullptr can't be passed as reference for vector
std::vector<unsigned char> place_holder;
std::string string_place_holder;
int service_type = SERVICE_TYPE_NONE;
if(protocol == "TELNET")
{
service_type = SERVICE_TYPE_LISTENER_TELNET;
m_log.write<Logging::DEBUG_LOG>("Async Listener Job Added to the Queue for", protocol);
m_io_service.addAsyncJob(place_holder, string_place_holder, m_socket_handler, callback, service_type);
}
}
};
typedef std::shared_ptr<AsyncAcceptor> acceptor_ptr;
#endif // ASYNC_ACCEPTOR_HPP