pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-uecups/+/40796?usp=email )

 (

4 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted 
one.
 )Change subject: cups_client: Use new iofd stream_srv APIs
......................................................................

cups_client: Use new iofd stream_srv APIs

Related: OS#6823
Change-Id: Ie9f127e82e39ad0b5cae83f870b678ba1800ded4
---
M daemon/cups_client.c
1 file changed, 35 insertions(+), 36 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified
  osmith: Looks good to me, but someone else must approve




diff --git a/daemon/cups_client.c b/daemon/cups_client.c
index ae17595..5b94bff 100644
--- a/daemon/cups_client.c
+++ b/daemon/cups_client.c
@@ -552,71 +552,63 @@
        return 0;
 }

+
+static void cups_client_free(struct cups_client *cc);
+
 /* control/user plane separation per-client read cb */
-static int cups_client_read_cb(struct osmo_stream_srv *conn)
+static int cups_client_read_cb(struct osmo_stream_srv *conn, int res, struct 
msgb *msg)
 {
-       struct osmo_fd *ofd = osmo_stream_srv_get_ofd(conn);
        struct cups_client *cc = osmo_stream_srv_get_data(conn);
-       struct msgb *msg = msgb_alloc(CUPS_MSGB_SIZE, "Rx JSON");
-       struct sctp_sndrcvinfo sinfo;
        json_error_t jerr;
        json_t *jroot;
-       int flags = 0;
-       int rc = 0;
+       int flags;

-       /* Read message from socket */
-       /* we cannot use osmo_stream_srv_recv() here, as we might get some 
out-of-band info from
-        * SCTP. FIXME: add something like osmo_stream_srv_recv_sctp() to 
libosmo-netif and use
-        * it here as well as in libosmo-sigtran and osmo-msc */
-       rc = sctp_recvmsg(ofd->fd, msg->tail, msgb_tailroom(msg), NULL, NULL, 
&sinfo, &flags);
-       if (rc <= 0) {
-               osmo_stream_srv_destroy(conn);
-               rc = -1;
-               goto out;
-       } else
-               msgb_put(msg, rc);
+       flags = msgb_sctp_msg_flags(msg);
+       LOGCC(cc, LOGL_DEBUG, "read %d bytes (flags=0x%x)\n", res, flags);

-       if (flags & MSG_NOTIFICATION) {
+       if (flags & OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION) {
                union sctp_notification *notif = (union sctp_notification *) 
msgb_data(msg);
                switch (notif->sn_header.sn_type) {
                case SCTP_SHUTDOWN_EVENT:
-                       osmo_stream_srv_destroy(conn);
-                       rc = -EBADF;
-                       goto out;
+                       goto free_client;
                default:
-                       break;
+                       msgb_free(msg);
+                       return 0;
                }
-               goto out;
        }
-
-       LOGCC(cc, LOGL_DEBUG, "Rx '%s'\n", msgb_data(msg));
+       if (res <= 0)
+               goto free_client;

        /* Parse the JSON */
        jroot = json_loadb((const char *) msgb_data(msg), msgb_length(msg), 0, 
&jerr);
        if (!jroot) {
-               LOGCC(cc, LOGL_ERROR, "Error decoding JSON (%s)", jerr.text);
-               rc = -1;
-               goto out;
+               LOGCC(cc, LOGL_ERROR, "Error decoding JSON (%s)\n", jerr.text);
+               msgb_free(msg);
+               return -1;
        }

        /* Dispatch */
-       rc = cups_client_handle_json(cc, jroot);
+       cups_client_handle_json(cc, jroot);

        json_decref(jroot);
        msgb_free(msg);

        return 0;
-out:
-       msgb_free(msg);
-       return rc;
-}

-static void cups_client_free(struct cups_client *cc);
+free_client:
+       LOGCC(cc, LOGL_NOTICE, "UECUPS connection lost\n");
+       msgb_free(msg);
+       cups_client_free(cc);
+       return -1;
+}

 static int cups_client_closed_cb(struct osmo_stream_srv *conn)
 {
        struct cups_client *cc = osmo_stream_srv_get_data(conn);

+       if (!cc) /* already being destroyed in cups_client_free() */
+               return 0;
+
        LOGCC(cc, LOGL_INFO, "UECUPS connection lost\n");
        cups_client_free(cc);
        return 0;
@@ -632,11 +624,13 @@

        cc->d = d;
        osmo_sock_get_name_buf(cc->sockname, sizeof(cc->sockname), fd);
-       cc->srv = osmo_stream_srv_create(cc, link, fd, cups_client_read_cb, 
cups_client_closed_cb, cc);
+       cc->srv = osmo_stream_srv_create2(cc, link, fd, cc);
        if (!cc->srv) {
                talloc_free(cc);
                return NULL;
        }
+       osmo_stream_srv_set_read_cb(cc->srv, cups_client_read_cb);
+       osmo_stream_srv_set_closed_cb(cc->srv, cups_client_closed_cb);

        llist_add_tail(&cc->list, &d->cups_clients);
        return cc;
@@ -649,6 +643,8 @@
        if (!cc)
                return;

+       LOGCC(cc, LOGL_DEBUG, "free()\n");
+
        /* kill + forget about all subprocesses of this client */
        /* We need no locking here as the subprocess list is only used from the 
main thread */
        llist_for_each_entry_safe(p, p2, &cc->d->subprocesses, list) {
@@ -657,8 +653,10 @@
        }

        llist_del(&cc->list);
-       if (cc->srv)
+       if (cc->srv) {
+               osmo_stream_srv_set_data(cc->srv, NULL);
                osmo_stream_srv_destroy(cc->srv);
+       }
        talloc_free(cc);
 }

@@ -691,6 +689,7 @@
        osmo_stream_srv_link_set_proto(srv_link, IPPROTO_SCTP);
        osmo_stream_srv_link_set_data(srv_link, g_daemon);
        osmo_stream_srv_link_set_accept_cb(srv_link, cups_accept_cb);
+       osmo_stream_srv_link_set_msgb_alloc_info(srv_link, CUPS_MSGB_SIZE, 0);
        osmo_stream_srv_link_open(srv_link);
        return srv_link;
 }

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

Gerrit-MessageType: merged
Gerrit-Project: osmo-uecups
Gerrit-Branch: master
Gerrit-Change-Id: Ie9f127e82e39ad0b5cae83f870b678ba1800ded4
Gerrit-Change-Number: 40796
Gerrit-PatchSet: 5
Gerrit-Owner: pespin <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to