laforge has submitted this change. (
https://gerrit.osmocom.org/c/libosmo-netif/+/33102 )
Change subject: stream: Introduce and use osmo_stream_cli_fd() to get the fd
......................................................................
stream: Introduce and use osmo_stream_cli_fd() to get the fd
This will become useful once osmo_io can be used as a backend.
Change-Id: I7e964dea0adee8edbb9b75d2d17e7d0c5d8917d5
---
M libosmo-netif.pc.in
M src/stream.c
2 files changed, 25 insertions(+), 7 deletions(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
diff --git a/libosmo-netif.pc.in b/libosmo-netif.pc.in
index 7f1335e..1a925f6 100644
--- a/libosmo-netif.pc.in
+++ b/libosmo-netif.pc.in
@@ -7,5 +7,5 @@
Description: C Utility Library
Version: @VERSION@
Libs: -L${libdir} -losmonetif
-Libs.private: @LIBSCTP_LIBS@
+Libs.private: @LIBSCTP_LIBS@ @LIBOSMOCORE_LIBS@
Cflags: -I${includedir}/
diff --git a/src/stream.c b/src/stream.c
index cbf0b27..b3721c5 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -321,6 +321,11 @@
cli->state = STREAM_CLI_STATE_CLOSED;
}
+static inline int osmo_stream_cli_fd(const struct osmo_stream_cli *cli)
+{
+ return cli->ofd.fd;
+}
+
static void osmo_stream_cli_read(struct osmo_stream_cli *cli)
{
LOGSCLI(cli, LOGL_DEBUG, "message received\n");
@@ -406,7 +411,7 @@
#ifdef SO_NOSIGPIPE
int ret;
int val = 1;
- ret = setsockopt(cli->ofd.fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&val,
sizeof(val));
+ ret = setsockopt(osmo_stream_cli_fd(cli), SOL_SOCKET, SO_NOSIGPIPE, (void *)&val,
sizeof(val));
if (ret < 0)
LOGSCLI(cli, LOGL_DEBUG, "Failed setting SO_NOSIGPIPE: %s\n",
strerror(errno));
return ret;
@@ -678,7 +683,7 @@
{
static char buf[OSMO_SOCK_NAME_MAXLEN];
- osmo_sock_get_name_buf(buf, OSMO_SOCK_NAME_MAXLEN, cli->ofd.fd);
+ osmo_sock_get_name_buf(buf, OSMO_SOCK_NAME_MAXLEN, osmo_stream_cli_fd(cli));
return buf;
}
@@ -811,10 +816,10 @@
* \return negative on error, 0 on success */
int osmo_stream_cli_open(struct osmo_stream_cli *cli)
{
- int ret;
+ int ret, fd = -1;
/* we are reconfiguring this socket, close existing first. */
- if ((cli->flags & OSMO_STREAM_CLI_F_RECONF) && cli->ofd.fd >= 0)
+ if ((cli->flags & OSMO_STREAM_CLI_F_RECONF) && osmo_stream_cli_fd(cli)
>= 0)
osmo_stream_cli_close(cli);
cli->flags &= ~OSMO_STREAM_CLI_F_RECONF;
@@ -850,14 +855,16 @@
osmo_stream_cli_reconnect(cli);
return ret;
}
- osmo_fd_setup(&cli->ofd, ret, OSMO_FD_READ | OSMO_FD_WRITE, cli->ofd.cb,
cli->ofd.data, cli->ofd.priv_nr);
+
+ fd = ret;
if (cli->flags & OSMO_STREAM_CLI_F_NODELAY) {
- ret = setsockopt_nodelay(cli->ofd.fd, cli->proto, 1);
+ ret = setsockopt_nodelay(fd, cli->proto, 1);
if (ret < 0)
goto error_close_socket;
}
+ osmo_fd_setup(&cli->ofd, fd, OSMO_FD_READ | OSMO_FD_WRITE, cli->ofd.cb,
cli->ofd.data, cli->ofd.priv_nr);
if (osmo_fd_register(&cli->ofd) < 0)
goto error_close_socket;
--
To view, visit
https://gerrit.osmocom.org/c/libosmo-netif/+/33102
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I7e964dea0adee8edbb9b75d2d17e7d0c5d8917d5
Gerrit-Change-Number: 33102
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged