2016-05-19 20:29:37 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jsonrpc_internal.h"
|
2017-08-11 23:27:04 +00:00
|
|
|
#include "spdk/string.h"
|
2018-12-05 15:28:23 +00:00
|
|
|
#include "spdk/util.h"
|
2016-05-19 20:29:37 +00:00
|
|
|
|
|
|
|
struct spdk_jsonrpc_server *
|
2016-12-13 22:58:42 +00:00
|
|
|
spdk_jsonrpc_server_listen(int domain, int protocol,
|
|
|
|
struct sockaddr *listen_addr, socklen_t addrlen,
|
2016-05-19 20:29:37 +00:00
|
|
|
spdk_jsonrpc_handle_request_fn handle_request)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_server *server;
|
2018-06-07 20:21:03 +00:00
|
|
|
int rc, val, flag, i;
|
2016-05-19 20:29:37 +00:00
|
|
|
|
|
|
|
server = calloc(1, sizeof(struct spdk_jsonrpc_server));
|
|
|
|
if (server == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-07 20:21:03 +00:00
|
|
|
TAILQ_INIT(&server->free_conns);
|
|
|
|
TAILQ_INIT(&server->conns);
|
|
|
|
|
|
|
|
for (i = 0; i < SPDK_JSONRPC_MAX_CONNS; i++) {
|
|
|
|
TAILQ_INSERT_TAIL(&server->free_conns, &server->conns_array[i], link);
|
|
|
|
}
|
|
|
|
|
2016-05-19 20:29:37 +00:00
|
|
|
server->handle_request = handle_request;
|
|
|
|
|
2016-12-13 22:58:42 +00:00
|
|
|
server->sockfd = socket(domain, SOCK_STREAM, protocol);
|
2016-05-19 20:29:37 +00:00
|
|
|
if (server->sockfd < 0) {
|
|
|
|
SPDK_ERRLOG("socket() failed\n");
|
|
|
|
free(server);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = 1;
|
|
|
|
setsockopt(server->sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
2016-12-13 22:58:42 +00:00
|
|
|
if (protocol == IPPROTO_TCP) {
|
|
|
|
setsockopt(server->sockfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
|
|
|
|
}
|
2016-05-19 20:29:37 +00:00
|
|
|
|
2017-11-27 14:57:41 +00:00
|
|
|
flag = fcntl(server->sockfd, F_GETFL);
|
|
|
|
if (fcntl(server->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
2017-11-07 12:56:52 +00:00
|
|
|
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
|
|
|
|
server->sockfd, spdk_strerror(errno));
|
2016-05-19 20:29:37 +00:00
|
|
|
close(server->sockfd);
|
|
|
|
free(server);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = bind(server->sockfd, listen_addr, addrlen);
|
|
|
|
if (rc != 0) {
|
2017-11-07 12:56:52 +00:00
|
|
|
SPDK_ERRLOG("could not bind JSON-RPC server: %s\n", spdk_strerror(errno));
|
2016-05-19 20:29:37 +00:00
|
|
|
close(server->sockfd);
|
|
|
|
free(server);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = listen(server->sockfd, 512);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("listen() failed, errno = %d\n", errno);
|
|
|
|
close(server->sockfd);
|
|
|
|
free(server);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2019-06-18 18:36:05 +00:00
|
|
|
static struct spdk_jsonrpc_request *
|
|
|
|
spdk_jsonrpc_server_dequeue_request(struct spdk_jsonrpc_server_conn *conn)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = NULL;
|
|
|
|
|
|
|
|
pthread_spin_lock(&conn->queue_lock);
|
|
|
|
request = STAILQ_FIRST(&conn->send_queue);
|
|
|
|
if (request) {
|
|
|
|
STAILQ_REMOVE_HEAD(&conn->send_queue, link);
|
|
|
|
}
|
|
|
|
pthread_spin_unlock(&conn->queue_lock);
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_jsonrpc_server_free_conn_request(struct spdk_jsonrpc_server_conn *conn)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
|
|
|
|
spdk_jsonrpc_free_request(conn->send_request);
|
|
|
|
conn->send_request = NULL ;
|
|
|
|
while ((request = spdk_jsonrpc_server_dequeue_request(conn)) != NULL) {
|
|
|
|
spdk_jsonrpc_free_request(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 15:28:23 +00:00
|
|
|
static void
|
|
|
|
spdk_jsonrpc_server_conn_close(struct spdk_jsonrpc_server_conn *conn)
|
|
|
|
{
|
|
|
|
conn->closed = true;
|
|
|
|
|
|
|
|
if (conn->sockfd >= 0) {
|
2019-06-18 18:36:05 +00:00
|
|
|
spdk_jsonrpc_server_free_conn_request(conn);
|
2018-12-05 15:28:23 +00:00
|
|
|
close(conn->sockfd);
|
|
|
|
conn->sockfd = -1;
|
|
|
|
|
|
|
|
if (conn->close_cb) {
|
|
|
|
conn->close_cb(conn, conn->close_cb_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 20:29:37 +00:00
|
|
|
void
|
|
|
|
spdk_jsonrpc_server_shutdown(struct spdk_jsonrpc_server *server)
|
|
|
|
{
|
2018-06-07 20:21:03 +00:00
|
|
|
struct spdk_jsonrpc_server_conn *conn;
|
2016-05-19 20:29:37 +00:00
|
|
|
|
|
|
|
close(server->sockfd);
|
|
|
|
|
2018-06-07 20:21:03 +00:00
|
|
|
TAILQ_FOREACH(conn, &server->conns, link) {
|
2018-12-05 15:28:23 +00:00
|
|
|
spdk_jsonrpc_server_conn_close(conn);
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(server);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_jsonrpc_server_conn_remove(struct spdk_jsonrpc_server_conn *conn)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_server *server = conn->server;
|
|
|
|
|
2017-07-12 19:56:02 +00:00
|
|
|
spdk_jsonrpc_server_conn_close(conn);
|
2016-05-19 20:29:37 +00:00
|
|
|
|
2018-04-10 22:13:17 +00:00
|
|
|
pthread_spin_destroy(&conn->queue_lock);
|
|
|
|
assert(STAILQ_EMPTY(&conn->send_queue));
|
2017-07-07 00:41:53 +00:00
|
|
|
|
2018-06-07 20:21:03 +00:00
|
|
|
TAILQ_REMOVE(&server->conns, conn, link);
|
|
|
|
TAILQ_INSERT_HEAD(&server->free_conns, conn, link);
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 15:28:23 +00:00
|
|
|
int
|
|
|
|
spdk_jsonrpc_conn_add_close_cb(struct spdk_jsonrpc_server_conn *conn,
|
|
|
|
spdk_jsonrpc_conn_closed_fn cb, void *ctx)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
pthread_spin_lock(&conn->queue_lock);
|
|
|
|
if (conn->close_cb == NULL) {
|
|
|
|
conn->close_cb = cb;
|
|
|
|
conn->close_cb_ctx = ctx;
|
|
|
|
} else {
|
|
|
|
rc = conn->close_cb == cb && conn->close_cb_ctx == ctx ? -EEXIST : -ENOSPC;
|
|
|
|
}
|
|
|
|
pthread_spin_unlock(&conn->queue_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_jsonrpc_conn_del_close_cb(struct spdk_jsonrpc_server_conn *conn,
|
|
|
|
spdk_jsonrpc_conn_closed_fn cb, void *ctx)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
pthread_spin_lock(&conn->queue_lock);
|
|
|
|
if (conn->close_cb == NULL || conn->close_cb != cb || conn->close_cb_ctx != ctx) {
|
|
|
|
rc = -ENOENT;
|
|
|
|
} else {
|
|
|
|
conn->close_cb = NULL;
|
|
|
|
}
|
|
|
|
pthread_spin_unlock(&conn->queue_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-05-19 20:29:37 +00:00
|
|
|
static int
|
|
|
|
spdk_jsonrpc_server_accept(struct spdk_jsonrpc_server *server)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_server_conn *conn;
|
2018-06-07 20:21:03 +00:00
|
|
|
int rc, flag;
|
2016-05-19 20:29:37 +00:00
|
|
|
|
|
|
|
rc = accept(server->sockfd, NULL, NULL);
|
|
|
|
if (rc >= 0) {
|
2018-06-07 20:21:03 +00:00
|
|
|
conn = TAILQ_FIRST(&server->free_conns);
|
|
|
|
assert(conn != NULL);
|
|
|
|
|
2016-05-19 20:29:37 +00:00
|
|
|
conn->server = server;
|
|
|
|
conn->sockfd = rc;
|
2017-07-07 00:41:53 +00:00
|
|
|
conn->closed = false;
|
2016-05-19 20:29:37 +00:00
|
|
|
conn->recv_len = 0;
|
2017-07-07 00:41:53 +00:00
|
|
|
conn->outstanding_requests = 0;
|
2018-04-10 22:13:17 +00:00
|
|
|
pthread_spin_init(&conn->queue_lock, PTHREAD_PROCESS_PRIVATE);
|
|
|
|
STAILQ_INIT(&conn->send_queue);
|
2017-07-07 00:41:53 +00:00
|
|
|
conn->send_request = NULL;
|
2016-05-19 20:29:37 +00:00
|
|
|
|
2017-11-27 14:57:41 +00:00
|
|
|
flag = fcntl(conn->sockfd, F_GETFL);
|
|
|
|
if (fcntl(conn->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
2017-11-07 12:56:52 +00:00
|
|
|
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
|
|
|
|
conn->sockfd, spdk_strerror(errno));
|
2016-05-19 20:29:37 +00:00
|
|
|
close(conn->sockfd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-07 20:21:03 +00:00
|
|
|
TAILQ_REMOVE(&server->free_conns, conn, link);
|
|
|
|
TAILQ_INSERT_TAIL(&server->conns, conn, link);
|
2016-05-19 20:29:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_server_handle_request(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *method, const struct spdk_json_val *params)
|
2016-05-19 20:29:37 +00:00
|
|
|
{
|
2017-06-29 20:37:39 +00:00
|
|
|
request->conn->server->handle_request(request, method, params);
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_request *request, int error)
|
2016-05-19 20:29:37 +00:00
|
|
|
{
|
|
|
|
const char *msg;
|
|
|
|
|
|
|
|
switch (error) {
|
|
|
|
case SPDK_JSONRPC_ERROR_PARSE_ERROR:
|
|
|
|
msg = "Parse error";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_JSONRPC_ERROR_INVALID_REQUEST:
|
|
|
|
msg = "Invalid request";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_JSONRPC_ERROR_METHOD_NOT_FOUND:
|
|
|
|
msg = "Method not found";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_JSONRPC_ERROR_INVALID_PARAMS:
|
|
|
|
msg = "Invalid parameters";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPDK_JSONRPC_ERROR_INTERNAL_ERROR:
|
|
|
|
msg = "Internal error";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg = "Error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, error, msg);
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_jsonrpc_server_conn_recv(struct spdk_jsonrpc_server_conn *conn)
|
|
|
|
{
|
2018-12-13 14:00:12 +00:00
|
|
|
ssize_t rc, offset;
|
2016-05-19 20:29:37 +00:00
|
|
|
size_t recv_avail = SPDK_JSONRPC_RECV_BUF_SIZE - conn->recv_len;
|
|
|
|
|
|
|
|
rc = recv(conn->sockfd, conn->recv_buf + conn->recv_len, recv_avail, 0);
|
|
|
|
if (rc == -1) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-07 12:56:52 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_RPC, "recv() failed: %s\n", spdk_strerror(errno));
|
2016-05-19 20:29:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == 0) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_RPC, "remote closed connection\n");
|
2019-01-23 13:38:01 +00:00
|
|
|
conn->closed = true;
|
|
|
|
return 0;
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conn->recv_len += rc;
|
|
|
|
|
2018-12-13 14:00:12 +00:00
|
|
|
offset = 0;
|
|
|
|
do {
|
|
|
|
rc = spdk_jsonrpc_parse_request(conn, conn->recv_buf + offset, conn->recv_len - offset);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("jsonrpc parse request failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += rc;
|
|
|
|
} while (rc > 0);
|
2016-05-19 20:29:37 +00:00
|
|
|
|
2018-12-13 14:00:12 +00:00
|
|
|
if (offset > 0) {
|
2016-05-19 20:29:37 +00:00
|
|
|
/*
|
2018-12-13 14:00:12 +00:00
|
|
|
* Successfully parsed a requests - move any data past the end of the
|
|
|
|
* parsed requests down to the beginning.
|
2016-05-19 20:29:37 +00:00
|
|
|
*/
|
2018-12-13 14:00:12 +00:00
|
|
|
assert((size_t)offset <= conn->recv_len);
|
|
|
|
memmove(conn->recv_buf, conn->recv_buf + offset, conn->recv_len - offset);
|
|
|
|
conn->recv_len -= offset;
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-07 00:41:53 +00:00
|
|
|
void
|
2018-08-13 18:46:01 +00:00
|
|
|
spdk_jsonrpc_server_send_response(struct spdk_jsonrpc_request *request)
|
2017-07-07 00:41:53 +00:00
|
|
|
{
|
2018-08-13 18:46:01 +00:00
|
|
|
struct spdk_jsonrpc_server_conn *conn = request->conn;
|
|
|
|
|
2017-07-07 00:41:53 +00:00
|
|
|
/* Queue the response to be sent */
|
2018-04-10 22:13:17 +00:00
|
|
|
pthread_spin_lock(&conn->queue_lock);
|
|
|
|
STAILQ_INSERT_TAIL(&conn->send_queue, request, link);
|
|
|
|
pthread_spin_unlock(&conn->queue_lock);
|
2017-07-07 00:41:53 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 22:13:17 +00:00
|
|
|
|
2016-05-19 20:29:37 +00:00
|
|
|
static int
|
|
|
|
spdk_jsonrpc_server_conn_send(struct spdk_jsonrpc_server_conn *conn)
|
|
|
|
{
|
2017-07-07 00:41:53 +00:00
|
|
|
struct spdk_jsonrpc_request *request;
|
2016-05-19 20:29:37 +00:00
|
|
|
ssize_t rc;
|
|
|
|
|
2017-07-07 00:41:53 +00:00
|
|
|
more:
|
|
|
|
if (conn->outstanding_requests == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conn->send_request == NULL) {
|
2018-04-10 22:13:17 +00:00
|
|
|
conn->send_request = spdk_jsonrpc_server_dequeue_request(conn);
|
2017-07-07 00:41:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
request = conn->send_request;
|
|
|
|
if (request == NULL) {
|
|
|
|
/* Nothing to send right now */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-13 18:46:01 +00:00
|
|
|
if (request->send_len > 0) {
|
|
|
|
rc = send(conn->sockfd, request->send_buf + request->send_offset,
|
|
|
|
request->send_len, 0);
|
|
|
|
if (rc < 0) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_RPC, "send() failed: %s\n", spdk_strerror(errno));
|
|
|
|
return -1;
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 18:46:01 +00:00
|
|
|
request->send_offset += rc;
|
|
|
|
request->send_len -= rc;
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 00:41:53 +00:00
|
|
|
if (request->send_len == 0) {
|
|
|
|
/*
|
|
|
|
* Full response has been sent.
|
|
|
|
* Free it and set send_request to NULL to move on to the next queued response.
|
|
|
|
*/
|
|
|
|
conn->send_request = NULL;
|
|
|
|
spdk_jsonrpc_free_request(request);
|
|
|
|
goto more;
|
|
|
|
}
|
2016-05-19 20:29:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_jsonrpc_server_poll(struct spdk_jsonrpc_server *server)
|
|
|
|
{
|
2018-06-07 20:21:03 +00:00
|
|
|
int rc;
|
|
|
|
struct spdk_jsonrpc_server_conn *conn, *conn_tmp;
|
2017-07-07 00:41:53 +00:00
|
|
|
|
2018-06-07 20:21:03 +00:00
|
|
|
TAILQ_FOREACH_SAFE(conn, &server->conns, link, conn_tmp) {
|
2019-01-23 13:38:01 +00:00
|
|
|
/* If we can't receive and there are no outstanding requests close the connection. */
|
|
|
|
if (conn->closed == true && conn->outstanding_requests == 0) {
|
|
|
|
spdk_jsonrpc_server_conn_close(conn);
|
|
|
|
}
|
|
|
|
|
2019-06-18 18:36:05 +00:00
|
|
|
if (conn->sockfd == -1 && conn->outstanding_requests == 0) {
|
|
|
|
spdk_jsonrpc_server_conn_remove(conn);
|
2017-07-07 00:41:53 +00:00
|
|
|
}
|
2017-07-12 20:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check listen socket */
|
2018-06-07 20:21:03 +00:00
|
|
|
if (!TAILQ_EMPTY(&server->free_conns)) {
|
2017-07-18 18:34:01 +00:00
|
|
|
spdk_jsonrpc_server_accept(server);
|
2017-07-12 20:11:11 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 20:21:03 +00:00
|
|
|
TAILQ_FOREACH(conn, &server->conns, link) {
|
2019-01-23 13:38:01 +00:00
|
|
|
if (conn->sockfd == -1) {
|
2017-07-18 18:34:01 +00:00
|
|
|
continue;
|
2017-07-07 00:41:53 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 18:34:01 +00:00
|
|
|
rc = spdk_jsonrpc_server_conn_send(conn);
|
|
|
|
if (rc != 0) {
|
|
|
|
spdk_jsonrpc_server_conn_close(conn);
|
|
|
|
continue;
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
2017-07-07 00:41:53 +00:00
|
|
|
|
2019-01-23 13:38:01 +00:00
|
|
|
if (!conn->closed) {
|
|
|
|
rc = spdk_jsonrpc_server_conn_recv(conn);
|
|
|
|
if (rc != 0) {
|
|
|
|
spdk_jsonrpc_server_conn_close(conn);
|
|
|
|
}
|
2017-07-12 19:56:02 +00:00
|
|
|
}
|
2016-05-19 20:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|