From 39f3538f7ee56dab414d62201235f8427b4a9592 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 24 Nov 2020 12:15:01 +0100 Subject: Added userspace-based network timeout The network in my whole city is down right now, so I've done some error catching using timeouts etc without the kernel blocking everything. Not having internet is exhausting though :( --- apps/browser.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'apps/browser.c') diff --git a/apps/browser.c b/apps/browser.c index 7f4fc6e..157ddbd 100644 --- a/apps/browser.c +++ b/apps/browser.c @@ -148,11 +148,12 @@ void on_submit(void *event, struct element *box) struct element_label *c = code_label->data; struct socket *socket = net_open(S_TCP); - if (socket && net_connect(socket, ip, 80)) { + if (socket && net_connect(socket, ip, 80, NET_TIMEOUT)) { net_send(socket, query, strlen(query)); char buf[4096] = { 0 }; char parsed[4096] = { 0 }; - net_receive(socket, buf, 4096); + if (!net_receive(socket, buf, 4096, NET_TIMEOUT)) + return; parse(http_data(buf), 4096, parsed); l->text = parsed[0] ? parsed : http_data(buf); c->text = http_code(buf); -- cgit v1.2.3