jsonrpc: use SOCK_NONBLOCK in socket() calls
This allows us to remove separate fcntl() calls to set O_NONBLOCK. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I1a590cfb3b65b3174bb5ef33e060cdc9bb7ac86c Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7598 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: <dongx.yi@intel.com>
This commit is contained in:
parent
c86075607b
commit
32999ab917
@ -227,23 +227,15 @@ static int
|
||||
jsonrpc_client_connect(struct spdk_jsonrpc_client *client, int domain, int protocol,
|
||||
struct sockaddr *server_addr, socklen_t addrlen)
|
||||
{
|
||||
int rc, flags;
|
||||
int rc;
|
||||
|
||||
client->sockfd = socket(domain, SOCK_STREAM, protocol);
|
||||
client->sockfd = socket(domain, SOCK_STREAM | SOCK_NONBLOCK, protocol);
|
||||
if (client->sockfd < 0) {
|
||||
rc = errno;
|
||||
SPDK_ERRLOG("socket() failed\n");
|
||||
return -rc;
|
||||
}
|
||||
|
||||
flags = fcntl(client->sockfd, F_GETFL);
|
||||
if (flags < 0 || fcntl(client->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
rc = errno;
|
||||
SPDK_ERRLOG("fcntl(): can't set nonblocking mode for socket (%d): %s\n",
|
||||
errno, spdk_strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
|
||||
rc = connect(client->sockfd, server_addr, addrlen);
|
||||
if (rc != 0) {
|
||||
rc = errno;
|
||||
|
@ -41,7 +41,7 @@ spdk_jsonrpc_server_listen(int domain, int protocol,
|
||||
spdk_jsonrpc_handle_request_fn handle_request)
|
||||
{
|
||||
struct spdk_jsonrpc_server *server;
|
||||
int rc, val, flag, i;
|
||||
int rc, val, i;
|
||||
|
||||
server = calloc(1, sizeof(struct spdk_jsonrpc_server));
|
||||
if (server == NULL) {
|
||||
@ -57,7 +57,7 @@ spdk_jsonrpc_server_listen(int domain, int protocol,
|
||||
|
||||
server->handle_request = handle_request;
|
||||
|
||||
server->sockfd = socket(domain, SOCK_STREAM, protocol);
|
||||
server->sockfd = socket(domain, SOCK_STREAM | SOCK_NONBLOCK, protocol);
|
||||
if (server->sockfd < 0) {
|
||||
SPDK_ERRLOG("socket() failed\n");
|
||||
free(server);
|
||||
@ -67,15 +67,6 @@ spdk_jsonrpc_server_listen(int domain, int protocol,
|
||||
val = 1;
|
||||
setsockopt(server->sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
||||
|
||||
flag = fcntl(server->sockfd, F_GETFL);
|
||||
if (fcntl(server->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
|
||||
server->sockfd, spdk_strerror(errno));
|
||||
close(server->sockfd);
|
||||
free(server);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = bind(server->sockfd, listen_addr, addrlen);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("could not bind JSON-RPC server: %s\n", spdk_strerror(errno));
|
||||
|
Loading…
Reference in New Issue
Block a user