Commit f93ee09d authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Tomasz Zawadzki
Browse files

sock: add utils to async connect



Change-Id: I6726c8a8b13c751364ff7aa84e37ccb075b79943
Signed-off-by: default avatarJacek Kalwas <jacek.kalwas@nutanix.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/25906


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
parent afaa7355
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -413,6 +413,24 @@ int spdk_sock_posix_fd_create(struct addrinfo *res, struct spdk_sock_opts *opts,
 */
int spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *opts);

/**
 * Initiates the socket connection.
 *
 * On success O_NONBLOCK is set otherwise property value is undefined.
 *
 * User must use \ref spdk_sock_posix_fd_connect_poll_async to determine connection status.
 *
 * \return 0 on success, -1 on failure, 1 to retry with different address if available.
 */
int spdk_sock_posix_fd_connect_async(int fd, struct addrinfo *res, struct spdk_sock_opts *opts);

/**
 * Polls the socket connection status.
 *
 * \return 0 on connect success, -1 on failure, 1 to retry with different address if available and -EAGAIN to retry later.
 */
int spdk_sock_posix_fd_connect_poll_async(int fd);

/**
 * Insert a group into the placement map.
 * If the group is already in the map, take a reference.
+24 −5
Original line number Diff line number Diff line
@@ -460,9 +460,6 @@ spdk_sock_posix_fd_create(struct addrinfo *res, struct spdk_sock_opts *opts,
	return fd;
}


/* Returns 0 on success, -1 on failure, 1 to retry with different address if available.
 * If block set to false it can return -EAGAIN to retry later. */
static int
sock_posix_fd_connect_poll(int fd, struct spdk_sock_opts *opts, bool block)
{
@@ -515,7 +512,13 @@ sock_posix_fd_connect_poll(int fd, struct spdk_sock_opts *opts, bool block)
}

int
spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *opts)
spdk_sock_posix_fd_connect_poll_async(int fd)
{
	return sock_posix_fd_connect_poll(fd, NULL, false);
}

static int
sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *opts, bool block)
{
	char portnum[PORTNUMLEN];
	const char *src_addr;
@@ -563,7 +566,11 @@ spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *
		return 1;
	}

	rc = sock_posix_fd_connect_poll(fd, opts, true);
	if (!block) {
		return 0;
	}

	rc = sock_posix_fd_connect_poll(fd, opts, block);
	if (rc) {
		return rc;
	}
@@ -575,6 +582,18 @@ spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *
	return 0;
}

int
spdk_sock_posix_fd_connect_async(int fd, struct addrinfo *res, struct spdk_sock_opts *opts)
{
	return sock_posix_fd_connect(fd, res, opts, false);
}

int
spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *opts)
{
	return sock_posix_fd_connect(fd, res, opts, true);
}

struct spdk_sock *
spdk_sock_connect(const char *ip, int port, const char *impl_name)
{
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@
	spdk_net_impl_register;
	spdk_sock_posix_fd_create;
	spdk_sock_posix_fd_connect;
	spdk_sock_posix_fd_connect_async;
	spdk_sock_posix_fd_connect_poll_async;
	spdk_sock_posix_getaddrinfo;
	spdk_sock_group_get_buf;
	spdk_sock_map_insert;
+3 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ DEFINE_STUB(spdk_sock_posix_fd_create, int, (struct addrinfo *res, struct spdk_s
		struct spdk_sock_impl_opts *impl_opts), 0);
DEFINE_STUB(spdk_sock_posix_fd_connect, int, (int fd, struct addrinfo *res,
		struct spdk_sock_opts *opts), 0);
DEFINE_STUB(spdk_sock_posix_fd_connect_async, int, (int fd, struct addrinfo *res,
		struct spdk_sock_opts *opts), 0);
DEFINE_STUB(spdk_sock_posix_fd_connect_poll_async, int, (int fd), 0);
DEFINE_STUB(spdk_sock_posix_getaddrinfo, struct addrinfo *, (const char *ip, int port), 0);

static void