laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/34881?usp=email )
Change subject: gsmtap_util: Simplify sink ......................................................................
gsmtap_util: Simplify sink
- Instead of using the osmo_fd API to call read() on the socket's file descriptor each time (unused) data is received, simply open the socket and never read
Related: OS#6213 Change-Id: I4025920d5f62d17133e9b5fe81cd34a88c4f20b5 --- M src/core/gsmtap_util.c 1 file changed, 21 insertions(+), 43 deletions(-)
Approvals: daniel: Looks good to me, but someone else must approve laforge: Looks good to me, approved Jenkins Builder: Verified
diff --git a/src/core/gsmtap_util.c b/src/core/gsmtap_util.c index 458d1d7..d817885 100644 --- a/src/core/gsmtap_util.c +++ b/src/core/gsmtap_util.c @@ -58,7 +58,7 @@ struct osmo_wqueue wq; /*!< the wait queue. This field member may not be changed or moved (backwards compatibility) */
struct osmo_io_fd *out; /*!< Used when osmo_io_mode is nonzero */ - struct osmo_fd sink_ofd; + int sink_fd; };
struct _gsmtap_inst_legacy { @@ -433,22 +433,6 @@ signal_dbm, snr, data, len); }
-/* Callback from select layer if we can read from the sink socket */ -static int gsmtap_sink_fd_cb(struct osmo_fd *fd, unsigned int flags) -{ - int rc; - uint8_t buf[4096]; - if (!(flags & OSMO_FD_READ)) - return 0; - - rc = read(fd->fd, buf, sizeof(buf)); - if (rc < 0) - return rc; - /* simply discard any data arriving on the socket */ - - return 0; -} - /*! Add a local sink to an existing GSMTAP source and return fd * \param[in] gti existing GSMTAP source * \returns file descriptor of locally bound receive socket @@ -466,28 +450,7 @@ */ int gsmtap_source_add_sink(struct gsmtap_inst *gti) { - int fd, rc; - - fd = gsmtap_source_add_sink_fd(gsmtap_inst_fd2(gti)); - if (fd < 0) - return fd; - - if (gti->osmo_io_mode) { - struct osmo_fd *sink_ofd; - - sink_ofd = >i->sink_ofd; - sink_ofd->fd = fd; - sink_ofd->when = OSMO_FD_READ; - sink_ofd->cb = gsmtap_sink_fd_cb; - - rc = osmo_fd_register(sink_ofd); - if (rc < 0) { - close(fd); - return rc; - } - } - - return fd; + return gti->sink_fd = gsmtap_source_add_sink_fd(gsmtap_inst_fd2(gti)); }
/* Registered in Osmo IO as a no-op to set the write callback. */ @@ -524,7 +487,7 @@ gti->osmo_io_mode = ofd_wq_mode; /* Still using the wq member for its 'fd' field only, since we are keeping it for now, anyways */ gti->wq.bfd.fd = fd; - gti->sink_ofd.fd = -1; + gti->sink_fd = -1;
if (ofd_wq_mode) { gti->out = osmo_iofd_setup(gti, gti->wq.bfd.fd, "gsmtap_inst.io_fd", OSMO_IO_FD_MODE_READ_WRITE, &gsmtap_ops, NULL); @@ -564,10 +527,11 @@ if (gti->osmo_io_mode) { osmo_iofd_free(gti->out);
- if (gti->sink_ofd.fd != -1) { - osmo_fd_unregister(>i->sink_ofd); - close(gti->sink_ofd.fd); + if (gti->sink_fd != -1) { + close(gti->sink_fd); + gti->sink_fd = -1; } + }
talloc_free(gti);