diff options
author | Marvin Borner | 2020-11-24 12:15:01 +0100 |
---|---|---|
committer | Marvin Borner | 2020-11-24 12:15:01 +0100 |
commit | 39f3538f7ee56dab414d62201235f8427b4a9592 (patch) | |
tree | f58a946b8db1e753bfa9d1123d39ba52f06b0770 /apps | |
parent | 8babf8b26e23ffdd8094c810295061effde153dd (diff) |
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 :(
Diffstat (limited to 'apps')
-rw-r--r-- | apps/browser.c | 5 | ||||
-rw-r--r-- | apps/server.c | 7 |
2 files changed, 8 insertions, 4 deletions
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); diff --git a/apps/server.c b/apps/server.c index 4ab3369..6aca617 100644 --- a/apps/server.c +++ b/apps/server.c @@ -21,7 +21,8 @@ int main() socket->state = S_CONNECTED; char buf[4096] = { 0 }; - net_receive(socket, buf, 4096); + if (!net_receive(socket, buf, 4096, NET_NO_TIMEOUT)) + break; char path[128] = { 0 }; strcat(path, PATH); @@ -41,5 +42,7 @@ int main() net_close(socket); } - return 0; + print("Server closed!\n"); + + return 1; } |