pespin has uploaded this change for review.

View Change

cups_client: Use new iofd stream_srv APIs

Change-Id: Ie9f127e82e39ad0b5cae83f870b678ba1800ded4
---
M daemon/cups_client.c
1 file changed, 23 insertions(+), 31 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-uecups refs/changes/96/40796/1
diff --git a/daemon/cups_client.c b/daemon/cups_client.c
index ae17595..b8a247b 100644
--- a/daemon/cups_client.c
+++ b/daemon/cups_client.c
@@ -553,62 +553,51 @@
}

/* 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)", 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:
+ msgb_free(msg);
+ cc->srv = NULL;
osmo_stream_srv_destroy(conn);
- rc = -EBADF;
- goto out;
+ return -EBADF;
default:
- break;
+ msgb_free(msg);
+ return 0;
}
- goto out;
}
-
- LOGCC(cc, LOGL_DEBUG, "Rx '%s'\n", msgb_data(msg));
+ if (res <= 0) {
+ msgb_free(msg);
+ cc->srv = NULL;
+ osmo_stream_srv_destroy(conn);
+ return -1;
+ }

/* 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;
+ 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);
@@ -632,11 +621,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;
@@ -691,6 +682,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 change 40796. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-uecups
Gerrit-Branch: master
Gerrit-Change-Id: Ie9f127e82e39ad0b5cae83f870b678ba1800ded4
Gerrit-Change-Number: 40796
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>