Обсуждение: [RFC,PATCH] Only disable sigpipe during SSL write

Поиск
Список
Период
Сортировка

[RFC,PATCH] Only disable sigpipe during SSL write

От
Jeremy Kerr
Дата:
If the connection isn't over SSL, there's no need to do the disable.

This effectively halves the number of syscalls performed by libpq when
SSL is not in use.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

---src/interfaces/libpq/fe-secure.c |    7 +++----1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index eb579cf..2101315 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -368,13 +368,13 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len){    ssize_t        n;
-    DISABLE_SIGPIPE(return -1);
-#ifdef USE_SSL    if (conn->ssl)    {        int            err;
+        DISABLE_SIGPIPE(return -1);
+        n = SSL_write(conn->ssl, ptr, len);        err = SSL_get_error(conn->ssl, n);        switch (err)
@@ -433,15 +433,14 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)                n = -1;
break;       }
 
+        RESTORE_SIGPIPE();    }    else#endif    {        n = send(conn->sock, ptr, len, 0);
-        REMEMBER_EPIPE(n < 0 && SOCK_ERRNO == EPIPE);    }
-    RESTORE_SIGPIPE();    return n;}