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

Function readwrite_routine

example_echosvr.cpp:64–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64static void *readwrite_routine( void *arg )
65{
66
67 co_enable_hook_sys();
68
69 task_t *co = (task_t*)arg;
70 char buf[ 1024 * 16 ];
71 for(;;)
72 {
73 if( -1 == co->fd )
74 {
75 g_readwrite.push( co );
76 co_yield_ct();
77 continue;
78 }
79
80 int fd = co->fd;
81 co->fd = -1;
82
83 for(;;)
84 {
85 struct pollfd pf = { 0 };
86 pf.fd = fd;
87 pf.events = (POLLIN|POLLERR|POLLHUP);
88 co_poll( co_get_epoll_ct(),&pf,1,1000);
89
90 int ret = read( fd,buf,sizeof(buf) );
91 if( ret > 0 )
92 {
93 ret = write( fd,buf,ret );
94 }
95 if( ret <= 0 )
96 {
97 // accept_routine->SetNonBlock(fd) cause EAGAIN, we should continue
98 if (errno == EAGAIN)
99 continue;
100 close( fd );
101 break;
102 }
103 }
104
105 }
106 return 0;
107}
108int co_accept(int fd, struct sockaddr *addr, socklen_t *len );
109static void *accept_routine( void * )
110{

Callers

nothing calls this directly

Calls 7

co_enable_hook_sysFunction · 0.85
co_yield_ctFunction · 0.85
co_pollFunction · 0.85
co_get_epoll_ctFunction · 0.85
readFunction · 0.85
writeFunction · 0.85
closeFunction · 0.85

Tested by

no test coverage detected