代码拉取完成,页面将自动刷新
同步操作将从 郭新华/php-cp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
+----------------------------------------------------------------------+
| common con pool |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Xinhua Guo <woshiguo35@sina.com> |
+----------------------------------------------------------------------+
*/
#include "php_connect_pool.h"
int cpEpoll_add(int epfd, int fd, int fdtype) {
struct epoll_event e;
int ret;
bzero(&e, sizeof (struct epoll_event));
e.data.fd = fd;
e.events = fdtype;
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &e);
if (ret < 0)
{
cpLog("add event fail. Error: %s[%d]", strerror(errno), errno);
return FAILURE;
}
return SUCCESS;
}
int cpEpoll_del(int epfd, int fd) {
struct epoll_event e;
int ret;
e.data.fd = fd;
if (fd <= 0)
{
return FAILURE;
}
// e.events = EPOLLIN | EPOLLET | EPOLLOUT;
ret = epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &e);
if (ret < 0)
{
cpLog("epoll remove fd[=%d] fail. Error: %s[%d]", fd, strerror(errno), errno);
return SUCCESS;
}
//close时会自动从epoll事件中移除
ret = close(fd);
return SUCCESS;
}
CPINLINE int cpReactor_error() {
switch (errno)
{
case EINTR:
return SUCCESS;
}
return FAILURE;
}
int cpEpoll_wait(epoll_wait_handle *handles, struct timeval *timeo, int epfd) {
int i, n, ret, usec;
// int pack_size = sizeof (uint32_t)*8;
if (timeo == NULL)
{
usec = CP_MAX_UINT;
}
else
{
usec = timeo->tv_sec * 1000 + timeo->tv_usec / 1000;
}
// uint8_t *run;
// if (CPGL.process_type == CP_PROCESS_WORKER) {
// run = &CPGS->workers[CPWG.id].run;
// } else {
// run = &CPGL.running;
// }
struct epoll_event events[CP_REACTOR_MAXEVENTS];
while (CPGS->running)
{
n = epoll_wait(epfd, events, CP_REACTOR_MAXEVENTS, usec);
for (i = 0; i < n; i++)
{
//取出事件
// ev.fd = object->events[i].data.u64;
// ev.type = object->events[i].data.u64 >> pack_size;
// if (events[i].events & EPOLLPRI) {
// char buf[1];
// ret = handles[EPOLLPRI](events[i].data.fd);
// recv(events[i].data.fd, buf, 1, MSG_OOB);
// if (ret < 0) {
// cpLog("epoll [EPOLLPRI] handle failed. fd=%d. Error: %s[%d]", events[i].data.fd,
// strerror(errno), errno);
// }
// }
if (events[i].events & EPOLLIN)
{
ret = handles[EPOLLIN](events[i].data.fd);
if (ret < 0)
{
cpLog("epoll [EPOLLIN] handle failed. fd=%d. Error: %s[%d]", events[i].data.fd,
strerror(errno), errno);
}
}
else if (events[i].events & EPOLLOUT)
{
ret = handles[EPOLLIN](events[i].data.fd);
if (ret < 0)
{
cpLog("epoll [EPOLLOUT] handle failed. fd=%d. Error: %s[%d]", events[i].data.fd,
strerror(errno), errno);
}
}
#ifndef NO_EPOLLRDHUP
else if ((events[i].events & (EPOLLRDHUP | EPOLLERR | EPOLLHUP)))
#else
else if ((events[i].events & (EPOLLERR | EPOLLHUP)))
#endif
{
if (events[i].data.fd > 0)
{
ret = handles[EPOLL_CLOSE](events[i].data.fd);
if (ret < 0)
{
cpLog("epoll [EPOLLRDHUP] handle failed. fd=%d. Error: %s[%d]", events[i].data.fd, strerror(errno), errno);
}
}
}
}
if (n < 0)
{
if (cpReactor_error() < 0)
{
cpLog("Epoll[#%d] Error: %s[%d]", events[i].data.fd, strerror(errno), errno);
return FAILURE;
}
}
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。