/* are we in the middle of a renegotiation? */
static bool in_ssl_renegotiation = false;
+/* kill-switch to have my_sock_read pretend there's no data */
+static bool my_block_raw_read = false;
+
static SSL_CTX *SSL_context = NULL;
/* ------------------------------------------------------------ */
}
errno = 0;
+ my_block_raw_read = true;
n = SSL_write(port->ssl, ptr, len);
+ my_block_raw_read = false;
err = SSL_get_error(port->ssl, n);
switch (err)
{
static int
my_sock_read(BIO *h, char *buf, int size)
{
- int res = 0;
+ int res;
- if (buf != NULL)
+ if (buf == NULL)
+ return 0; /* XXX: can this happen? */
+
+ /* If the kill-switch is set, pretend that there is no data. */
+ if (my_block_raw_read)
{
- res = secure_raw_read(((Port *)h->ptr), buf, size);
+ errno = EWOULDBLOCK;
BIO_clear_retry_flags(h);
- if (res <= 0)
+ BIO_set_retry_read(h);
+ return -1;
+ }
+
+ res = secure_raw_read(((Port *)h->ptr), buf, size);
+ BIO_clear_retry_flags(h);
+ if (res <= 0)
+ {
+ /* If we were interrupted, tell caller to retry */
+ if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN)
{
- /* If we were interrupted, tell caller to retry */
- if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN)
- {
- BIO_set_retry_read(h);
- }
+ BIO_set_retry_read(h);
}
}
/* --------------------------------
* pq_recvbuf - load some bytes into the input buffer
*
- * returns 0 if OK, EOF if trouble
+ * returns 0 if OK, EOF if trouble
* --------------------------------
*/
-static int
-pq_recvbuf(void)
+int
+pq_recvbuf(bool block)
{
if (PqRecvPointer > 0)
{
PqRecvLength = PqRecvPointer = 0;
}
- /* Ensure that we're in blocking mode */
- socket_set_nonblocking(false);
+ /* Ensure that we're in blocking mode (or not) */
+ socket_set_nonblocking(!block);
/* Can fill buffer from PqRecvLength and upwards */
for (;;)
if (errno == EINTR)
continue; /* Ok if interrupted */
+ if (!block)
+ {
+ if (errno == EWOULDBLOCK || errno == EAGAIN)
+ return 0;
+ }
+
/*
* Careful: an ereport() that tries to write to the client would
* cause recursion to here, leading to stack overflow and core
while (PqRecvPointer >= PqRecvLength)
{
- if (pq_recvbuf()) /* If nothing in buffer, then recv some */
+ if (pq_recvbuf(true)) /* If nothing in buffer, then recv some */
return EOF; /* Failed to recv data */
}
return (unsigned char) PqRecvBuffer[PqRecvPointer++];
while (PqRecvPointer >= PqRecvLength)
{
- if (pq_recvbuf()) /* If nothing in buffer, then recv some */
+ if (pq_recvbuf(true)) /* If nothing in buffer, then recv some */
return EOF; /* Failed to recv data */
}
return (unsigned char) PqRecvBuffer[PqRecvPointer];
{
while (PqRecvPointer >= PqRecvLength)
{
- if (pq_recvbuf()) /* If nothing in buffer, then recv some */
+ if (pq_recvbuf(true)) /* If nothing in buffer, then recv some */
return EOF; /* Failed to recv data */
}
amount = PqRecvLength - PqRecvPointer;
{
while (PqRecvPointer >= PqRecvLength)
{
- if (pq_recvbuf()) /* If nothing in buffer, then recv some */
+ if (pq_recvbuf(true)) /* If nothing in buffer, then recv some */
return EOF; /* Failed to recv data */
}
amount = PqRecvLength - PqRecvPointer;
{
while (PqRecvPointer >= PqRecvLength)
{
- if (pq_recvbuf()) /* If nothing in buffer, then recv some */
+ if (pq_recvbuf(true)) /* If nothing in buffer, then recv some */
return EOF; /* Failed to recv data */
}