| 150 | } |
| 151 | |
| 152 | static void run_server(const char *addr) |
| 153 | { |
| 154 | ACL_VSTREAM *sstream = acl_vstream_listen(addr, 128); |
| 155 | acl_pthread_pool_t *pool; |
| 156 | CONN *conn; |
| 157 | acl_pthread_t tid; |
| 158 | acl_pthread_attr_t attr; |
| 159 | ACL_VSTREAM *client; |
| 160 | |
| 161 | if (sstream == NULL) { |
| 162 | acl_msg_error("listen %s error(%s)", addr, acl_last_serror()); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | pthread_attr_init(&attr); |
| 167 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 168 | |
| 169 | printf("listening on %s ...\n", addr); |
| 170 | pool = acl_thread_pool_create(10, 10); |
| 171 | while (1) { |
| 172 | acl_mem_slice_delay_destroy(); |
| 173 | if (acl_read_wait(ACL_VSTREAM_SOCK(sstream), 5) == -1) |
| 174 | continue; |
| 175 | client = acl_vstream_accept(sstream, NULL, 0); |
| 176 | if (client == NULL) { |
| 177 | acl_msg_error("accept error(%s)", acl_last_serror()); |
| 178 | break; |
| 179 | } |
| 180 | acl_tcp_set_nodelay(ACL_VSTREAM_SOCK(client)); |
| 181 | conn = acl_mycalloc(1, sizeof(CONN)); |
| 182 | conn->stream = client; |
| 183 | |
| 184 | if (0) |
| 185 | thread_run(conn); |
| 186 | else if (1) |
| 187 | acl_pthread_create(&tid, &attr, thread_main, conn); |
| 188 | else |
| 189 | acl_pthread_pool_add(pool, thread_run, conn); |
| 190 | } |
| 191 | |
| 192 | acl_vstream_close(sstream); |
| 193 | } |
| 194 | |
| 195 | static void run_client(const char *addr, const char *filename) |
| 196 | { |
no test coverage detected
searching dependent graphs…