int mz_epoll(void)
{
int listenfd,socketfd;
int epollfd,fds;
struct epoll_event en,evevts[MAX_EVENTS]
int i,rv;
epollfd = get_server_epoll_fd();
listenfd = ipv4_tcp_create_socket();
ipv4_socket_nonblock(listenfd);
rv =ipv4_epoll_add_event_by_fd(listenfd);
if(rv < 0){
return -1;
}
while(1){
//timeout
fds = epoll_wait(epollfd,events,MAX_EVENTS);
if(fds < 0){
if(errno == EINTR){
m_log(M_ERR,"skip Interrupted system call err.\n");
continue;
}
m_log(M_ERR,"epoll_wait err:%s\n",strerror(errno));
for(i = 0;i < fds;i++)
{
if(events[i].data.fd == listenfd)
{
new_client_init(listenfd);
continue;
}
else
{
m_log(LOG_DEBUG,"recv data.\n");
rv = process_data(events[i].fata.ptr);
if(rv == CLIENT_CLOSE)
{
rv = ipv4_epoll_delete_events(&envents[i]);
if(rv < 0)
{
m_log(LOG_DEBUG,"epoll delete error.\n");
}
continue;
}
}
}
}
}
}
int main(int argc,char *argv[])
{
server_init();
mz_epoll();
................
.......................
}
一个嵌入式linux项目的流程以及rshell的介绍
最新推荐文章于 2024-08-31 07:21:12 发布