13
static int pipefd_handle_event(pipefd_t *s)
20
client_fd_info_t client_fd_info;
21
int rbytes = read(s->fd, &client_fd_info, sizeof(client_fd_info));
24
ussl_log_error("read EOF, pipe fd may be closed, pipefd:%d, errno:%d",
27
} else if (-1 == rbytes) {
28
if (EAGAIN != errno && EWOULDBLOCK != errno) {
29
ussl_log_error("call read failed, pipefd:%d, errno:%d", s->fd, errno);
34
clientfd_sk_t *clientfd_sk = (clientfd_sk_t *)s->fty->create((ussl_sf_t *)s->fty);
36
ussl_log_error("create clientfd sock failed, the clientfd will be closed. clientfd:%d, "
38
client_fd_info.client_fd, client_fd_info.client_gid, errno);
39
if (client_fd_info.client_fd >= 0) {
40
shutdown(client_fd_info.client_fd, SHUT_WR);
41
if (0 != libc_epoll_ctl(client_fd_info.org_epfd, EPOLL_CTL_ADD,
42
client_fd_info.client_fd, &client_fd_info.event)) {
43
ussl_log_error("give back fd to origin epoll failed, fd:%d, errno:%d",
44
client_fd_info.client_fd, errno);
48
memcpy(&clientfd_sk->fd_info, &client_fd_info, sizeof(client_fd_info));
49
clientfd_sk->fd = client_fd_info.client_fd;
50
clientfd_sk->ep = s->ep;
51
if (0 != ussl_eloop_regist(clientfd_sk->ep, (ussl_sock_t *)clientfd_sk, EPOLLOUT)) {
52
ussl_log_warn("[pipefd_handle_event] call eloop_regist failed, the clientfd will be "
53
"closed. clientfd:%d, gid:0x%lx, errno:%d",
54
client_fd_info.client_fd, client_fd_info.client_gid, errno);
55
if (client_fd_info.client_fd >= 0) {
56
shutdown(client_fd_info.client_fd, SHUT_WR);
57
if (0 != libc_epoll_ctl(client_fd_info.org_epfd, EPOLL_CTL_ADD,
58
client_fd_info.client_fd, &client_fd_info.event)) {
59
ussl_log_warn("give back fd to origin epoll failed, fd:%d, errno:%d",
60
client_fd_info.client_fd, errno);
63
s->fty->destroy(s->fty, (ussl_sock_t *)clientfd_sk);
71
int pipefd_init(ussl_eloop_t *ep, pipefd_t *s, ussl_sf_t *sf, int fd)
74
ussl_sk_init((ussl_sock_t *)s, sf, (void *)pipefd_handle_event, fd);
79
ussl_log_error("pipefd is initialized with an invalid fd, errno:%d", errno);
80
} else if (0 != (ret = ussl_eloop_regist(ep, (ussl_sock_t *)s, EPOLLIN))) {
81
ussl_log_error("regist pipefd failed, ret:%d", ret);