| 62 | } |
| 63 | |
| 64 | static 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 | } |
| 108 | int co_accept(int fd, struct sockaddr *addr, socklen_t *len ); |
| 109 | static void *accept_routine( void * ) |
| 110 | { |
nothing calls this directly
no test coverage detected