-
Notifications
You must be signed in to change notification settings - Fork 1
/
pd_accepter.c
executable file
·65 lines (61 loc) · 1.64 KB
/
pd_accepter.c
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
#include "pd_accepter.h"
#include "pd_socket.h"
#include "pd_log.h"
#include "pd_tcp.h"
#include "pd_ioc.h"
#include "pd_transport.h"
int pd_listen_on_readable(struct PdIOComponent *ioc)
{
int ret = 0;
struct PdSocket *accept_sock = NULL;
struct PdIOComponent *accept_ioc = NULL;
if (NULL == ioc)
{
PD_LOG(WARN, "ioc null pointer");
}
else if (NULL == ioc->sock)
{
PD_LOG(WARN, "sock null pointer");
}
else if (NULL == ioc->ts)
{
PD_LOG(WARN, "ts null pointer");
}
else if (NULL == (accept_sock = pd_socket_accept_tcp_client(ioc->sock)))
{
PD_LOG(WARN, "accept sock fail, listen_sock=%p", ioc->sock);
}
else if (NULL == (accept_ioc = pd_tcp_ioc_alloc()))
{
PD_LOG(WARN, "alloc ioc fail, accept_sock=%p", accept_sock);
pd_socket_destroy(accept_sock);
}
else
{
accept_ioc->sock = accept_sock;
accept_ioc->ts = ioc->ts;
accept_ioc->on_readable = pd_tcp_on_readable;
accept_ioc->on_writeable = pd_tcp_on_writeable;
accept_ioc->on_error = pd_tcp_on_error;
accept_ioc->in_epoll_read = 0;
accept_ioc->in_epoll_write = 0;
accept_ioc->tmp_pos = 0;
if (0 != pd_transport_set_ioc(ioc->ts, accept_ioc, 1, 0))
{
PD_LOG(WARN, "pd_transport_set_ioc fail, accept_ioc=%p", accept_ioc);
pd_socket_destroy(accept_sock);
pd_tcp_ioc_free(accept_ioc);
}
}
return ret;
}
int pd_listen_on_writeable(struct PdIOComponent *ioc)
{
int ret = 0;
PD_LOG(FATAL, "unexpected error, listen fd cannot be writeable, ioc=%p", ioc);
return ret;
}
void pd_listen_on_error(struct PdIOComponent *ioc)
{
PD_LOG(FATAL, "unexpected error, listen fd cannot be error, ioc=%p", ioc);
}