| 99 | } |
| 100 | |
| 101 | static void *readwrite_routine( void *arg ) |
| 102 | { |
| 103 | |
| 104 | co_enable_hook_sys(); |
| 105 | |
| 106 | stEndPoint *endpoint = (stEndPoint *)arg; |
| 107 | char str[8]="sarlmol"; |
| 108 | char buf[ 1024 * 16 ]; |
| 109 | int fd = -1; |
| 110 | int ret = 0; |
| 111 | for(;;) |
| 112 | { |
| 113 | if ( fd < 0 ) |
| 114 | { |
| 115 | fd = socket(PF_INET, SOCK_STREAM, 0); |
| 116 | struct sockaddr_in addr; |
| 117 | SetAddr(endpoint->ip, endpoint->port, addr); |
| 118 | ret = connect(fd,(struct sockaddr*)&addr,sizeof(addr)); |
| 119 | |
| 120 | if ( errno == EALREADY || errno == EINPROGRESS ) |
| 121 | { |
| 122 | struct pollfd pf = { 0 }; |
| 123 | pf.fd = fd; |
| 124 | pf.events = (POLLOUT|POLLERR|POLLHUP); |
| 125 | co_poll( co_get_epoll_ct(),&pf,1,200); |
| 126 | //check connect |
| 127 | int error = 0; |
| 128 | uint32_t socklen = sizeof(error); |
| 129 | errno = 0; |
| 130 | ret = getsockopt(fd, SOL_SOCKET, SO_ERROR,(void *)&error, &socklen); |
| 131 | if ( ret == -1 ) |
| 132 | { |
| 133 | //printf("getsockopt ERROR ret %d %d:%s\n", ret, errno, strerror(errno)); |
| 134 | close(fd); |
| 135 | fd = -1; |
| 136 | AddFailCnt(); |
| 137 | continue; |
| 138 | } |
| 139 | if ( error ) |
| 140 | { |
| 141 | errno = error; |
| 142 | //printf("connect ERROR ret %d %d:%s\n", error, errno, strerror(errno)); |
| 143 | close(fd); |
| 144 | fd = -1; |
| 145 | AddFailCnt(); |
| 146 | continue; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | } |
| 151 | |
| 152 | ret = write( fd,str, 8); |
| 153 | if ( ret > 0 ) |
| 154 | { |
| 155 | ret = read( fd,buf, sizeof(buf) ); |
| 156 | if ( ret <= 0 ) |
| 157 | { |
| 158 | //printf("co %p read ret %d errno %d (%s)\n", |
nothing calls this directly
no test coverage detected