static int my_sock_read(BIO *h, char *buf, int size) { int res = 0; prepare_for_client_read(); if (buf != NULL) { res = recv(h->num, buf, size, 0); BIO_clear_retry_flags(h); if (res <= 0) { /* If we were interrupted, tell caller to retry */ if (errno == EINTR) { BIO_set_retry_read(h); } } } client_read_ended(); return res; }
static int my_sock_read(BIO *h, char *buf, int size) { int res; prepare_for_client_read(); res = std_sock_read(h, buf, size); client_read_ended(); return res; }
/* * Read data from a secure connection. */ ssize_t secure_read(Port *port, void *ptr, size_t len) { ssize_t n; #ifdef USE_SSL if (port->ssl) { int err; rloop: errno = 0; n = SSL_read(port->ssl, ptr, len); err = SSL_get_error(port->ssl, n); switch (err) { case SSL_ERROR_NONE: port->count += n; break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: if (port->noblock) { errno = EWOULDBLOCK; n = -1; break; } #ifdef WIN32 pgwin32_waitforsinglesocket(SSL_get_fd(port->ssl), (err == SSL_ERROR_WANT_READ) ? FD_READ | FD_CLOSE : FD_WRITE | FD_CLOSE, INFINITE); #endif goto rloop; case SSL_ERROR_SYSCALL: /* leave it to caller to ereport the value of errno */ if (n != -1) { errno = ECONNRESET; n = -1; } break; case SSL_ERROR_SSL: ereport(COMMERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("SSL error: %s", SSLerrmessage()))); /* fall through */ case SSL_ERROR_ZERO_RETURN: errno = ECONNRESET; n = -1; break; default: ereport(COMMERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("unrecognized SSL error code: %d", err))); n = -1; break; } } else #endif { prepare_for_client_read(); n = recv(port->sock, ptr, len, 0); client_read_ended(); } return n; }
/* * Read data from a secure connection. */ ssize_t secure_read(Port *port, void *ptr, size_t len) { ssize_t n; #ifdef USE_SSL if (port->ssl) { rloop: n = SSL_read(port->ssl, ptr, len); switch (SSL_get_error(port->ssl, n)) { case SSL_ERROR_NONE: port->count += n; break; case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_WRITE: goto rloop; case SSL_ERROR_SYSCALL: if (n == -1) ereport(COMMERROR, (errcode_for_socket_access(), errmsg("SSL SYSCALL error: %m"))); else { ereport(COMMERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("SSL SYSCALL error: EOF detected"))); errno = ECONNRESET; n = -1; } break; case SSL_ERROR_SSL: ereport(COMMERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("SSL error: %s", SSLerrmessage()))); /* fall through */ case SSL_ERROR_ZERO_RETURN: errno = ECONNRESET; n = -1; break; default: ereport(COMMERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("unrecognized SSL error code %d", SSL_get_error(port->ssl, n)))); n = -1; break; } } else #endif { prepare_for_client_read(); n = recv(port->sock, ptr, len, 0); client_read_ended(); } return n; }