From 743ed86373eed67da6c1ff710016983de245f080 Mon Sep 17 00:00:00 2001 From: Vladimir Davydov <vdavydov@tarantool.org> Date: Tue, 21 Dec 2021 17:11:19 +0300 Subject: [PATCH] evio: store uri in evio_service_entry The uri is passed to the accept callback. Currently, it's unused, but in future we will use uri parameters to configure connections (e.g. setup encryption). --- src/box/iproto.cc | 7 ++++--- src/lib/core/coio.c | 4 +++- src/lib/core/coio.h | 1 + src/lib/core/evio.c | 32 ++++++++++++++++---------------- src/lib/core/evio.h | 8 +++++--- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/box/iproto.cc b/src/box/iproto.cc index 42bc310223..d2a84af638 100644 --- a/src/box/iproto.cc +++ b/src/box/iproto.cc @@ -2565,11 +2565,12 @@ net_send_greeting(struct cmsg *m) * Create a connection and start input. */ static int -iproto_on_accept(struct evio_service *service, int fd, +iproto_on_accept(struct evio_service *service, const struct uri *uri, int fd, struct sockaddr *addr, socklen_t addrlen) { - (void) addr; - (void) addrlen; + (void)uri; + (void)addr; + (void)addrlen; struct iproto_msg *msg; struct iproto_thread *iproto_thread = diff --git a/src/lib/core/coio.c b/src/lib/core/coio.c index 844f394971..2729d5afe6 100644 --- a/src/lib/core/coio.c +++ b/src/lib/core/coio.c @@ -40,6 +40,7 @@ #include "iostream.h" #include "sio.h" #include "coio_task.h" /* coio_resolve() */ +#include "uri/uri.h" typedef void (*ev_stat_cb)(ev_loop *, ev_stat *, int); @@ -469,9 +470,10 @@ coio_writev_timeout(struct iostream *io, struct iovec *iov, int iovcnt, } static int -coio_service_on_accept(struct evio_service *evio_service, +coio_service_on_accept(struct evio_service *evio_service, const struct uri *uri, int fd, struct sockaddr *addr, socklen_t addrlen) { + (void)uri; struct coio_service *service = (struct coio_service *) evio_service->on_accept_param; diff --git a/src/lib/core/coio.h b/src/lib/core/coio.h index 4ca4760d6b..6849f43aee 100644 --- a/src/lib/core/coio.h +++ b/src/lib/core/coio.h @@ -41,6 +41,7 @@ extern "C" { struct iostream; struct sockaddr; +struct uri_set; /** * Co-operative I/O diff --git a/src/lib/core/evio.c b/src/lib/core/evio.c index fe83c098b7..9c463d1be4 100644 --- a/src/lib/core/evio.c +++ b/src/lib/core/evio.c @@ -38,11 +38,11 @@ #include <trivia/util.h> #include "exception.h" +#include "uri/uri.h" struct evio_service_entry { - /** Bind host:service, useful for logging */ - char host[URI_MAXHOST]; - char serv[URI_MAXSERVICE]; + /** Bind URI */ + struct uri uri; /** Interface/port to bind to */ union { @@ -190,7 +190,7 @@ evio_service_entry_accept_cb(ev_loop *loop, ev_io *watcher, int events) if (evio_setsockopt_client(fd, entry->addr.sa_family, SOCK_STREAM) != 0) break; - if (entry->service->on_accept(entry->service, fd, + if (entry->service->on_accept(entry->service, &entry->uri, fd, (struct sockaddr *)&addr, addrlen) != 0) break; @@ -301,6 +301,7 @@ evio_service_entry_create(struct evio_service_entry *entry, struct evio_service *service) { memset(entry, 0, sizeof(struct evio_service_entry)); + uri_create(&entry->uri, NULL); /* * Initialize libev objects to be able to detect if they * are active or not in evio_service_entry_stop(). @@ -317,18 +318,17 @@ evio_service_entry_create(struct evio_service_entry *entry, static int evio_service_entry_bind(struct evio_service_entry *entry, const struct uri *u) { - entry->serv[0] = entry->host[0] = '\0'; assert(u->service != NULL); - strlcpy(entry->serv, u->service, sizeof(entry->serv)); - if (u->host != NULL && strcmp(u->host, "*") != 0) - strlcpy(entry->host, u->host, sizeof(entry->host)); - assert(! ev_is_active(&entry->ev)); + assert(!ev_is_active(&entry->ev)); - if (strcmp(entry->host, URI_HOST_UNIX) == 0) { + uri_destroy(&entry->uri); + uri_copy(&entry->uri, u); + + if (u->host != NULL && strcmp(u->host, URI_HOST_UNIX) == 0) { /* UNIX domain socket */ struct sockaddr_un *un = (struct sockaddr_un *) &entry->addr; entry->addr_len = sizeof(*un); - strlcpy(un->sun_path, entry->serv, sizeof(un->sun_path)); + strlcpy(un->sun_path, u->service, sizeof(un->sun_path)); un->sun_family = AF_UNIX; return evio_service_entry_bind_addr(entry); } @@ -340,9 +340,8 @@ evio_service_entry_bind(struct evio_service_entry *entry, const struct uri *u) hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE|AI_ADDRCONFIG; - /* make no difference between empty string and NULL for host */ - if (getaddrinfo(*entry->host ? entry->host : NULL, entry->serv, - &hints, &res) != 0 || res == NULL) { + if (getaddrinfo(u->host, u->service, &hints, &res) != 0 || + res == NULL) { diag_set(SocketError, sio_socketname(-1), "can't resolve uri for bind"); return -1; @@ -373,6 +372,7 @@ evio_service_entry_detach(struct evio_service_entry *entry) entry->addr_len = 0; } ev_io_set(&entry->ev, -1, 0); + uri_destroy(&entry->uri); } /** It's safe to stop a service entry which is not started yet. */ @@ -401,8 +401,8 @@ evio_service_entry_attach(struct evio_service_entry *dst, const struct evio_service_entry *src) { assert(!ev_is_active(&dst->ev)); - strcpy(dst->host, src->host); - strcpy(dst->serv, src->serv); + uri_destroy(&dst->uri); + uri_copy(&dst->uri, &src->uri); dst->addrstorage = src->addrstorage; dst->addr_len = src->addr_len; ev_io_set(&dst->ev, src->ev.fd, EV_READ); diff --git a/src/lib/core/evio.h b/src/lib/core/evio.h index 0266737f52..53fd1fabdb 100644 --- a/src/lib/core/evio.h +++ b/src/lib/core/evio.h @@ -37,7 +37,6 @@ #include <stdbool.h> #include "tarantool_ev.h" #include "sio.h" -#include "uri/uri.h" #if defined(__cplusplus) extern "C" { @@ -64,9 +63,12 @@ extern "C" { */ struct evio_service_entry; struct evio_service; +struct uri; +struct uri_set; -typedef int (*evio_accept_f)(struct evio_service *, int, struct sockaddr *, - socklen_t); +typedef int (*evio_accept_f)(struct evio_service *service, + const struct uri *uri, int fd, + struct sockaddr *addr, socklen_t addrlen); struct evio_service { /** Total count of services */ -- GitLab