diff options
author | 2007-01-11 18:05:08 +0000 | |
---|---|---|
committer | 2007-01-11 18:05:08 +0000 | |
commit | 01d85ec50e7c7f9cd9579cac1b47540cd154dba2 (patch) | |
tree | 7b3b790acb05cfe278ec2a27d0c5caabd586766f /usr.sbin/hoststated/check_tcp.c | |
parent | rework opencvs so that we can deal with binary files. previously we assumed all files were ascii, (diff) | |
download | wireguard-openbsd-01d85ec50e7c7f9cd9579cac1b47540cd154dba2.tar.xz wireguard-openbsd-01d85ec50e7c7f9cd9579cac1b47540cd154dba2.zip |
use real async events for checks and improve the non-blocking socket
usage. also modify the check_icmp code to use non-blocking raw sockets
and merge the icmp4 and icmp6 functions. some other minor changes
while i'm here.
as discussed with pyr@ claudio@ deraadt@
ok pyr@
Diffstat (limited to 'usr.sbin/hoststated/check_tcp.c')
-rw-r--r-- | usr.sbin/hoststated/check_tcp.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/usr.sbin/hoststated/check_tcp.c b/usr.sbin/hoststated/check_tcp.c index 86b8244093f..fc365c18d9d 100644 --- a/usr.sbin/hoststated/check_tcp.c +++ b/usr.sbin/hoststated/check_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: check_tcp.c,v 1.8 2007/01/09 00:45:32 deraadt Exp $ */ +/* $OpenBSD: check_tcp.c,v 1.9 2007/01/11 18:05:08 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -71,17 +71,16 @@ check_tcp(struct ctl_tcp_event *cte) if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) goto bad; + bcopy(&cte->table->timeout, &tv, sizeof(tv)); if (connect(s, (struct sockaddr *)&cte->host->ss, len) == -1) { if (errno != EINPROGRESS) goto bad; - } else { + } else cte->host->up = HOST_UP; - tcp_host_up(s, cte); - return; - } - bcopy(&cte->table->timeout, &tv, sizeof(tv)); - event_once(s, EV_TIMEOUT|EV_WRITE, tcp_write, cte, &tv); + event_set(&cte->ev, s, EV_TIMEOUT|EV_WRITE, tcp_write, cte); + event_add(&cte->ev, &tv); return; + bad: close(s); cte->host->up = HOST_DOWN; @@ -102,7 +101,7 @@ tcp_write(int s, short event, void *arg) len = sizeof(err); if (getsockopt(s, SOL_SOCKET, SO_ERROR, &err, &len)) fatal("tcp_write: getsockopt"); - if (err) + if (err != 0) cte->host->up = HOST_DOWN; else cte->host->up = HOST_UP; @@ -123,16 +122,18 @@ tcp_host_up(int s, struct ctl_tcp_event *cte) switch (cte->table->check) { case CHECK_TCP: close(s); - hce_notify_done(cte->host, "tcp_write: success"); + hce_notify_done(cte->host, "tcp_host_up: success"); break; case CHECK_HTTP_CODE: case CHECK_HTTP_DIGEST: - send_http_request(cte); + event_again(&cte->ev, s, EV_TIMEOUT|EV_WRITE, send_http_request, + &cte->tv_start, &cte->table->timeout, cte); break; case CHECK_SEND_EXPECT: - start_send_expect(cte); + event_again(&cte->ev, s, EV_TIMEOUT|EV_WRITE, start_send_expect, + &cte->tv_start, &cte->table->timeout, cte); break; default: - fatalx("tcp_write: unhandled check type"); + fatalx("tcp_host_up: unhandled check type"); } } |