Only use recv/send for socket BIOs on Windows.

In OpenSSL, socket BIOs only used recv/send on Windows and read/write on POSIX.
Align our socket BIOs with that behavior. This should be a no-op, but avoids
frustrating consumers overly sensitive to the syscalls used now that SSL_set_fd
has switched to socket BIOs to align with OpenSSL. b/28138582.

Change-Id: Id4870ef8e668e587d6ef51c5b5f21e03af66a288
Reviewed-on: https://boringssl-review.googlesource.com/7686
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2016-04-15 16:12:19 -04:00 committed by Adam Langley
parent 919610b4c4
commit 26993ad55e
2 changed files with 11 additions and 3 deletions

View File

@ -110,7 +110,11 @@ static int sock_read(BIO *b, char *out, int outl) {
} }
bio_clear_socket_error(); bio_clear_socket_error();
#if defined(OPENSSL_WINDOWS)
ret = recv(b->num, out, outl, 0); ret = recv(b->num, out, outl, 0);
#else
ret = read(b->num, out, outl);
#endif
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
if (ret <= 0) { if (ret <= 0) {
if (bio_fd_should_retry(ret)) { if (bio_fd_should_retry(ret)) {
@ -124,7 +128,11 @@ static int sock_write(BIO *b, const char *in, int inl) {
int ret; int ret;
bio_clear_socket_error(); bio_clear_socket_error();
#if defined(OPENSSL_WINDOWS)
ret = send(b->num, in, inl, 0); ret = send(b->num, in, inl, 0);
#else
ret = write(b->num, in, inl);
#endif
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
if (ret <= 0) { if (ret <= 0) {
if (bio_fd_should_retry(ret)) { if (bio_fd_should_retry(ret)) {

View File

@ -529,9 +529,9 @@ OPENSSL_EXPORT int BIO_set_write_buffer_size(BIO *bio, int buffer_size);
/* Socket BIOs. /* Socket BIOs.
* *
* Socket BIOs behave like file descriptor BIOs but wrap the system's |recv| * Socket BIOs behave like file descriptor BIOs but, on Windows systems, wrap
* and |send| functions. This is relevant for Windows systems where file * the system's |recv| and |send| functions instead of |read| and |write|. On
* descriptors, provided by C runtime for use with |read| and |write|, are not * Windows, file descriptors are provided by C runtime and are not
* interchangeable with sockets. * interchangeable with sockets.
* *
* Socket BIOs may be used with |BIO_set_fd| and |BIO_get_fd|. * Socket BIOs may be used with |BIO_set_fd| and |BIO_get_fd|.