diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2016-12-07 13:21:46 -0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2016-12-08 12:50:25 +0100 |
| commit | 6228a3b8743ea2a6589070de926588e2ceb0f27f (patch) | |
| tree | 1d4f333086f14d333c2aae31b1c01a27e55e8b0b /lib/sockopt.c | |
| parent | de587d745e3b8b75cf92b2bff78af370adddb39f (diff) | |
*: always set SO_SNDBUF and SO_RCVBUF using a best effort approach
If we fail to set any socket's buffer size, try again with a smaller value
and keep going until it succeeds. This is better than just giving up or,
even worse, abort the creation of a socket (ospf6d and ripd).
Fix broken ospf6d on FreeBSD.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/sockopt.c')
| -rw-r--r-- | lib/sockopt.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/sockopt.c b/lib/sockopt.c index be3ac0e4bf..461e1f7f54 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -29,30 +29,30 @@ #include "sockopt.h" #include "sockunion.h" -int +void setsockopt_so_recvbuf (int sock, int size) { - int ret; - - if ( (ret = setsockopt (sock, SOL_SOCKET, SO_RCVBUF, (char *) - &size, sizeof (int))) < 0) - zlog_err ("fd %d: can't setsockopt SO_RCVBUF to %d: %s", - sock,size,safe_strerror(errno)); + int orig_req = size; - return ret; + while (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size)) == -1) + size /= 2; + + if (size != orig_req) + zlog_warn ("%s: fd %d: SO_RCVBUF set to %d (requested %d)", __func__, sock, + size, orig_req); } -int +void setsockopt_so_sendbuf (const int sock, int size) { - int ret = setsockopt (sock, SOL_SOCKET, SO_SNDBUF, - (char *)&size, sizeof (int)); - - if (ret < 0) - zlog_err ("fd %d: can't setsockopt SO_SNDBUF to %d: %s", - sock, size, safe_strerror (errno)); + int orig_req = size; - return ret; + while (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) == -1) + size /= 2; + + if (size != orig_req) + zlog_warn ("%s: fd %d: SO_SNDBUF set to %d (requested %d)", __func__, sock, + size, orig_req); } int |
