1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2017 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/stdinc.h" 7 8 #include "spdk/env.h" 9 #include "spdk/init.h" 10 #include "spdk/thread.h" 11 #include "spdk/log.h" 12 #include "spdk/rpc.h" 13 14 #define RPC_SELECT_INTERVAL 4000 /* 4ms */ 15 16 static struct spdk_poller *g_rpc_poller = NULL; 17 18 static int 19 rpc_subsystem_poll(void *arg) 20 { 21 spdk_rpc_accept(); 22 return SPDK_POLLER_BUSY; 23 } 24 25 int 26 spdk_rpc_initialize(const char *listen_addr) 27 { 28 int rc; 29 30 if (listen_addr == NULL) { 31 /* Not treated as an error */ 32 return 0; 33 } 34 35 if (!spdk_rpc_verify_methods()) { 36 return -EINVAL; 37 } 38 39 /* Listen on the requested address */ 40 rc = spdk_rpc_listen(listen_addr); 41 if (rc != 0) { 42 SPDK_ERRLOG("Unable to start RPC service at %s\n", listen_addr); 43 /* TODO: Eventually, treat this as an error. But it historically has not 44 * been and many tests rely on this gracefully failing. */ 45 return 0; 46 } 47 48 spdk_rpc_set_state(SPDK_RPC_STARTUP); 49 50 /* Register a poller to periodically check for RPCs */ 51 g_rpc_poller = SPDK_POLLER_REGISTER(rpc_subsystem_poll, NULL, RPC_SELECT_INTERVAL); 52 53 return 0; 54 } 55 56 void 57 spdk_rpc_finish(void) 58 { 59 spdk_rpc_close(); 60 spdk_poller_unregister(&g_rpc_poller); 61 } 62