From af7dbbcbc9fe89deb4951d45b0f6ce839199c88b Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 10 Jun 2020 14:51:49 +0200 Subject: Convert proxy to use task_buf as well --- proxy.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'proxy.c') diff --git a/proxy.c b/proxy.c index e5a4eff..98a5af1 100644 --- a/proxy.c +++ b/proxy.c @@ -46,13 +46,8 @@ proxy_client_data_out(struct cfg *cfg, struct uring_task *task, int res) if (res <= 0) return; - if (res != proxy->clientlen) { - fprintf(stderr, "%s: short write\n", __func__); - return; - } - uring_task_set_fd(&proxy->clienttask, proxy->cfd); - uring_read(cfg, task, proxy->clientbuf, sizeof(proxy->clientbuf), 0, proxy_client_data_in); + uring_tbuf_read(cfg, task, proxy_client_data_in); } static void @@ -64,9 +59,8 @@ proxy_client_data_in(struct cfg *cfg, struct uring_task *task, int res) if (res <= 0) return; - proxy->clientlen = res; uring_task_set_fd(&proxy->clienttask, proxy->sfd); - uring_write(cfg, task, proxy->clientbuf, res, proxy_client_data_out); + uring_tbuf_write(cfg, task, proxy_client_data_out); } static void proxy_server_data_in(struct cfg *cfg, struct uring_task *task, int res); @@ -80,13 +74,8 @@ proxy_server_data_out(struct cfg *cfg, struct uring_task *task, int res) if (res <= 0) return; - if (res != proxy->serverlen) { - fprintf(stderr, "%s: short write\n", __func__); - return; - } - uring_task_set_fd(&proxy->servertask, proxy->sfd); - uring_read(cfg, task, proxy->serverbuf, sizeof(proxy->serverbuf), 0, proxy_server_data_in); + uring_tbuf_read(cfg, &proxy->servertask, proxy_server_data_in); } static void @@ -98,9 +87,8 @@ proxy_server_data_in(struct cfg *cfg, struct uring_task *task, int res) if (res <= 0) return; - proxy->serverlen = res; uring_task_set_fd(&proxy->servertask, proxy->cfd); - uring_write(cfg, task, proxy->serverbuf, res, proxy_server_data_out); + uring_tbuf_write(cfg, task, proxy_server_data_out); } static void proxy_connect_next_remote(struct cfg *cfg, struct server_proxy *proxy); @@ -112,12 +100,14 @@ proxy_server_connected(struct cfg *cfg, struct uring_task *task, int res) fprintf(stderr, "%s: connected %i\n", __func__, res); if (res < 0) { + proxy->sfd = -1; + uring_task_close_fd(cfg, task); proxy_connect_next_remote(cfg, proxy); return; } - uring_read(cfg, &proxy->clienttask, proxy->clientbuf, sizeof(proxy->clientbuf), 0, proxy_client_data_in); - uring_read(cfg, &proxy->servertask, proxy->serverbuf, sizeof(proxy->serverbuf), 0, proxy_server_data_in); + uring_tbuf_read(cfg, &proxy->clienttask, proxy_client_data_in); + uring_tbuf_read(cfg, &proxy->servertask, proxy_server_data_in); } static void @@ -178,8 +168,10 @@ proxy_new(struct cfg *cfg, struct server *scfg, struct sockaddr_in46 *client, in proxy->client = *client; sockaddr_to_str(&proxy->client, proxy->clientstr, sizeof(proxy->clientstr)); uring_task_init(&proxy->clienttask, "proxy_client", &scfg->task, proxy_client_free); - uring_task_init(&proxy->servertask, "proxy_server", &scfg->task, proxy_server_free); + uring_task_set_buf(&proxy->clienttask, &proxy->clientbuf); uring_task_set_fd(&proxy->clienttask, fd); + uring_task_init(&proxy->servertask, "proxy_server", &scfg->task, proxy_server_free); + uring_task_set_buf(&proxy->servertask, &proxy->serverbuf); list_add(&proxy->list, &scfg->proxys); proxy_connect_next_remote(cfg, proxy); -- cgit v1.2.3