Commit 52ccf4b7 authored by Ben Walker's avatar Ben Walker
Browse files

sock/posix: Increase SO_RECVBUF size by default



Everywhere we use this, we increase the size to 2MB.
Just make that the default behavior.

Change-Id: Ie174419a09df1792a0c7311eddd0c2dcefa267b5
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/466991


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 4bb8a88c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
DEPDIRS-sock_posix := log sock util
DEPDIRS-sock_vpp := log sock util thread

# module/bdev
+27 −7
Original line number Diff line number Diff line
@@ -41,10 +41,12 @@

#include "spdk/log.h"
#include "spdk/sock.h"
#include "spdk/string.h"
#include "spdk_internal/sock.h"

#define MAX_TMPBUF 1024
#define PORTNUMLEN 32
#define SO_RCVBUF_SIZE (2 * 1024 * 1024)

struct spdk_posix_sock {
	struct spdk_sock	base;
@@ -317,9 +319,10 @@ spdk_posix_sock_accept(struct spdk_sock *_sock)
	struct spdk_posix_sock		*sock = __posix_sock(_sock);
	struct sockaddr_storage		sa;
	socklen_t			salen;
	int				rc;
	int				rc, fd;
	struct spdk_posix_sock		*new_sock;
	int				flag;
	size_t				sz;

	memset(&sa, 0, sizeof(sa));
	salen = sizeof(sa);
@@ -332,21 +335,38 @@ spdk_posix_sock_accept(struct spdk_sock *_sock)
		return NULL;
	}

	flag = fcntl(rc, F_GETFL);
	if ((!(flag & O_NONBLOCK)) && (fcntl(rc, F_SETFL, flag | O_NONBLOCK) < 0)) {
		SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%d)\n", rc, errno);
		close(rc);
	fd = rc;

	flag = fcntl(fd, F_GETFL);
	if ((!(flag & O_NONBLOCK)) && (fcntl(fd, F_SETFL, flag | O_NONBLOCK) < 0)) {
		SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%d)\n", fd, errno);
		close(fd);
		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");
		close(rc);
		close(fd);
		return NULL;
	}

	new_sock->fd = rc;
	new_sock->fd = fd;
	return &new_sock->base;
}