diff options
author | bcook <> | 2014-10-13 02:39:09 +0000 |
---|---|---|
committer | bcook <> | 2014-10-13 02:39:09 +0000 |
commit | 7b944af97196f9b4b28af3b73db474a465f413a6 (patch) | |
tree | 70c469b77c3b1769a4552537e8f7a18cbb3e5ef8 /src | |
parent | 188e36185aae11a52b07f29de8b1334484bac87e (diff) | |
download | openbsd-7b944af97196f9b4b28af3b73db474a465f413a6.tar.gz openbsd-7b944af97196f9b4b28af3b73db474a465f413a6.tar.bz2 openbsd-7b944af97196f9b4b28af3b73db474a465f413a6.zip |
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@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bio/b_sock.c | 10 | ||||
-rw-r--r-- | src/usr.bin/openssl/s_client.c | 8 | ||||
-rw-r--r-- | src/usr.bin/openssl/s_server.c | 10 |
4 files changed, 23 insertions, 15 deletions
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 @@ | |||
1 | /* $OpenBSD: b_sock.c,v 1.56 2014/07/16 10:43:06 deraadt Exp $ */ | 1 | /* $OpenBSD: b_sock.c,v 1.57 2014/10/13 02:39:09 bcook Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -65,6 +65,7 @@ | |||
65 | #include <netinet/tcp.h> | 65 | #include <netinet/tcp.h> |
66 | 66 | ||
67 | #include <errno.h> | 67 | #include <errno.h> |
68 | #include <fcntl.h> | ||
68 | #include <limits.h> | 69 | #include <limits.h> |
69 | #include <netdb.h> | 70 | #include <netdb.h> |
70 | #include <stdio.h> | 71 | #include <stdio.h> |
@@ -459,5 +460,10 @@ BIO_set_tcp_ndelay(int s, int on) | |||
459 | int | 460 | int |
460 | BIO_socket_nbio(int s, int mode) | 461 | BIO_socket_nbio(int s, int mode) |
461 | { | 462 | { |
462 | return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); | 463 | int flags = fcntl(s, F_GETFD); |
464 | if (mode && !(flags & O_NONBLOCK)) | ||
465 | return (fcntl(s, F_SETFL, flags | O_NONBLOCK) == 0); | ||
466 | else if (!mode && (flags & O_NONBLOCK)) | ||
467 | return (fcntl(s, F_SETFL, flags & ~O_NONBLOCK) == 0); | ||
468 | return (1); | ||
463 | } | 469 | } |
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 @@ | |||
1 | /* $OpenBSD: b_sock.c,v 1.56 2014/07/16 10:43:06 deraadt Exp $ */ | 1 | /* $OpenBSD: b_sock.c,v 1.57 2014/10/13 02:39:09 bcook Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -65,6 +65,7 @@ | |||
65 | #include <netinet/tcp.h> | 65 | #include <netinet/tcp.h> |
66 | 66 | ||
67 | #include <errno.h> | 67 | #include <errno.h> |
68 | #include <fcntl.h> | ||
68 | #include <limits.h> | 69 | #include <limits.h> |
69 | #include <netdb.h> | 70 | #include <netdb.h> |
70 | #include <stdio.h> | 71 | #include <stdio.h> |
@@ -459,5 +460,10 @@ BIO_set_tcp_ndelay(int s, int on) | |||
459 | int | 460 | int |
460 | BIO_socket_nbio(int s, int mode) | 461 | BIO_socket_nbio(int s, int mode) |
461 | { | 462 | { |
462 | return (BIO_socket_ioctl(s, FIONBIO, &mode) == 0); | 463 | int flags = fcntl(s, F_GETFD); |
464 | if (mode && !(flags & O_NONBLOCK)) | ||
465 | return (fcntl(s, F_SETFL, flags | O_NONBLOCK) == 0); | ||
466 | else if (!mode && (flags & O_NONBLOCK)) | ||
467 | return (fcntl(s, F_SETFL, flags & ~O_NONBLOCK) == 0); | ||
468 | return (1); | ||
463 | } | 469 | } |
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 @@ | |||
1 | /* $OpenBSD: s_client.c,v 1.2 2014/09/01 20:54:37 doug Exp $ */ | 1 | /* $OpenBSD: s_client.c,v 1.3 2014/10/13 02:39:09 bcook Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -829,9 +829,9 @@ re_start: | |||
829 | BIO_printf(bio_c_out, "CONNECTED(%08X)\n", s); | 829 | BIO_printf(bio_c_out, "CONNECTED(%08X)\n", s); |
830 | 830 | ||
831 | if (c_nbio) { | 831 | if (c_nbio) { |
832 | unsigned long l = 1; | 832 | if (!c_quiet) |
833 | BIO_printf(bio_c_out, "turning on non blocking io\n"); | 833 | BIO_printf(bio_c_out, "turning on non blocking io\n"); |
834 | if (BIO_socket_ioctl(s, FIONBIO, &l) < 0) { | 834 | if (!BIO_socket_nbio(s, 1)) { |
835 | ERR_print_errors(bio_err); | 835 | ERR_print_errors(bio_err); |
836 | goto end; | 836 | goto end; |
837 | } | 837 | } |
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 @@ | |||
1 | /* $OpenBSD: s_server.c,v 1.1 2014/08/26 17:47:25 jsing Exp $ */ | 1 | /* $OpenBSD: s_server.c,v 1.2 2014/10/13 02:39:09 bcook Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -1364,11 +1364,9 @@ sv_body(char *hostname, int s, unsigned char *context) | |||
1364 | goto err; | 1364 | goto err; |
1365 | } | 1365 | } |
1366 | if (s_nbio) { | 1366 | if (s_nbio) { |
1367 | unsigned long sl = 1; | ||
1368 | |||
1369 | if (!s_quiet) | 1367 | if (!s_quiet) |
1370 | BIO_printf(bio_err, "turning on non blocking io\n"); | 1368 | BIO_printf(bio_err, "turning on non blocking io\n"); |
1371 | if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0) | 1369 | if (!BIO_socket_nbio(s, 1)) |
1372 | ERR_print_errors(bio_err); | 1370 | ERR_print_errors(bio_err); |
1373 | } | 1371 | } |
1374 | 1372 | ||
@@ -1798,11 +1796,9 @@ www_body(char *hostname, int s, unsigned char *context) | |||
1798 | goto err; | 1796 | goto err; |
1799 | 1797 | ||
1800 | if (s_nbio) { | 1798 | if (s_nbio) { |
1801 | unsigned long sl = 1; | ||
1802 | |||
1803 | if (!s_quiet) | 1799 | if (!s_quiet) |
1804 | BIO_printf(bio_err, "turning on non blocking io\n"); | 1800 | BIO_printf(bio_err, "turning on non blocking io\n"); |
1805 | if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0) | 1801 | if (!BIO_socket_nbio(s, 1)) |
1806 | ERR_print_errors(bio_err); | 1802 | ERR_print_errors(bio_err); |
1807 | } | 1803 | } |
1808 | 1804 | ||