ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) { ssize_t ret; EVENT *ev; if (sockfd < 0) { acl_msg_error("%s: invalid sockfd: %d", __FUNCTION__, sockfd); return -1; } if (!acl_var_hook_sys_api) return __sys_recvmsg(sockfd, msg, flags); ev = fiber_io_event(); if (ev && event_readable(ev, sockfd)) { event_clear_readable(ev, sockfd); ret = __sys_recvmsg(sockfd, msg, flags); if (ret > 0) return ret; fiber_save_errno(); return ret; } fiber_wait_read(sockfd); if (ev) event_clear_readable(ev, sockfd); ret = __sys_recvmsg(sockfd, msg, flags); if (ret > 0) return ret; fiber_save_errno(); return ret; }
ssize_t readv(int fd, const struct iovec *iov, int iovcnt) { ssize_t ret; EVENT *ev; if (fd < 0) { acl_msg_error("%s: invalid fd: %d", __FUNCTION__, fd); return -1; } if (!acl_var_hook_sys_api) return __sys_readv(fd, iov, iovcnt); ev = fiber_io_event(); if (ev && event_readable(ev, fd)) { event_clear_readable(ev, fd); ret = __sys_readv(fd, iov, iovcnt); if (ret > 0) return ret; fiber_save_errno(); return ret; } fiber_wait_read(fd); if (ev) event_clear_readable(ev, fd); ret = __sys_readv(fd, iov, iovcnt); if (ret > 0) return ret; fiber_save_errno(); return ret; }
inline ssize_t fiber_recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen) { ssize_t ret; EVENT *ev; ACL_FIBER *me; if (sockfd < 0) { acl_msg_error("%s: invalid sockfd: %d", __FUNCTION__, sockfd); return -1; } if (!acl_var_hook_sys_api) { if (__sys_recvfrom == NULL) hook_io(); return __sys_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); } ev = fiber_io_event(); if (ev && event_readable(ev, sockfd)) { event_clear_readable(ev, sockfd); ret = __sys_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); if (ret < 0) fiber_save_errno(); return ret; } fiber_wait_read(sockfd); if (ev) event_clear_readable(ev, sockfd); ret = __sys_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); if (ret >= 0) return ret; fiber_save_errno(); me = acl_fiber_running(); if (acl_fiber_killed(me)) { acl_msg_info("%s(%d), %s: fiber-%u is existing", __FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me)); return -1; } return ret; }
inline ssize_t fiber_recvmsg(int sockfd, struct msghdr *msg, int flags) { ssize_t ret; EVENT *ev; ACL_FIBER *me; if (sockfd < 0) { acl_msg_error("%s: invalid sockfd: %d", __FUNCTION__, sockfd); return -1; } if (!acl_var_hook_sys_api) { if (__sys_recvmsg == NULL) hook_io(); return __sys_recvmsg(sockfd, msg, flags); } ev = fiber_io_event(); if (ev && event_readable(ev, sockfd)) { event_clear_readable(ev, sockfd); ret = __sys_recvmsg(sockfd, msg, flags); if (ret < 0) fiber_save_errno(); return ret; } fiber_wait_read(sockfd); if (ev) event_clear_readable(ev, sockfd); ret = __sys_recvmsg(sockfd, msg, flags); if (ret >= 0) return ret; fiber_save_errno(); me = acl_fiber_running(); if (acl_fiber_killed(me)) acl_msg_info("%s(%d), %s: fiber-%u is existing", __FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me)); return ret; }
inline ssize_t fiber_readv(int fd, const struct iovec *iov, int iovcnt) { ssize_t ret; EVENT *ev; ACL_FIBER *me; if (fd < 0) { acl_msg_error("%s: invalid fd: %d", __FUNCTION__, fd); return -1; } if (!acl_var_hook_sys_api) { if (__sys_readv == NULL) hook_io(); return __sys_readv(fd, iov, iovcnt); } ev = fiber_io_event(); if (ev && event_readable(ev, fd)) { event_clear_readable(ev, fd); ret = __sys_readv(fd, iov, iovcnt); if (ret < 0) fiber_save_errno(); return ret; } fiber_wait_read(fd); if (ev) event_clear_readable(ev, fd); ret = __sys_readv(fd, iov, iovcnt); if (ret >= 0) return ret; fiber_save_errno(); me = acl_fiber_running(); if (acl_fiber_killed(me)) acl_msg_info("%s(%d), %s: fiber-%u is existing", __FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me)); return ret; }
inline ssize_t fiber_read(int fd, void *buf, size_t count) { ssize_t ret; EVENT *ev; ACL_FIBER *me; if (fd < 0) { acl_msg_error("%s: invalid fd: %d", __FUNCTION__, fd); return -1; } if (!acl_var_hook_sys_api) return __sys_read(fd, buf, count); ev = fiber_io_event(); if (ev && event_readable(ev, fd)) { event_clear_readable(ev, fd); ret = __sys_read(fd, buf, count); if (ret < 0) fiber_save_errno(); return ret; } fiber_wait_read(fd); if (ev) event_clear_readable(ev, fd); ret = __sys_read(fd, buf, count); if (ret >= 0) return ret; fiber_save_errno(); me = acl_fiber_running(); if (acl_fiber_killed(me)) acl_msg_info("%s(%d), %s: fiber-%d is existing", __FILE__, __LINE__, __FUNCTION__, acl_fiber_id(me)); return ret; }
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen) { ssize_t ret; EVENT *ev; if (sockfd < 0) { acl_msg_error("%s: invalid sockfd: %d", __FUNCTION__, sockfd); return -1; } if (!acl_var_hook_sys_api) return __sys_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); ev = fiber_io_event(); if (ev && event_readable(ev, sockfd)) { event_clear_readable(ev, sockfd); ret = __sys_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); if (ret > 0) return ret; fiber_save_errno(); return ret; } fiber_wait_read(sockfd); if (ev) event_clear_readable(ev, sockfd); ret = __sys_recvfrom(sockfd, buf, len, flags, src_addr, addrlen); if (ret > 0) return ret; fiber_save_errno(); return ret; }