Skip to content

Commit

Permalink
[#85] Don't control the client socket properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Jun 24, 2020
1 parent 62286ee commit 4840744
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
8 changes: 8 additions & 0 deletions src/include/network.h
Expand Up @@ -146,6 +146,14 @@ pgagroal_socket_buffers(int fd, void* shmem);
int
pgagroal_socket_nonblocking(int fd, bool value);

/**
* Does the descriptor have O_NONBLOCK
* @param fd The descriptor
* @return true if non blocking, otherwise false
*/
bool
pgagroal_socket_is_nonblocking(int fd);

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 10 additions & 0 deletions src/libpgagroal/network.c
Expand Up @@ -424,6 +424,16 @@ pgagroal_socket_nonblocking(int fd, bool value)
return 0;
}

bool
pgagroal_socket_is_nonblocking(int fd)
{
int flags;

flags = fcntl(fd, F_GETFL);

return flags & O_NONBLOCK;
}

int
pgagroal_tcp_nodelay(int fd, void* shmem)
{
Expand Down
12 changes: 9 additions & 3 deletions src/libpgagroal/security.c
Expand Up @@ -1527,6 +1527,7 @@ client_password(SSL* c_ssl, int client_fd, char* username, char* password, int s
{
int status;
time_t start_time;
bool non_blocking;
struct configuration* config;
struct message* msg = NULL;

Expand All @@ -1542,6 +1543,7 @@ client_password(SSL* c_ssl, int client_fd, char* username, char* password, int s

start_time = time(NULL);

non_blocking = pgagroal_socket_is_nonblocking(client_fd);
pgagroal_socket_nonblocking(client_fd, true);

/* psql may just close the connection without word, so loop */
Expand Down Expand Up @@ -1569,7 +1571,7 @@ client_password(SSL* c_ssl, int client_fd, char* username, char* password, int s
goto error;
}

if (!config->non_blocking)
if (!non_blocking)
{
pgagroal_socket_nonblocking(client_fd, false);
}
Expand Down Expand Up @@ -1604,6 +1606,7 @@ client_md5(SSL* c_ssl, int client_fd, char* username, char* password, int slot,
int status;
char salt[4];
time_t start_time;
bool non_blocking;
size_t size;
char* pwdusr = NULL;
char* shadow = NULL;
Expand All @@ -1629,6 +1632,7 @@ client_md5(SSL* c_ssl, int client_fd, char* username, char* password, int slot,

start_time = time(NULL);

non_blocking = pgagroal_socket_is_nonblocking(client_fd);
pgagroal_socket_nonblocking(client_fd, true);

/* psql may just close the connection without word, so loop */
Expand Down Expand Up @@ -1656,7 +1660,7 @@ client_md5(SSL* c_ssl, int client_fd, char* username, char* password, int slot,
goto error;
}

if (!config->non_blocking)
if (!non_blocking)
{
pgagroal_socket_nonblocking(client_fd, false);
}
Expand Down Expand Up @@ -1726,6 +1730,7 @@ client_scram256(SSL* c_ssl, int client_fd, char* username, char* password, int s
{
int status;
time_t start_time;
bool non_blocking;
char* password_prep = NULL;
char* client_first_message_bare = NULL;
char* server_first_message = NULL;
Expand Down Expand Up @@ -1760,6 +1765,7 @@ client_scram256(SSL* c_ssl, int client_fd, char* username, char* password, int s

start_time = time(NULL);

non_blocking = pgagroal_socket_is_nonblocking(client_fd);
pgagroal_socket_nonblocking(client_fd, true);

/* psql may just close the connection without word, so loop */
Expand Down Expand Up @@ -1787,7 +1793,7 @@ client_scram256(SSL* c_ssl, int client_fd, char* username, char* password, int s
goto error;
}

if (!config->non_blocking)
if (!non_blocking)
{
pgagroal_socket_nonblocking(client_fd, false);
}
Expand Down
21 changes: 0 additions & 21 deletions src/libpgagroal/worker.c
Expand Up @@ -94,27 +94,6 @@ pgagroal_worker(int client_fd, char* address, void* shmem, void* pipeline_shmem)

pgagroal_pool_status(shmem);

if (config->nodelay)
{
if (pgagroal_tcp_nodelay(client_fd, shmem))
{
ZF_LOGW("pgagroal_worker: TCP_NODELAY failed for %d", client_fd);
}
}

if (config->non_blocking)
{
if (pgagroal_socket_nonblocking(client_fd, true))
{
ZF_LOGW("pgagroal_worker: O_NONBLOCK failed for %d", client_fd);
}
}

if (pgagroal_socket_buffers(client_fd, shmem))
{
ZF_LOGW("pgagroal_worker: SO_RCVBUF/SO_SNDBUF failed for %d", client_fd);
}

if (config->pipeline == PIPELINE_PERFORMANCE)
{
p = performance_pipeline();
Expand Down

0 comments on commit 4840744

Please sign in to comment.