Skip to content

Commit

Permalink
[#479] Remove buffer_size from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 30, 2024
1 parent 4a82850 commit 0e4c711
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/libpgagroal/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <netinet/tcp.h>

static int bind_host(const char* hostname, int port, int** fds, int* length, bool non_blocking, int* buffer_size, bool no_delay, int backlog);
static int socket_buffers(int fd, int* buffer_size);

/**
*
Expand Down Expand Up @@ -523,28 +524,6 @@ pgagroal_tcp_nodelay(int fd)
return 0;
}

int
pgagroal_socket_buffers(int fd, int* buffer_size)
{
socklen_t optlen = sizeof(int);

if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, buffer_size, optlen) == -1)
{
pgagroal_log_warn("socket_buffers: SO_RCVBUF %d %s", fd, strerror(errno));
errno = 0;
return 1;
}

if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, buffer_size, optlen) == -1)
{
pgagroal_log_warn("socket_buffers: SO_SNDBUF %d %s", fd, strerror(errno));
errno = 0;
return 1;
}

return 0;
}

int
pgagroal_read_socket(SSL* ssl, int fd, char* buffer, size_t buffer_size)
{
Expand Down Expand Up @@ -577,6 +556,28 @@ pgagroal_write_socket(SSL* ssl, int fd, char* buffer, size_t buffer_size)
return byte_write;
}

static int
socket_buffers(int fd, int* buffer_size)
{
socklen_t optlen = sizeof(int);

if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, buffer_size, optlen) == -1)
{
pgagroal_log_warn("socket_buffers: SO_RCVBUF %d %s", fd, strerror(errno));
errno = 0;
return 1;
}

if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, buffer_size, optlen) == -1)
{
pgagroal_log_warn("socket_buffers: SO_SNDBUF %d %s", fd, strerror(errno));
errno = 0;
return 1;
}

return 0;
}

/**
*
*/
Expand Down Expand Up @@ -654,7 +655,7 @@ bind_host(const char* hostname, int port, int** fds, int* length, bool non_block
}
}

if (pgagroal_socket_buffers(sockfd, buffer_size))
if (socket_buffers(sockfd, buffer_size))
{
pgagroal_disconnect(sockfd);
continue;
Expand Down

0 comments on commit 0e4c711

Please sign in to comment.