MCPcopy Create free account
hub / github.com/Tencent/libco / accept_routine

Function accept_routine

example_echosvr.cpp:109–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108int co_accept(int fd, struct sockaddr *addr, socklen_t *len );
109static void *accept_routine( void * )
110{
111 co_enable_hook_sys();
112 printf("accept_routine\n");
113 fflush(stdout);
114 for(;;)
115 {
116 //printf("pid %ld g_readwrite.size %ld\n",getpid(),g_readwrite.size());
117 if( g_readwrite.empty() )
118 {
119 printf("empty\n"); //sleep
120 struct pollfd pf = { 0 };
121 pf.fd = -1;
122 poll( &pf,1,1000);
123
124 continue;
125
126 }
127 struct sockaddr_in addr; //maybe sockaddr_un;
128 memset( &addr,0,sizeof(addr) );
129 socklen_t len = sizeof(addr);
130
131 int fd = co_accept(g_listen_fd, (struct sockaddr *)&addr, &len);
132 if( fd < 0 )
133 {
134 struct pollfd pf = { 0 };
135 pf.fd = g_listen_fd;
136 pf.events = (POLLIN|POLLERR|POLLHUP);
137 co_poll( co_get_epoll_ct(),&pf,1,1000 );
138 continue;
139 }
140 if( g_readwrite.empty() )
141 {
142 close( fd );
143 continue;
144 }
145 SetNonBlock( fd );
146 task_t *co = g_readwrite.top();
147 co->fd = fd;
148 g_readwrite.pop();
149 co_resume( co->co );
150 }
151 return 0;
152}
153
154static void SetAddr(const char *pszIP,const unsigned short shPort,struct sockaddr_in &addr)
155{

Callers

nothing calls this directly

Calls 8

co_enable_hook_sysFunction · 0.85
pollFunction · 0.85
co_acceptFunction · 0.85
co_pollFunction · 0.85
co_get_epoll_ctFunction · 0.85
closeFunction · 0.85
co_resumeFunction · 0.85
SetNonBlockFunction · 0.70

Tested by

no test coverage detected