pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-netif/+/33337 )


Change subject: stream: set name to sockname by default
......................................................................

stream: set name to sockname by default

Change-Id: I17ef699dab72c1b613708070d22e9f040b0fe069
---
M src/stream.c
1 file changed, 39 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/37/33337/1

diff --git a/src/stream.c b/src/stream.c
index 0f97c28..3843cbf 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -271,6 +271,8 @@

 struct osmo_stream_cli {
        char *name;
+       /* whether the name set in "name" is internally generated dynamicalli 
(_set_name() was not called): */
+       bool name_dynamic;
        enum osmo_stream_mode mode;
        union {
                struct osmo_fd                  ofd;
@@ -510,6 +512,12 @@
        if (cli->mode == OSMO_STREAM_MODE_OSMO_FD && 
llist_empty(&cli->tx_queue))
                osmo_fd_write_disable(&cli->ofd);

+       /* If user didn't set a name, (re-)set a dynamic default one based on 
socket info: */
+       if (!cli->name || cli->name_dynamic) {
+               cli->name_dynamic = true;
+               osmo_talloc_replace_string(cli, &cli->name, 
osmo_sock_get_name2_c(cli, fd));
+       }
+
        LOGSCLI(cli, LOGL_DEBUG, "connection established\n");
        cli->state = STREAM_CLI_STATE_CONNECTED;
        switch (cli->sk_domain) {
@@ -649,6 +657,7 @@
  */
 void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name)
 {
+       cli->name_dynamic = false;
        osmo_talloc_replace_string(cli, &cli->name, name);
 }

@@ -1139,6 +1148,8 @@

 struct osmo_stream_srv_link {
        struct osmo_fd          ofd;
+       /* whether the name set in "name" is internally generated dynamicalli 
(_set_name() was not called): */
+       bool                    name_dynamic;
        char                    *name;
        char                    *addr[OSMO_STREAM_MAX_ADDRS];
        uint8_t                 addrcnt;
@@ -1247,6 +1258,7 @@
  */
 void osmo_stream_srv_link_set_name(struct osmo_stream_srv_link *link, const 
char *name)
 {
+       link->name_dynamic = false;
        osmo_talloc_replace_string(link, &link->name, name);
 }

@@ -1478,6 +1490,12 @@
                link->ofd.fd = -1;
                return -EIO;
        }
+
+       /* If user didn't set a name, (re-)set a dynamic default one based on 
socket info: */
+       if (!link->name || link->name_dynamic) {
+               link->name_dynamic = true;
+               osmo_talloc_replace_string(link, &link->name, 
talloc_strdup(link, osmo_stream_srv_link_get_sockname(link)));
+       }
        return 0;
 }

@@ -1511,6 +1529,8 @@

 struct osmo_stream_srv {
        struct osmo_stream_srv_link     *srv;
+       /* whether the name set in "name" is internally generated dynamicalli 
(_set_name() was not called): */
+       bool                            name_dynamic;
        char                            *name;
        enum osmo_stream_mode mode;
        union {
@@ -1688,6 +1708,9 @@
        conn->data = data;
        INIT_LLIST_HEAD(&conn->tx_queue);

+       conn->name_dynamic = true;
+       conn->name = osmo_sock_get_name2_c(conn, fd);
+
        if (osmo_fd_register(&conn->ofd) < 0) {
                LOGSSRV(conn, LOGL_ERROR, "could not register FD\n");
                talloc_free(conn);
@@ -1717,7 +1740,6 @@

        conn->mode = OSMO_STREAM_MODE_OSMO_IO;
        conn->srv = link;
-       conn->name = talloc_strdup(conn, name);
        conn->iofd = osmo_iofd_setup(conn, fd, name, 
OSMO_IO_FD_MODE_READ_WRITE, &srv_ioops, conn);
        if (!conn->iofd) {
                talloc_free(conn);
@@ -1725,6 +1747,13 @@
        }
        conn->data = data;

+       if (name) {
+               conn->name = talloc_strdup(conn, name);
+       } else {
+               conn->name_dynamic = true;
+               conn->name = osmo_sock_get_name2_c(conn, fd);
+       }
+
        if (osmo_iofd_register(conn->iofd, fd) < 0) {
                LOGSSRV(conn, LOGL_ERROR, "could not register FD %d\n", fd);
                talloc_free(conn);

--
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/33337
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I17ef699dab72c1b613708070d22e9f040b0fe069
Gerrit-Change-Number: 33337
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to