sock/posix: Call set_recvbuf internally

Instead of having two places in the code that do the
syscalls to set up the recvbuf size, just call the
function we already have.

Change-Id: I7d098fc7a39d0593c58fbe05b1f0b14f8b6a360d
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470509
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2019-09-30 12:07:28 -07:00 committed by Tomasz Zawadzki
parent 8efa583f13
commit 7171d7d4e3
2 changed files with 33 additions and 29 deletions

View File

@ -101,7 +101,7 @@ DEPDIRS-blob_bdev := log thread bdev
DEPDIRS-copy_ioat := log ioat conf thread $(JSON_LIBS) copy
# module/sock
DEPDIRS-sock_posix := log sock util
DEPDIRS-sock_posix := log sock
DEPDIRS-sock_vpp := log sock util thread
# module/bdev

View File

@ -41,7 +41,6 @@
#include "spdk/log.h"
#include "spdk/sock.h"
#include "spdk/string.h"
#include "spdk_internal/sock.h"
#define MAX_TMPBUF 1024
@ -166,6 +165,26 @@ enum spdk_posix_sock_create_type {
SPDK_SOCK_CREATE_CONNECT,
};
static int
spdk_posix_sock_set_recvbuf(struct spdk_sock *_sock, int sz)
{
struct spdk_posix_sock *sock = __posix_sock(_sock);
int rc;
assert(sock != NULL);
if (sz < SO_RCVBUF_SIZE) {
sz = SO_RCVBUF_SIZE;
}
rc = setsockopt(sock->fd, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz));
if (rc < 0) {
return rc;
}
return 0;
}
static struct spdk_sock *
spdk_posix_sock_create(const char *ip, int port, enum spdk_posix_sock_create_type type)
{
@ -298,6 +317,12 @@ retry:
}
sock->fd = fd;
rc = spdk_posix_sock_set_recvbuf(&sock->base, SO_RCVBUF_SIZE);
if (rc) {
/* Not fatal */
}
return &sock->base;
}
@ -322,7 +347,6 @@ spdk_posix_sock_accept(struct spdk_sock *_sock)
int rc, fd;
struct spdk_posix_sock *new_sock;
int flag;
size_t sz = 0;
memset(&sa, 0, sizeof(sa));
salen = sizeof(sa);
@ -344,21 +368,6 @@ spdk_posix_sock_accept(struct spdk_sock *_sock)
return NULL;
}
rc = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sz, &salen);
if (rc < 0) {
SPDK_ERRLOG("Unable to get recvbuf size for socket fd %d (%s)\n", fd, spdk_strerror(errno));
close(fd);
return NULL;
}
if (sz < SO_RCVBUF_SIZE) {
sz = SO_RCVBUF_SIZE;
rc = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz));
if (rc < 0) {
SPDK_WARNLOG("Unable to increase size of rcvbuf for socket fd %d (%s)", fd, spdk_strerror(errno));
}
}
new_sock = calloc(1, sizeof(*sock));
if (new_sock == NULL) {
SPDK_ERRLOG("sock allocation failed\n");
@ -367,6 +376,12 @@ spdk_posix_sock_accept(struct spdk_sock *_sock)
}
new_sock->fd = fd;
rc = spdk_posix_sock_set_recvbuf(&new_sock->base, SO_RCVBUF_SIZE);
if (rc) {
/* Not fatal */
}
return &new_sock->base;
}
@ -425,17 +440,6 @@ spdk_posix_sock_set_recvlowat(struct spdk_sock *_sock, int nbytes)
return 0;
}
static int
spdk_posix_sock_set_recvbuf(struct spdk_sock *_sock, int sz)
{
struct spdk_posix_sock *sock = __posix_sock(_sock);
assert(sock != NULL);
return setsockopt(sock->fd, SOL_SOCKET, SO_RCVBUF,
&sz, sizeof(sz));
}
static int
spdk_posix_sock_set_sendbuf(struct spdk_sock *_sock, int sz)
{