diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2003-12-25 13:13:19 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2003-12-25 13:13:19 +0000 |
commit | d8e1c03504634bb031161260263cfd92aaf19af4 (patch) | |
tree | 152aa9ac4b6a62b882f9bcc394f32b78981b2ab0 /usr.sbin/bgpd | |
parent | 88be3bdd2737f314dd7e1fa3ec1b9faeb1c0ca77 (diff) |
we need nonblocking connect
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/session.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index 1f60fc08ddc..32754a10dfc 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.39 2003/12/24 23:48:05 henning Exp $ */ +/* $OpenBSD: session.c,v 1.40 2003/12/25 13:13:18 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -59,6 +59,7 @@ void session_close_connection(struct peer *); void session_terminate(void); void change_state(struct peer *, enum session_state, enum session_events); int session_setup_socket(struct peer *); +void session_socket_blockmode(int, int); void session_accept(int); int session_connect(struct peer *); void session_open(struct peer *); @@ -688,6 +689,8 @@ session_connect(struct peer *peer) return (-1); } + session_socket_blockmode(peer->sock, 1); + if ((n = connect(peer->sock, (struct sockaddr *)&peer->conf.remote_addr, sizeof(peer->conf.remote_addr))) == -1) if (errno != EINPROGRESS) { @@ -734,6 +737,23 @@ session_setup_socket(struct peer *p) } void +session_socket_blockmode(int fd, int block) +{ + int flags; + + if ((flags = fcntl(fd, F_GETFL, 0)) == -1) + fatal("fnctl F_GETFL", errno); + + if (block) + flags |= O_NONBLOCK; + else + flags &= ~O_NONBLOCK; + + if ((flags = fcntl(fd, F_SETFL, flags)) == -1) + fatal("fnctl F_SETFL", errno); +} + +void session_open(struct peer *peer) { struct msg_open msg; @@ -741,6 +761,8 @@ session_open(struct peer *peer) u_int16_t len; int errs = 0, n; + session_socket_blockmode(peer->sock, 0); + len = MSGSIZE_OPEN_MIN; memset(&msg.header.marker, 0xff, sizeof(msg.header.marker)); |