laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-mgw/+/36360?usp=email )


Change subject: remove osmo_fd from mgcp_create_bind()
......................................................................

remove osmo_fd from mgcp_create_bind()

preparation for osmo_io

Change-Id: I4a3b66a14fdfbc867daca0f0a05f694d5e0d7b66
---
M include/osmocom/mgcp/mgcp.h
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_osmux.c
3 files changed, 26 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/60/36360/1

diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h
index bfb412b..e61ba89 100644
--- a/include/osmocom/mgcp/mgcp.h
+++ b/include/osmocom/mgcp/mgcp.h
@@ -204,6 +204,5 @@
 int mgcp_send_reset_all(struct mgcp_config *cfg);


-int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port, 
uint8_t dscp,
-                    uint8_t prio);
+int mgcp_create_bind(const char *source_addr, int port, uint8_t dscp, uint8_t 
prio);
 int mgcp_udp_send(int fd, const struct osmo_sockaddr *addr, const char *buf, 
int len);
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index ee25f74..0a1bc11 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -1517,13 +1517,11 @@

 /*! bind RTP port to osmo_fd.
  *  \param[in] source_addr source (local) address to bind on.
- *  \param[in] fd associated file descriptor.
  *  \param[in] port to bind on.
  *  \param[in] dscp IP DSCP value to use.
  *  \param[in] prio socket priority to use.
  *  \returns 0 on success, -1 on ERROR. */
-int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port, 
uint8_t dscp,
-                    uint8_t prio)
+int mgcp_create_bind(const char *source_addr, int port, uint8_t dscp, uint8_t 
prio)
 {
        int rc;

@@ -1535,34 +1533,37 @@
                     source_addr, port);
                return -1;
        }
-       fd->fd = rc;
        LOGP(DRTP, LOGL_DEBUG, "created socket + bound UDP port (%s:%i).\n", 
source_addr, port);

-       return 0;
+       return rc;
 }

 /* Bind RTP and RTCP port (helper function for mgcp_bind_net_rtp_port()) */
 static int bind_rtp(struct mgcp_config *cfg, const char *source_addr,
                    struct mgcp_rtp_end *rtp_end, struct mgcp_endpoint *endp)
 {
+       int rc;
+
        /* NOTE: The port that is used for RTCP is the RTP port incremented by 
one
         * (e.g. RTP-Port = 16000 ==> RTCP-Port = 16001) */

-       if (mgcp_create_bind(source_addr, &rtp_end->rtp, rtp_end->local_port,
-                            cfg->endp_dscp, cfg->endp_priority) != 0) {
+       rc = mgcp_create_bind(source_addr, rtp_end->local_port, cfg->endp_dscp, 
cfg->endp_priority);
+       if (rc < 0) {
                LOGPENDP(endp, DRTP, LOGL_ERROR,
                         "failed to create RTP port: %s:%d\n",
                         source_addr, rtp_end->local_port);
                goto cleanup0;
        }
+       rtp_end->rtp.fd = rc;

-       if (mgcp_create_bind(source_addr, &rtp_end->rtcp, rtp_end->local_port + 
1,
-                            cfg->endp_dscp, cfg->endp_priority) != 0) {
+       rc = mgcp_create_bind(source_addr, rtp_end->local_port + 1, 
cfg->endp_dscp, cfg->endp_priority);
+       if (rc < 0) {
                LOGPENDP(endp, DRTP, LOGL_ERROR,
                         "failed to create RTCP port: %s:%d\n",
                         source_addr, rtp_end->local_port + 1);
                goto cleanup1;
        }
+       rtp_end->rtcp.fd = rc;

        if (osmo_fd_register(&rtp_end->rtp) != 0) {
                LOGPENDP(endp, DRTP, LOGL_ERROR,
diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c
index 185aecd..997b07b 100644
--- a/src/libosmo-mgcp/mgcp_osmux.c
+++ b/src/libosmo-mgcp/mgcp_osmux.c
@@ -514,13 +514,14 @@
        osmo_fd_setup(&osmux_fd_v6, -1, OSMO_FD_READ, osmux_read_fd_cb, trunk, 
0);

        if (cfg->osmux.local_addr_v4) {
-               ret = mgcp_create_bind(cfg->osmux.local_addr_v4, &osmux_fd_v4, 
cfg->osmux.local_port,
+               ret = mgcp_create_bind(cfg->osmux.local_addr_v4, 
cfg->osmux.local_port,
                                        cfg->endp_dscp, cfg->endp_priority);
                if (ret < 0) {
                        LOGP(DOSMUX, LOGL_ERROR, "Cannot bind OSMUX IPv4 socket 
to %s:%u\n",
                             cfg->osmux.local_addr_v4, cfg->osmux.local_port);
                        return ret;
                }
+               osmux_fd_v4.fd = ret;

                ret = osmo_fd_register(&osmux_fd_v4);
                if (ret < 0) {
@@ -532,13 +533,14 @@
                     osmo_sock_get_name2(osmux_fd_v4.fd));
        }
        if (cfg->osmux.local_addr_v6) {
-               ret = mgcp_create_bind(cfg->osmux.local_addr_v6, &osmux_fd_v6, 
cfg->osmux.local_port,
+               ret = mgcp_create_bind(cfg->osmux.local_addr_v6, 
cfg->osmux.local_port,
                                        cfg->endp_dscp, cfg->endp_priority);
                if (ret < 0) {
                        LOGP(DOSMUX, LOGL_ERROR, "Cannot bind OSMUX IPv6 socket 
to [%s]:%u\n",
                             cfg->osmux.local_addr_v6, cfg->osmux.local_port);
                        return ret;
                }
+               osmux_fd_v6.fd = ret;

                ret = osmo_fd_register(&osmux_fd_v6);
                if (ret < 0) {

--
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/36360?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I4a3b66a14fdfbc867daca0f0a05f694d5e0d7b66
Gerrit-Change-Number: 36360
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <lafo...@osmocom.org>
Gerrit-MessageType: newchange

Reply via email to