You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

698 lines
21 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
11 years ago
11 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
11 years ago
11 years ago
12 years ago
  1. #include <sys/socket.h>
  2. #include <sys/stat.h>
  3. #include <sys/types.h>
  4. #include <arpa/inet.h>
  5. #include <errno.h>
  6. #include <fcntl.h>
  7. #include <locale.h>
  8. #include <netdb.h>
  9. #include <netinet/in.h>
  10. #include <netinet/tcp.h>
  11. #include <pthread.h>
  12. #include <signal.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <strings.h>
  17. #include <time.h>
  18. #include <unistd.h>
  19. #include <assert.h>
  20. #include "utils.h"
  21. #include "local.h"
  22. #include "socks5.h"
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #ifndef EAGAIN
  27. #define EAGAIN EWOULDBLOCK
  28. #endif
  29. #ifndef EWOULDBLOCK
  30. #define EWOULDBLOCK EAGAIN
  31. #endif
  32. #define min(a,b) (((a)<(b))?(a):(b))
  33. int setnonblocking(int fd) {
  34. int flags;
  35. if (-1 ==(flags = fcntl(fd, F_GETFL, 0)))
  36. flags = 0;
  37. return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  38. }
  39. int create_and_bind(const char *port) {
  40. struct addrinfo hints;
  41. struct addrinfo *result, *rp;
  42. int s, listen_sock;
  43. memset(&hints, 0, sizeof(struct addrinfo));
  44. hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */
  45. hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */
  46. s = getaddrinfo("0.0.0.0", port, &hints, &result);
  47. if (s != 0) {
  48. LOGD("getaddrinfo: %s\n", gai_strerror(s));
  49. return -1;
  50. }
  51. for (rp = result; rp != NULL; rp = rp->ai_next) {
  52. listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  53. if (listen_sock == -1)
  54. continue;
  55. int opt = 1;
  56. int err = setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
  57. if (err) {
  58. perror("setsocket");
  59. }
  60. s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
  61. if (s == 0) {
  62. /* We managed to bind successfully! */
  63. break;
  64. } else {
  65. perror("bind");
  66. }
  67. close(listen_sock);
  68. }
  69. if (rp == NULL) {
  70. LOGE("Could not bind\n");
  71. return -1;
  72. }
  73. freeaddrinfo(result);
  74. return listen_sock;
  75. }
  76. static void server_recv_cb (EV_P_ ev_io *w, int revents) {
  77. struct server_ctx *server_recv_ctx = (struct server_ctx *)w;
  78. struct server *server = server_recv_ctx->server;
  79. struct remote *remote = server->remote;
  80. if (remote == NULL) {
  81. close_and_free_server(EV_A_ server);
  82. return;
  83. }
  84. while (1) {
  85. char *buf = remote->buf;
  86. int *buf_len = &remote->buf_len;
  87. if (server->stage != 5) {
  88. buf = server->buf;
  89. buf_len = &server->buf_len;
  90. }
  91. ssize_t r = recv(server->fd, buf, BUF_SIZE, 0);
  92. if (r == 0) {
  93. // connection closed
  94. *buf_len = 0;
  95. close_and_free_remote(EV_A_ remote);
  96. close_and_free_server(EV_A_ server);
  97. return;
  98. } else if(r < 0) {
  99. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  100. // no data
  101. // continue to wait for recv
  102. break;
  103. } else {
  104. perror("server recv");
  105. close_and_free_remote(EV_A_ remote);
  106. close_and_free_server(EV_A_ server);
  107. return;
  108. }
  109. }
  110. // local socks5 server
  111. if (server->stage == 5) {
  112. encrypt_ctx(remote->buf, r, server->e_ctx);
  113. int w = send(remote->fd, remote->buf, r, 0);
  114. if(w == -1) {
  115. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  116. // no data, wait for send
  117. remote->buf_len = r;
  118. ev_io_stop(EV_A_ &server_recv_ctx->io);
  119. ev_io_start(EV_A_ &remote->send_ctx->io);
  120. break;
  121. } else {
  122. perror("send");
  123. close_and_free_remote(EV_A_ remote);
  124. close_and_free_server(EV_A_ server);
  125. return;
  126. }
  127. } else if(w < r) {
  128. char *pt = remote->buf;
  129. char *et = pt + r;
  130. while (pt + w < et) {
  131. *pt = *(pt + w);
  132. pt++;
  133. }
  134. remote->buf_len = r - w;
  135. assert(remote->buf_len >= 0);
  136. ev_io_stop(EV_A_ &server_recv_ctx->io);
  137. ev_io_start(EV_A_ &remote->send_ctx->io);
  138. break;
  139. }
  140. } else if (server->stage == 0) {
  141. struct method_select_response response;
  142. response.ver = SVERSION;
  143. response.method = 0;
  144. char *send_buf = (char *)&response;
  145. send(server->fd, send_buf, sizeof(response), 0);
  146. server->stage = 1;
  147. return;
  148. } else if (server->stage == 1) {
  149. struct socks5_request *request = (struct socks5_request *)server->buf;
  150. if (request->cmd != 1) {
  151. LOGE("unsupported cmd: %d\n", request->cmd);
  152. struct socks5_response response;
  153. response.ver = SVERSION;
  154. response.rep = CMD_NOT_SUPPORTED;
  155. response.rsv = 0;
  156. response.atyp = 1;
  157. char *send_buf = (char *)&response;
  158. send(server->fd, send_buf, 4, 0);
  159. close_and_free_remote(EV_A_ remote);
  160. close_and_free_server(EV_A_ server);
  161. return;
  162. }
  163. char addr_to_send[256];
  164. uint8_t addr_len = 0;
  165. addr_to_send[addr_len++] = request->atyp;
  166. // get remote addr and port
  167. if (request->atyp == 1) {
  168. // IP V4
  169. size_t in_addr_len = sizeof(struct in_addr);
  170. memcpy(addr_to_send + addr_len, server->buf + 4, in_addr_len + 2);
  171. addr_len += in_addr_len + 2;
  172. } else if (request->atyp == 3) {
  173. // Domain name
  174. uint8_t name_len = *(uint8_t *)(server->buf + 4);
  175. addr_to_send[addr_len++] = name_len;
  176. memcpy(addr_to_send + addr_len, server->buf + 4 + 1, name_len);
  177. addr_len += name_len;
  178. // get port
  179. addr_to_send[addr_len++] = *(uint8_t *)(server->buf + 4 + 1 + name_len);
  180. addr_to_send[addr_len++] = *(uint8_t *)(server->buf + 4 + 1 + name_len + 1);
  181. } else {
  182. LOGE("unsupported addrtype: %d\n", request->atyp);
  183. close_and_free_remote(EV_A_ remote);
  184. close_and_free_server(EV_A_ server);
  185. return;
  186. }
  187. encrypt_ctx(addr_to_send, addr_len, server->e_ctx);
  188. send(remote->fd, addr_to_send, addr_len, 0);
  189. // Fake reply
  190. struct socks5_response response;
  191. response.ver = SVERSION;
  192. response.rep = 0;
  193. response.rsv = 0;
  194. response.atyp = 1;
  195. struct in_addr sin_addr;
  196. inet_aton("0.0.0.0", &sin_addr);
  197. memcpy(server->buf, &response, 4);
  198. memset(server->buf + 4, 0, sizeof(struct in_addr) + sizeof(uint16_t));
  199. int reply_size = 4 + sizeof(struct in_addr) + sizeof(uint16_t);
  200. int r = send(server->fd, server->buf, reply_size, 0);
  201. if (r < reply_size) {
  202. LOGE("header not complete sent\n");
  203. close_and_free_remote(EV_A_ remote);
  204. close_and_free_server(EV_A_ server);
  205. return;
  206. }
  207. server->stage = 5;
  208. }
  209. }
  210. }
  211. static void server_send_cb (EV_P_ ev_io *w, int revents) {
  212. struct server_ctx *server_send_ctx = (struct server_ctx *)w;
  213. struct server *server = server_send_ctx->server;
  214. struct remote *remote = server->remote;
  215. if (server->buf_len == 0) {
  216. // close and free
  217. close_and_free_remote(EV_A_ remote);
  218. close_and_free_server(EV_A_ server);
  219. return;
  220. } else {
  221. // has data to send
  222. ssize_t r = send(server->fd, server->buf,
  223. server->buf_len, 0);
  224. if (r < 0) {
  225. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  226. perror("send");
  227. close_and_free_remote(EV_A_ remote);
  228. close_and_free_server(EV_A_ server);
  229. }
  230. return;
  231. }
  232. if (r < server->buf_len) {
  233. // partly sent, move memory, wait for the next time to send
  234. char *pt = server->buf;
  235. char *et = pt + server->buf_len;
  236. while (pt + r < et) {
  237. *pt = *(pt + r);
  238. pt++;
  239. }
  240. server->buf_len -= r;
  241. assert(server->buf_len >= 0);
  242. return;
  243. } else {
  244. // all sent out, wait for reading
  245. ev_io_stop(EV_A_ &server_send_ctx->io);
  246. if (remote != NULL) {
  247. ev_io_start(EV_A_ &remote->recv_ctx->io);
  248. } else {
  249. close_and_free_remote(EV_A_ remote);
  250. close_and_free_server(EV_A_ server);
  251. return;
  252. }
  253. }
  254. }
  255. }
  256. static void remote_timeout_cb(EV_P_ ev_timer *watcher, int revents) {
  257. struct remote_ctx *remote_ctx = (struct remote_ctx *) (((void*)watcher)
  258. - sizeof(ev_io));
  259. struct remote *remote = remote_ctx->remote;
  260. struct server *server = remote->server;
  261. LOGD("remote timeout\n");
  262. ev_timer_stop(EV_A_ watcher);
  263. if (server == NULL) {
  264. close_and_free_remote(EV_A_ remote);
  265. return;
  266. }
  267. close_and_free_remote(EV_A_ remote);
  268. close_and_free_server(EV_A_ server);
  269. }
  270. static void remote_recv_cb (EV_P_ ev_io *w, int revents) {
  271. struct remote_ctx *remote_recv_ctx = (struct remote_ctx *)w;
  272. struct remote *remote = remote_recv_ctx->remote;
  273. struct server *server = remote->server;
  274. if (server == NULL) {
  275. close_and_free_remote(EV_A_ remote);
  276. return;
  277. }
  278. while (1) {
  279. ssize_t r = recv(remote->fd, server->buf, BUF_SIZE, 0);
  280. if (r == 0) {
  281. // connection closed
  282. server->buf_len = 0;
  283. close_and_free_remote(EV_A_ remote);
  284. close_and_free_server(EV_A_ server);
  285. return;
  286. } else if(r < 0) {
  287. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  288. // no data
  289. // continue to wait for recv
  290. break;
  291. } else {
  292. perror("remote recv");
  293. close_and_free_remote(EV_A_ remote);
  294. close_and_free_server(EV_A_ server);
  295. return;
  296. }
  297. }
  298. decrypt_ctx(server->buf, r, server->d_ctx);
  299. int w = send(server->fd, server->buf, r, 0);
  300. if(w == -1) {
  301. if (errno == EAGAIN || errno == EWOULDBLOCK) {
  302. // no data, wait for send
  303. server->buf_len = r;
  304. ev_io_stop(EV_A_ &remote_recv_ctx->io);
  305. ev_io_start(EV_A_ &server->send_ctx->io);
  306. break;
  307. } else {
  308. perror("send");
  309. close_and_free_remote(EV_A_ remote);
  310. close_and_free_server(EV_A_ server);
  311. return;
  312. }
  313. } else if(w < r) {
  314. char *pt = server->buf;
  315. char *et = pt + r;
  316. while (pt + w < et) {
  317. *pt = *(pt + w);
  318. pt++;
  319. }
  320. server->buf_len = r - w;
  321. assert(server->buf_len >= 0);
  322. ev_io_stop(EV_A_ &remote_recv_ctx->io);
  323. ev_io_start(EV_A_ &server->send_ctx->io);
  324. break;
  325. }
  326. }
  327. }
  328. static void remote_send_cb (EV_P_ ev_io *w, int revents) {
  329. struct remote_ctx *remote_send_ctx = (struct remote_ctx *)w;
  330. struct remote *remote = remote_send_ctx->remote;
  331. struct server *server = remote->server;
  332. if (!remote_send_ctx->connected) {
  333. struct sockaddr_storage addr;
  334. socklen_t len = sizeof addr;
  335. int r = getpeername(remote->fd, (struct sockaddr*)&addr, &len);
  336. if (r == 0) {
  337. remote_send_ctx->connected = 1;
  338. ev_io_stop(EV_A_ &remote_send_ctx->io);
  339. ev_timer_stop(EV_A_ &remote_send_ctx->watcher);
  340. ev_io_start(EV_A_ &server->recv_ctx->io);
  341. ev_io_start(EV_A_ &remote->recv_ctx->io);
  342. return;
  343. } else {
  344. perror("getpeername");
  345. // not connected
  346. close_and_free_remote(EV_A_ remote);
  347. close_and_free_server(EV_A_ server);
  348. return;
  349. }
  350. } else {
  351. if (remote->buf_len == 0) {
  352. // close and free
  353. close_and_free_remote(EV_A_ remote);
  354. close_and_free_server(EV_A_ server);
  355. return;
  356. } else {
  357. // has data to send
  358. ssize_t r = send(remote->fd, remote->buf,
  359. remote->buf_len, 0);
  360. if (r < 0) {
  361. if (errno != EAGAIN && errno != EWOULDBLOCK) {
  362. perror("send");
  363. // close and free
  364. close_and_free_remote(EV_A_ remote);
  365. close_and_free_server(EV_A_ server);
  366. }
  367. return;
  368. }
  369. if (r < remote->buf_len) {
  370. // partly sent, move memory, wait for the next time to send
  371. char *pt = remote->buf;
  372. char *et = pt + remote->buf_len;
  373. while (pt + r < et) {
  374. *pt = *(pt + r);
  375. pt++;
  376. }
  377. remote->buf_len -= r;
  378. assert(remote->buf_len >= 0);
  379. return;
  380. } else {
  381. // all sent out, wait for reading
  382. ev_io_stop(EV_A_ &remote_send_ctx->io);
  383. if (server != NULL) {
  384. ev_io_start(EV_A_ &server->recv_ctx->io);
  385. } else {
  386. close_and_free_remote(EV_A_ remote);
  387. close_and_free_server(EV_A_ server);
  388. return;
  389. }
  390. }
  391. }
  392. }
  393. }
  394. struct remote* new_remote(int fd, int timeout) {
  395. struct remote *remote;
  396. remote = malloc(sizeof(struct remote));
  397. remote->recv_ctx = malloc(sizeof(struct remote_ctx));
  398. remote->send_ctx = malloc(sizeof(struct remote_ctx));
  399. remote->fd = fd;
  400. ev_io_init(&remote->recv_ctx->io, remote_recv_cb, fd, EV_READ);
  401. ev_io_init(&remote->send_ctx->io, remote_send_cb, fd, EV_WRITE);
  402. ev_timer_init(&remote->send_ctx->watcher, remote_timeout_cb, timeout, 0);
  403. remote->recv_ctx->remote = remote;
  404. remote->recv_ctx->connected = 0;
  405. remote->send_ctx->remote = remote;
  406. remote->send_ctx->connected = 0;
  407. remote->buf_len = 0;
  408. return remote;
  409. }
  410. void free_remote(struct remote *remote) {
  411. if (remote != NULL) {
  412. if (remote->server != NULL) {
  413. remote->server->remote = NULL;
  414. }
  415. free(remote->recv_ctx);
  416. free(remote->send_ctx);
  417. free(remote);
  418. }
  419. }
  420. void close_and_free_remote(EV_P_ struct remote *remote) {
  421. if (remote != NULL) {
  422. ev_timer_stop(EV_A_ &remote->send_ctx->watcher);
  423. ev_io_stop(EV_A_ &remote->send_ctx->io);
  424. ev_io_stop(EV_A_ &remote->recv_ctx->io);
  425. close(remote->fd);
  426. free_remote(remote);
  427. }
  428. }
  429. struct server* new_server(int fd) {
  430. struct server *server;
  431. server = malloc(sizeof(struct server));
  432. server->recv_ctx = malloc(sizeof(struct server_ctx));
  433. server->send_ctx = malloc(sizeof(struct server_ctx));
  434. server->fd = fd;
  435. ev_io_init(&server->recv_ctx->io, server_recv_cb, fd, EV_READ);
  436. ev_io_init(&server->send_ctx->io, server_send_cb, fd, EV_WRITE);
  437. server->recv_ctx->server = server;
  438. server->recv_ctx->connected = 0;
  439. server->send_ctx->server = server;
  440. server->send_ctx->connected = 0;
  441. server->stage = 0;
  442. if (enc_conf.method == RC4) {
  443. server->e_ctx = malloc(sizeof(struct rc4_state));
  444. server->d_ctx = malloc(sizeof(struct rc4_state));
  445. enc_ctx_init(server->e_ctx, 1);
  446. enc_ctx_init(server->d_ctx, 0);
  447. } else {
  448. server->e_ctx = NULL;
  449. server->d_ctx = NULL;
  450. }
  451. server->buf_len = 0;
  452. return server;
  453. }
  454. void free_server(struct server *server) {
  455. if (server != NULL) {
  456. if (server->remote != NULL) {
  457. server->remote->server = NULL;
  458. }
  459. if (enc_conf.method == RC4) {
  460. free(server->e_ctx);
  461. free(server->d_ctx);
  462. }
  463. free(server->recv_ctx);
  464. free(server->send_ctx);
  465. free(server);
  466. }
  467. }
  468. void close_and_free_server(EV_P_ struct server *server) {
  469. if (server != NULL) {
  470. ev_io_stop(EV_A_ &server->send_ctx->io);
  471. ev_io_stop(EV_A_ &server->recv_ctx->io);
  472. close(server->fd);
  473. free_server(server);
  474. }
  475. }
  476. static void accept_cb (EV_P_ ev_io *w, int revents) {
  477. struct listen_ctx *listener = (struct listen_ctx *)w;
  478. int serverfd = accept(listener->fd, NULL, NULL);
  479. if (serverfd == -1) {
  480. perror("accept");
  481. return;
  482. }
  483. setnonblocking(serverfd);
  484. struct addrinfo hints, *res;
  485. int sockfd;
  486. memset(&hints, 0, sizeof hints);
  487. hints.ai_family = AF_UNSPEC;
  488. hints.ai_socktype = SOCK_STREAM;
  489. int index = clock() % listener->remote_num;
  490. int err = getaddrinfo(listener->remote_host[index], listener->remote_port, &hints, &res);
  491. if (err) {
  492. perror("getaddrinfo");
  493. return;
  494. }
  495. sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  496. if (sockfd < 0) {
  497. perror("socket");
  498. close(sockfd);
  499. freeaddrinfo(res);
  500. return;
  501. }
  502. struct timeval timeout;
  503. timeout.tv_sec = listener->timeout;
  504. timeout.tv_usec = 0;
  505. err = setsockopt(sockfd, SOL_SOCKET,
  506. SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  507. if (err) perror("setsockopt");
  508. err = setsockopt(sockfd, SOL_SOCKET,
  509. SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
  510. if (err) perror("setsockopt");
  511. setnonblocking(sockfd);
  512. struct server *server = new_server(serverfd);
  513. struct remote *remote = new_remote(sockfd, listener->timeout);
  514. server->remote = remote;
  515. remote->server = server;
  516. connect(sockfd, res->ai_addr, res->ai_addrlen);
  517. freeaddrinfo(res);
  518. // listen to remote connected event
  519. ev_io_start(EV_A_ &remote->send_ctx->io);
  520. ev_timer_start(EV_A_ &remote->send_ctx->watcher);
  521. }
  522. int main (int argc, char **argv) {
  523. int i, c;
  524. int pid_flags = 0;
  525. char *local_port = NULL;
  526. char *password = NULL;
  527. char *timeout = NULL;
  528. char *method = NULL;
  529. char *pid_path = NULL;
  530. char *conf_path = NULL;
  531. int remote_num = 0;
  532. char *remote_host[MAX_REMOTE_NUM];
  533. char *remote_port = NULL;
  534. opterr = 0;
  535. while ((c = getopt (argc, argv, "f:s:p:l:k:t:m:c:")) != -1) {
  536. switch (c) {
  537. case 's':
  538. remote_host[remote_num++] = optarg;
  539. break;
  540. case 'p':
  541. remote_port = optarg;
  542. break;
  543. case 'l':
  544. local_port = optarg;
  545. break;
  546. case 'k':
  547. password = optarg;
  548. break;
  549. case 'f':
  550. pid_flags = 1;
  551. pid_path = optarg;
  552. break;
  553. case 't':
  554. timeout = optarg;
  555. break;
  556. case 'm':
  557. method = optarg;
  558. break;
  559. case 'c':
  560. conf_path = optarg;
  561. break;
  562. }
  563. }
  564. if (opterr) {
  565. usage();
  566. exit(EXIT_FAILURE);
  567. }
  568. if (conf_path != NULL) {
  569. jconf_t *conf = read_jconf(conf_path);
  570. if (remote_num == 0) {
  571. remote_num = conf->remote_num;
  572. for (i = 0; i < remote_num; i++) {
  573. remote_host[i] = conf->remote_host[i];
  574. }
  575. }
  576. if (remote_port == NULL) remote_port = conf->remote_port;
  577. if (local_port == NULL) local_port = conf->local_port;
  578. if (password == NULL) password = conf->password;
  579. if (method == NULL) method = conf->method;
  580. if (timeout == NULL) timeout = conf->timeout;
  581. }
  582. if (remote_num == 0 || remote_port == NULL ||
  583. local_port == NULL || password == NULL) {
  584. usage();
  585. exit(EXIT_FAILURE);
  586. }
  587. if (timeout == NULL) timeout = "10";
  588. if (pid_flags) {
  589. demonize(pid_path);
  590. }
  591. // ignore SIGPIPE
  592. signal(SIGPIPE, SIG_IGN);
  593. // Setup keys
  594. LOGD("calculating ciphers...\n");
  595. enc_conf_init(password, method);
  596. // Setup socket
  597. int listenfd;
  598. listenfd = create_and_bind(local_port);
  599. if (listenfd < 0) {
  600. FATAL("bind() error..\n");
  601. }
  602. if (listen(listenfd, SOMAXCONN) == -1) {
  603. FATAL("listen() error.\n");
  604. }
  605. setnonblocking(listenfd);
  606. LOGD("server listening at port %s.\n", local_port);
  607. // Setup proxy context
  608. struct listen_ctx listen_ctx;
  609. listen_ctx.remote_num = remote_num;
  610. listen_ctx.remote_host = malloc(sizeof(char *) * remote_num);
  611. while (remote_num > 0) {
  612. int index = --remote_num;
  613. listen_ctx.remote_host[index] = strdup(remote_host[index]);
  614. }
  615. listen_ctx.remote_port = strdup(remote_port);
  616. listen_ctx.timeout = atoi(timeout);
  617. listen_ctx.fd = listenfd;
  618. struct ev_loop *loop = ev_default_loop(0);
  619. if (!loop) {
  620. FATAL("ev_loop error.\n");
  621. }
  622. ev_io_init (&listen_ctx.io, accept_cb, listenfd, EV_READ);
  623. ev_io_start (loop, &listen_ctx.io);
  624. ev_run (loop, 0);
  625. return 0;
  626. }