From 7b944af97196f9b4b28af3b73db474a465f413a6 Mon Sep 17 00:00:00 2001 From: bcook <> Date: Mon, 13 Oct 2014 02:39:09 +0000 Subject: Use O_NONBLOCK over FIONBIO. Prefer this because it is the POSIX standard and has consistent behavior across platforms. Use BIO_socket_nbio consistently across the tree. from Jonas 'Sortie' Termansen, ok deraadt@ --- src/lib/libcrypto/bio/b_sock.c | 10 ++++++++-- src/lib/libssl/src/crypto/bio/b_sock.c | 10 ++++++++-- src/usr.bin/openssl/s_client.c | 8 ++++---- src/usr.bin/openssl/s_server.c | 10 +++------- 4 files changed, 23 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index c095943e8b..81c48a6e5c 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_sock.c,v 1.56 2014/07/16 10:43:06 deraadt Exp $ */ +/* $OpenBSD: b_sock.c,v 1.57 2014/10/13 02:39:09 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -65,6 +65,7 @@ #include #include +#include #include #include #include @@ -459,5 +460,10 @@ BIO_set_tcp_ndelay(int s, int on) int BIO_socket_nbio(int s, int mode) { - return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); + int flags = fcntl(s, F_GETFD); + if (mode && !(flags & O_NONBLOCK)) + return (fcntl(s, F_SETFL, flags | O_NONBLOCK) == 0); + else if (!mode && (flags & O_NONBLOCK)) + return (fcntl(s, F_SETFL, flags & ~O_NONBLOCK) == 0); + return (1); } diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c index c095943e8b..81c48a6e5c 100644 --- a/src/lib/libssl/src/crypto/bio/b_sock.c +++ b/src/lib/libssl/src/crypto/bio/b_sock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_sock.c,v 1.56 2014/07/16 10:43:06 deraadt Exp $ */ +/* $OpenBSD: b_sock.c,v 1.57 2014/10/13 02:39:09 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -65,6 +65,7 @@ #include #include +#include #include #include #include @@ -459,5 +460,10 @@ BIO_set_tcp_ndelay(int s, int on) int BIO_socket_nbio(int s, int mode) { - return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); + int flags = fcntl(s, F_GETFD); + if (mode && !(flags & O_NONBLOCK)) + return (fcntl(s, F_SETFL, flags | O_NONBLOCK) == 0); + else if (!mode && (flags & O_NONBLOCK)) + return (fcntl(s, F_SETFL, flags & ~O_NONBLOCK) == 0); + return (1); } diff --git a/src/usr.bin/openssl/s_client.c b/src/usr.bin/openssl/s_client.c index 1ba399a4ae..dba1336f76 100644 --- a/src/usr.bin/openssl/s_client.c +++ b/src/usr.bin/openssl/s_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_client.c,v 1.2 2014/09/01 20:54:37 doug Exp $ */ +/* $OpenBSD: s_client.c,v 1.3 2014/10/13 02:39:09 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -829,9 +829,9 @@ re_start: BIO_printf(bio_c_out, "CONNECTED(%08X)\n", s); if (c_nbio) { - unsigned long l = 1; - BIO_printf(bio_c_out, "turning on non blocking io\n"); - if (BIO_socket_ioctl(s, FIONBIO, &l) < 0) { + if (!c_quiet) + BIO_printf(bio_c_out, "turning on non blocking io\n"); + if (!BIO_socket_nbio(s, 1)) { ERR_print_errors(bio_err); goto end; } diff --git a/src/usr.bin/openssl/s_server.c b/src/usr.bin/openssl/s_server.c index 7fa875c661..9ca13dd335 100644 --- a/src/usr.bin/openssl/s_server.c +++ b/src/usr.bin/openssl/s_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: s_server.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ +/* $OpenBSD: s_server.c,v 1.2 2014/10/13 02:39:09 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -1364,11 +1364,9 @@ sv_body(char *hostname, int s, unsigned char *context) goto err; } if (s_nbio) { - unsigned long sl = 1; - if (!s_quiet) BIO_printf(bio_err, "turning on non blocking io\n"); - if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0) + if (!BIO_socket_nbio(s, 1)) ERR_print_errors(bio_err); } @@ -1798,11 +1796,9 @@ www_body(char *hostname, int s, unsigned char *context) goto err; if (s_nbio) { - unsigned long sl = 1; - if (!s_quiet) BIO_printf(bio_err, "turning on non blocking io\n"); - if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0) + if (!BIO_socket_nbio(s, 1)) ERR_print_errors(bio_err); } -- cgit v1.2.3-55-g6feb