2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2018 Intel Corporation.
|
2018-08-02 16:07:50 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/thread.h"
|
|
|
|
#include "spdk/env.h"
|
|
|
|
#include "spdk/event.h"
|
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/string.h"
|
|
|
|
|
|
|
|
#include "spdk/sock.h"
|
|
|
|
|
|
|
|
#define ACCEPT_TIMEOUT_US 1000
|
|
|
|
#define CLOSE_TIMEOUT_US 1000000
|
|
|
|
#define BUFFER_SIZE 1024
|
|
|
|
#define ADDR_STR_LEN INET6_ADDRSTRLEN
|
|
|
|
|
|
|
|
static bool g_is_running;
|
|
|
|
|
|
|
|
static char *g_host;
|
2020-01-18 16:07:36 +00:00
|
|
|
static char *g_sock_impl_name;
|
2018-08-02 16:07:50 +00:00
|
|
|
static int g_port;
|
|
|
|
static bool g_is_server;
|
2022-05-02 06:00:14 +00:00
|
|
|
static int g_zcopy;
|
2022-05-11 14:27:38 +00:00
|
|
|
static int g_ktls;
|
|
|
|
static int g_tls_version;
|
2018-08-02 16:07:50 +00:00
|
|
|
static bool g_verbose;
|
2022-07-22 14:27:45 +00:00
|
|
|
static char *g_psk_key;
|
|
|
|
static char *g_psk_identity;
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We'll use this struct to gather housekeeping hello_context to pass between
|
|
|
|
* our events and callbacks.
|
|
|
|
*/
|
|
|
|
struct hello_context_t {
|
|
|
|
bool is_server;
|
|
|
|
char *host;
|
2020-01-18 16:07:36 +00:00
|
|
|
char *sock_impl_name;
|
2018-08-02 16:07:50 +00:00
|
|
|
int port;
|
2022-05-02 06:00:14 +00:00
|
|
|
int zcopy;
|
2022-05-11 14:27:38 +00:00
|
|
|
int ktls;
|
|
|
|
int tls_version;
|
2022-07-22 14:27:45 +00:00
|
|
|
char *psk_key;
|
|
|
|
char *psk_identity;
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
bool verbose;
|
|
|
|
int bytes_in;
|
|
|
|
int bytes_out;
|
|
|
|
|
|
|
|
struct spdk_sock *sock;
|
|
|
|
|
|
|
|
struct spdk_sock_group *group;
|
|
|
|
struct spdk_poller *poller_in;
|
|
|
|
struct spdk_poller *poller_out;
|
|
|
|
struct spdk_poller *time_out;
|
2018-09-26 07:55:28 +00:00
|
|
|
|
|
|
|
int rc;
|
2018-08-02 16:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Usage function for printing parameters that are specific to this application
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
hello_sock_usage(void)
|
|
|
|
{
|
2022-07-22 14:27:45 +00:00
|
|
|
printf(" -E psk_key Default PSK KEY in hexadecimal digits, e.g. 1234567890ABCDEF (only applies when sock_impl == ssl)\n");
|
2018-08-02 16:07:50 +00:00
|
|
|
printf(" -H host_addr host address\n");
|
2022-07-22 14:27:45 +00:00
|
|
|
printf(" -I psk_id Default PSK ID, e.g. psk.spdk.io (only applies when sock_impl == ssl)\n");
|
2018-08-02 16:07:50 +00:00
|
|
|
printf(" -P port port number\n");
|
2020-08-11 09:46:18 +00:00
|
|
|
printf(" -N sock_impl socket implementation, e.g., -N posix or -N uring\n");
|
2018-08-02 16:07:50 +00:00
|
|
|
printf(" -S start in server mode\n");
|
2022-05-11 14:27:38 +00:00
|
|
|
printf(" -T tls_ver TLS version, e.g., -T 12 or -T 13. If omitted, auto-negotiation will take place\n");
|
|
|
|
printf(" -k disable KTLS for the given sock implementation (default)\n");
|
|
|
|
printf(" -K enable KTLS for the given sock implementation\n");
|
2022-11-02 15:09:36 +00:00
|
|
|
printf(" -V print out additional information\n");
|
2022-05-02 06:00:14 +00:00
|
|
|
printf(" -z disable zero copy send for the given sock implementation\n");
|
|
|
|
printf(" -Z enable zero copy send for the given sock implementation\n");
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called to parse the parameters that are specific to this application
|
|
|
|
*/
|
2022-06-22 21:35:04 +00:00
|
|
|
static int
|
|
|
|
hello_sock_parse_arg(int ch, char *arg)
|
2018-08-02 16:07:50 +00:00
|
|
|
{
|
|
|
|
switch (ch) {
|
2022-07-22 14:27:45 +00:00
|
|
|
case 'E':
|
|
|
|
g_psk_key = arg;
|
|
|
|
break;
|
2018-08-02 16:07:50 +00:00
|
|
|
case 'H':
|
|
|
|
g_host = arg;
|
|
|
|
break;
|
2022-07-22 14:27:45 +00:00
|
|
|
case 'I':
|
|
|
|
g_psk_identity = arg;
|
|
|
|
break;
|
2020-01-18 16:07:36 +00:00
|
|
|
case 'N':
|
|
|
|
g_sock_impl_name = arg;
|
|
|
|
break;
|
2018-08-02 16:07:50 +00:00
|
|
|
case 'P':
|
2019-01-23 01:01:26 +00:00
|
|
|
g_port = spdk_strtol(arg, 10);
|
|
|
|
if (g_port < 0) {
|
|
|
|
fprintf(stderr, "Invalid port ID\n");
|
|
|
|
return g_port;
|
|
|
|
}
|
2018-08-02 16:07:50 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
g_is_server = 1;
|
|
|
|
break;
|
2022-05-11 14:27:38 +00:00
|
|
|
case 'K':
|
|
|
|
g_ktls = 1;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
g_ktls = 0;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
g_tls_version = spdk_strtol(arg, 10);
|
|
|
|
if (g_tls_version < 0) {
|
|
|
|
fprintf(stderr, "Invalid TLS version\n");
|
|
|
|
return g_tls_version;
|
|
|
|
}
|
|
|
|
break;
|
2018-08-02 16:07:50 +00:00
|
|
|
case 'V':
|
|
|
|
g_verbose = true;
|
2019-01-21 14:56:47 +00:00
|
|
|
break;
|
2022-05-02 06:00:14 +00:00
|
|
|
case 'Z':
|
|
|
|
g_zcopy = 1;
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
g_zcopy = 0;
|
|
|
|
break;
|
2019-01-21 14:56:47 +00:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
2019-01-08 19:40:06 +00:00
|
|
|
return 0;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_close_timeout_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct hello_context_t *ctx = arg;
|
|
|
|
SPDK_NOTICELOG("Connection closed\n");
|
|
|
|
|
|
|
|
spdk_poller_unregister(&ctx->time_out);
|
|
|
|
spdk_poller_unregister(&ctx->poller_in);
|
|
|
|
spdk_sock_close(&ctx->sock);
|
2018-09-26 07:55:28 +00:00
|
|
|
spdk_sock_group_close(&ctx->group);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
2019-08-30 10:10:21 +00:00
|
|
|
spdk_app_stop(ctx->rc);
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2018-09-26 07:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_quit(struct hello_context_t *ctx, int rc)
|
|
|
|
{
|
|
|
|
ctx->rc = rc;
|
|
|
|
spdk_poller_unregister(&ctx->poller_out);
|
2018-12-14 11:17:46 +00:00
|
|
|
if (!ctx->time_out) {
|
2020-04-14 06:49:46 +00:00
|
|
|
ctx->time_out = SPDK_POLLER_REGISTER(hello_sock_close_timeout_poll, ctx,
|
2018-12-14 11:17:46 +00:00
|
|
|
CLOSE_TIMEOUT_US);
|
|
|
|
}
|
2018-08-02 16:07:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_recv_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct hello_context_t *ctx = arg;
|
|
|
|
int rc;
|
|
|
|
char buf_in[BUFFER_SIZE];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get response
|
|
|
|
*/
|
|
|
|
rc = spdk_sock_recv(ctx->sock, buf_in, sizeof(buf_in) - 1);
|
|
|
|
|
|
|
|
if (rc <= 0) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_IDLE;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
|
|
|
|
errno, spdk_strerror(errno));
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc > 0) {
|
|
|
|
ctx->bytes_in += rc;
|
|
|
|
buf_in[rc] = '\0';
|
|
|
|
printf("%s", buf_in);
|
|
|
|
}
|
|
|
|
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_writev_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct hello_context_t *ctx = arg;
|
|
|
|
int rc = 0;
|
|
|
|
char buf_out[BUFFER_SIZE];
|
|
|
|
struct iovec iov;
|
|
|
|
ssize_t n;
|
|
|
|
|
|
|
|
n = read(STDIN_FILENO, buf_out, sizeof(buf_out));
|
|
|
|
if (n == 0 || !g_is_running) {
|
|
|
|
/* EOF */
|
|
|
|
SPDK_NOTICELOG("Closing connection...\n");
|
2018-09-26 07:55:28 +00:00
|
|
|
hello_sock_quit(ctx, 0);
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_IDLE;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
if (n > 0) {
|
|
|
|
/*
|
|
|
|
* Send message to the server
|
|
|
|
*/
|
|
|
|
iov.iov_base = buf_out;
|
|
|
|
iov.iov_len = n;
|
|
|
|
rc = spdk_sock_writev(ctx->sock, &iov, 1);
|
|
|
|
if (rc > 0) {
|
|
|
|
ctx->bytes_out += rc;
|
|
|
|
}
|
|
|
|
}
|
2021-07-01 18:45:51 +00:00
|
|
|
return rc > 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_connect(struct hello_context_t *ctx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
char saddr[ADDR_STR_LEN], caddr[ADDR_STR_LEN];
|
2018-10-08 01:51:03 +00:00
|
|
|
uint16_t cport, sport;
|
2022-05-02 16:08:50 +00:00
|
|
|
struct spdk_sock_impl_opts impl_opts;
|
|
|
|
size_t impl_opts_size = sizeof(impl_opts);
|
2022-05-02 06:00:14 +00:00
|
|
|
struct spdk_sock_opts opts;
|
|
|
|
|
2022-05-02 16:08:50 +00:00
|
|
|
spdk_sock_impl_get_opts(ctx->sock_impl_name, &impl_opts, &impl_opts_size);
|
|
|
|
impl_opts.enable_ktls = ctx->ktls;
|
|
|
|
impl_opts.tls_version = ctx->tls_version;
|
2022-07-22 14:27:45 +00:00
|
|
|
impl_opts.psk_key = ctx->psk_key;
|
|
|
|
impl_opts.psk_identity = ctx->psk_identity;
|
2022-05-02 16:08:50 +00:00
|
|
|
|
2022-05-02 06:00:14 +00:00
|
|
|
opts.opts_size = sizeof(opts);
|
|
|
|
spdk_sock_get_default_opts(&opts);
|
|
|
|
opts.zcopy = ctx->zcopy;
|
2022-05-02 16:08:50 +00:00
|
|
|
opts.impl_opts = &impl_opts;
|
|
|
|
opts.impl_opts_size = sizeof(impl_opts);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
2020-01-18 16:07:36 +00:00
|
|
|
SPDK_NOTICELOG("Connecting to the server on %s:%d with sock_impl(%s)\n", ctx->host, ctx->port,
|
|
|
|
ctx->sock_impl_name);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
2022-05-02 06:00:14 +00:00
|
|
|
ctx->sock = spdk_sock_connect_ext(ctx->host, ctx->port, ctx->sock_impl_name, &opts);
|
2018-08-02 16:07:50 +00:00
|
|
|
if (ctx->sock == NULL) {
|
|
|
|
SPDK_ERRLOG("connect error(%d): %s\n", errno, spdk_strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-08 01:51:03 +00:00
|
|
|
rc = spdk_sock_getaddr(ctx->sock, saddr, sizeof(saddr), &sport, caddr, sizeof(caddr), &cport);
|
2018-08-02 16:07:50 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Cannot get connection addresses\n");
|
|
|
|
spdk_sock_close(&ctx->sock);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-08 01:51:03 +00:00
|
|
|
SPDK_NOTICELOG("Connection accepted from (%s, %hu) to (%s, %hu)\n", caddr, cport, saddr, sport);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK);
|
|
|
|
|
|
|
|
g_is_running = true;
|
2020-04-14 06:49:46 +00:00
|
|
|
ctx->poller_in = SPDK_POLLER_REGISTER(hello_sock_recv_poll, ctx, 0);
|
|
|
|
ctx->poller_out = SPDK_POLLER_REGISTER(hello_sock_writev_poll, ctx, 0);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hello_sock_cb(void *arg, struct spdk_sock_group *group, struct spdk_sock *sock)
|
|
|
|
{
|
|
|
|
ssize_t n;
|
|
|
|
char buf[BUFFER_SIZE];
|
|
|
|
struct iovec iov;
|
|
|
|
struct hello_context_t *ctx = arg;
|
|
|
|
|
|
|
|
n = spdk_sock_recv(sock, buf, sizeof(buf));
|
|
|
|
if (n < 0) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
|
|
SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
|
|
|
|
errno, spdk_strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
|
|
|
|
errno, spdk_strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
ctx->bytes_in += n;
|
|
|
|
iov.iov_base = buf;
|
|
|
|
iov.iov_len = n;
|
|
|
|
n = spdk_sock_writev(sock, &iov, 1);
|
|
|
|
if (n > 0) {
|
|
|
|
ctx->bytes_out += n;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connection closed */
|
|
|
|
SPDK_NOTICELOG("Connection closed\n");
|
|
|
|
spdk_sock_group_remove_sock(group, sock);
|
|
|
|
spdk_sock_close(&sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_accept_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct hello_context_t *ctx = arg;
|
|
|
|
struct spdk_sock *sock;
|
|
|
|
int rc;
|
|
|
|
int count = 0;
|
|
|
|
char saddr[ADDR_STR_LEN], caddr[ADDR_STR_LEN];
|
2018-10-08 01:51:03 +00:00
|
|
|
uint16_t cport, sport;
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
if (!g_is_running) {
|
2018-09-26 07:55:28 +00:00
|
|
|
hello_sock_quit(ctx, 0);
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_IDLE;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
sock = spdk_sock_accept(ctx->sock);
|
|
|
|
if (sock != NULL) {
|
2018-09-26 07:55:28 +00:00
|
|
|
rc = spdk_sock_getaddr(sock, saddr, sizeof(saddr), &sport, caddr, sizeof(caddr), &cport);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Cannot get connection addresses\n");
|
2022-12-15 06:22:02 +00:00
|
|
|
spdk_sock_close(&sock);
|
2021-07-01 18:45:51 +00:00
|
|
|
return SPDK_POLLER_IDLE;
|
2018-09-26 07:55:28 +00:00
|
|
|
}
|
2018-08-02 16:07:50 +00:00
|
|
|
|
2018-10-08 01:51:03 +00:00
|
|
|
SPDK_NOTICELOG("Accepting a new connection from (%s, %hu) to (%s, %hu)\n",
|
|
|
|
caddr, cport, saddr, sport);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
rc = spdk_sock_group_add_sock(ctx->group, sock,
|
|
|
|
hello_sock_cb, ctx);
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
spdk_sock_close(&sock);
|
|
|
|
SPDK_ERRLOG("failed\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
count++;
|
|
|
|
} else {
|
|
|
|
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
|
|
|
SPDK_ERRLOG("accept error(%d): %s\n", errno, spdk_strerror(errno));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-01 18:45:51 +00:00
|
|
|
return count > 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_group_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct hello_context_t *ctx = arg;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_sock_group_poll(ctx->group);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to poll sock_group=%p\n", ctx->group);
|
|
|
|
}
|
|
|
|
|
2021-07-01 18:45:51 +00:00
|
|
|
return rc > 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE;
|
2018-08-02 16:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hello_sock_listen(struct hello_context_t *ctx)
|
|
|
|
{
|
2022-05-02 16:08:50 +00:00
|
|
|
struct spdk_sock_impl_opts impl_opts;
|
|
|
|
size_t impl_opts_size = sizeof(impl_opts);
|
2022-05-02 06:00:14 +00:00
|
|
|
struct spdk_sock_opts opts;
|
|
|
|
|
2022-05-02 16:08:50 +00:00
|
|
|
spdk_sock_impl_get_opts(ctx->sock_impl_name, &impl_opts, &impl_opts_size);
|
|
|
|
impl_opts.enable_ktls = ctx->ktls;
|
|
|
|
impl_opts.tls_version = ctx->tls_version;
|
2022-07-22 14:27:45 +00:00
|
|
|
impl_opts.psk_key = ctx->psk_key;
|
|
|
|
impl_opts.psk_identity = ctx->psk_identity;
|
2022-05-02 16:08:50 +00:00
|
|
|
|
2022-05-02 06:00:14 +00:00
|
|
|
opts.opts_size = sizeof(opts);
|
|
|
|
spdk_sock_get_default_opts(&opts);
|
|
|
|
opts.zcopy = ctx->zcopy;
|
2022-05-02 16:08:50 +00:00
|
|
|
opts.impl_opts = &impl_opts;
|
|
|
|
opts.impl_opts_size = sizeof(impl_opts);
|
2022-05-02 06:00:14 +00:00
|
|
|
|
|
|
|
ctx->sock = spdk_sock_listen_ext(ctx->host, ctx->port, ctx->sock_impl_name, &opts);
|
2018-08-02 16:07:50 +00:00
|
|
|
if (ctx->sock == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot create server socket\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-01-18 16:07:36 +00:00
|
|
|
SPDK_NOTICELOG("Listening connection on %s:%d with sock_impl(%s)\n", ctx->host, ctx->port,
|
|
|
|
ctx->sock_impl_name);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create sock group for server socket
|
|
|
|
*/
|
2019-05-14 18:40:20 +00:00
|
|
|
ctx->group = spdk_sock_group_create(NULL);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
g_is_running = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start acceptor and group poller
|
|
|
|
*/
|
2020-04-14 06:49:46 +00:00
|
|
|
ctx->poller_in = SPDK_POLLER_REGISTER(hello_sock_accept_poll, ctx,
|
2018-08-02 16:07:50 +00:00
|
|
|
ACCEPT_TIMEOUT_US);
|
2020-04-14 06:49:46 +00:00
|
|
|
ctx->poller_out = SPDK_POLLER_REGISTER(hello_sock_group_poll, ctx, 0);
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hello_sock_shutdown_cb(void)
|
|
|
|
{
|
|
|
|
g_is_running = false;
|
|
|
|
}
|
2018-09-26 07:55:28 +00:00
|
|
|
|
2018-08-02 16:07:50 +00:00
|
|
|
/*
|
|
|
|
* Our initial event that kicks off everything from main().
|
|
|
|
*/
|
|
|
|
static void
|
2019-08-30 10:10:21 +00:00
|
|
|
hello_start(void *arg1)
|
2018-08-02 16:07:50 +00:00
|
|
|
{
|
|
|
|
struct hello_context_t *ctx = arg1;
|
2019-08-30 10:10:21 +00:00
|
|
|
int rc;
|
2018-08-02 16:07:50 +00:00
|
|
|
|
|
|
|
SPDK_NOTICELOG("Successfully started the application\n");
|
|
|
|
|
|
|
|
if (ctx->is_server) {
|
|
|
|
rc = hello_sock_listen(ctx);
|
|
|
|
} else {
|
|
|
|
rc = hello_sock_connect(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
spdk_app_stop(-1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct spdk_app_opts opts = {};
|
|
|
|
int rc = 0;
|
|
|
|
struct hello_context_t hello_context = {};
|
|
|
|
|
|
|
|
/* Set default values in opts structure. */
|
2020-11-30 11:38:37 +00:00
|
|
|
spdk_app_opts_init(&opts, sizeof(opts));
|
2018-08-02 16:07:50 +00:00
|
|
|
opts.name = "hello_sock";
|
|
|
|
opts.shutdown_cb = hello_sock_shutdown_cb;
|
|
|
|
|
2022-07-22 14:27:45 +00:00
|
|
|
if ((rc = spdk_app_parse_args(argc, argv, &opts, "E:H:I:kKN:P:ST:VzZ", NULL, hello_sock_parse_arg,
|
2018-08-02 16:07:50 +00:00
|
|
|
hello_sock_usage)) != SPDK_APP_PARSE_ARGS_SUCCESS) {
|
|
|
|
exit(rc);
|
|
|
|
}
|
|
|
|
hello_context.is_server = g_is_server;
|
|
|
|
hello_context.host = g_host;
|
2020-01-18 16:07:36 +00:00
|
|
|
hello_context.sock_impl_name = g_sock_impl_name;
|
2018-08-02 16:07:50 +00:00
|
|
|
hello_context.port = g_port;
|
2022-05-02 06:00:14 +00:00
|
|
|
hello_context.zcopy = g_zcopy;
|
2022-05-11 14:27:38 +00:00
|
|
|
hello_context.ktls = g_ktls;
|
|
|
|
hello_context.tls_version = g_tls_version;
|
2022-07-22 14:27:45 +00:00
|
|
|
hello_context.psk_key = g_psk_key;
|
|
|
|
hello_context.psk_identity = g_psk_identity;
|
2018-08-02 16:07:50 +00:00
|
|
|
hello_context.verbose = g_verbose;
|
|
|
|
|
2019-08-30 10:10:21 +00:00
|
|
|
rc = spdk_app_start(&opts, hello_start, &hello_context);
|
2018-08-02 16:07:50 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("ERROR starting application\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_NOTICELOG("Exiting from application\n");
|
|
|
|
|
|
|
|
if (hello_context.verbose) {
|
|
|
|
printf("** %d bytes received, %d bytes sent **\n",
|
|
|
|
hello_context.bytes_in, hello_context.bytes_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gracefully close out all of the SPDK subsystems. */
|
|
|
|
spdk_app_fini();
|
|
|
|
return rc;
|
|
|
|
}
|