8
8
SocketServer *SocketServer::socketServer = nullptr ;
9
9
10
10
SocketServer::SocketServer (uint16_t t_pullport, uint16_t t_pushport,
11
- void (*t_handler)( size_t , uint8_t *))
11
+ std::function< void ( size_t , uint8_t *)> t_handler )
12
12
: pull_portno(t_pullport), push_portno(t_pushport) {
13
13
this ->pullServer = new AsyncServer (t_pullport);
14
14
this ->pushServer = new AsyncServer (t_pushport);
@@ -17,8 +17,9 @@ SocketServer::SocketServer(uint16_t t_pullport, uint16_t t_pushport,
17
17
this ->handler = t_handler;
18
18
}
19
19
20
- void SocketServer::createServer (uint16_t t_pullport, uint16_t t_pushport,
21
- void (*t_handler)(size_t , uint8_t *)) {
20
+ void SocketServer::createServer (
21
+ uint16_t t_pullport, uint16_t t_pushport,
22
+ std::function<void (size_t , uint8_t *)> t_handler) {
22
23
if (socketServer == nullptr )
23
24
socketServer = new SocketServer (t_pullport, t_pushport, t_handler);
24
25
}
@@ -74,7 +75,7 @@ void SocketServer::registerClient(AsyncClient *new_client,
74
75
return ;
75
76
}
76
77
77
- void (*handler)( size_t , uint8_t *) = this ->handler ;
78
+ std::function< void ( size_t , uint8_t *)> _handler = this ->handler ;
78
79
SocketServer *thisServer = this ;
79
80
new_client->onError (
80
81
[thisServer](void *r, AsyncClient *t_client, int8_t error) {
@@ -93,9 +94,11 @@ void SocketServer::registerClient(AsyncClient *new_client,
93
94
thisServer->unregisterClient (t_client);
94
95
},
95
96
NULL );
96
- new_client->onData ([handler](void *r, AsyncClient *t_client, void *buf,
97
- size_t len) { handler (len, (uint8_t *)buf); },
98
- NULL );
97
+ new_client->onData (
98
+ [_handler](void *r, AsyncClient *t_client, void *buf, size_t len) {
99
+ _handler (len, (uint8_t *)buf);
100
+ },
101
+ NULL );
99
102
}
100
103
101
104
void SocketServer::unregisterClient (AsyncClient *t_client) {
0 commit comments