sock/posix: Move repeated socket allocation code to a function
Change-Id: I71726be5dbe2bb112b7569869dd456ef38f84d9d Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472649 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Alexey Marchuk <alexeymar@mellanox.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
913f780e10
commit
81a47d9820
@ -206,6 +206,33 @@ spdk_posix_sock_set_sendbuf(struct spdk_sock *_sock, int sz)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct spdk_posix_sock *
|
||||
_spdk_posix_sock_alloc(int fd)
|
||||
{
|
||||
struct spdk_posix_sock *sock;
|
||||
int rc;
|
||||
|
||||
sock = calloc(1, sizeof(*sock));
|
||||
if (sock == NULL) {
|
||||
SPDK_ERRLOG("sock allocation failed\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->fd = fd;
|
||||
|
||||
rc = spdk_posix_sock_set_recvbuf(&sock->base, SO_RCVBUF_SIZE);
|
||||
if (rc) {
|
||||
/* Not fatal */
|
||||
}
|
||||
|
||||
rc = spdk_posix_sock_set_sendbuf(&sock->base, SO_SNDBUF_SIZE);
|
||||
if (rc) {
|
||||
/* Not fatal */
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
static struct spdk_sock *
|
||||
spdk_posix_sock_create(const char *ip, int port, enum spdk_posix_sock_create_type type)
|
||||
{
|
||||
@ -330,25 +357,13 @@ retry:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock = calloc(1, sizeof(*sock));
|
||||
sock = _spdk_posix_sock_alloc(fd);
|
||||
if (sock == NULL) {
|
||||
SPDK_ERRLOG("sock allocation failed\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sock->fd = fd;
|
||||
|
||||
rc = spdk_posix_sock_set_recvbuf(&sock->base, SO_RCVBUF_SIZE);
|
||||
if (rc) {
|
||||
/* Not fatal */
|
||||
}
|
||||
|
||||
rc = spdk_posix_sock_set_sendbuf(&sock->base, SO_SNDBUF_SIZE);
|
||||
if (rc) {
|
||||
/* Not fatal */
|
||||
}
|
||||
|
||||
return &sock->base;
|
||||
}
|
||||
|
||||
@ -394,25 +409,12 @@ spdk_posix_sock_accept(struct spdk_sock *_sock)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_sock = calloc(1, sizeof(*sock));
|
||||
new_sock = _spdk_posix_sock_alloc(fd);
|
||||
if (new_sock == NULL) {
|
||||
SPDK_ERRLOG("sock allocation failed\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_sock->fd = fd;
|
||||
|
||||
rc = spdk_posix_sock_set_recvbuf(&new_sock->base, SO_RCVBUF_SIZE);
|
||||
if (rc) {
|
||||
/* Not fatal */
|
||||
}
|
||||
|
||||
rc = spdk_posix_sock_set_sendbuf(&new_sock->base, SO_SNDBUF_SIZE);
|
||||
if (rc) {
|
||||
/* Not fatal */
|
||||
}
|
||||
|
||||
return &new_sock->base;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user