lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/21751 )
Change subject: gprs_ns2: fr: implement a write queue ...................................................................... gprs_ns2: fr: implement a write queue Change-Id: Id6eba04d5fb744f791b333c168729bbbd28cabd9 --- M src/gb/gprs_ns2_fr.c 1 file changed, 20 insertions(+), 28 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/51/21751/1 diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c index fc6f166..6aa687c 100644 --- a/src/gb/gprs_ns2_fr.c +++ b/src/gb/gprs_ns2_fr.c @@ -50,6 +50,7 @@ #include <osmocom/core/select.h> #include <osmocom/core/socket.h> #include <osmocom/core/talloc.h> +#include <osmocom/core/write_queue.h> #include <osmocom/gprs/gprs_ns2.h> #ifdef ENABLE_LIBMNL @@ -83,9 +84,9 @@ }; struct priv_bind { - struct osmo_fd fd; char netif[IF_NAMESIZE]; struct osmo_fr_link *link; + struct osmo_wqueue wqueue; int ifindex; bool if_running; }; @@ -142,7 +143,7 @@ OSMO_ASSERT(llist_empty(&bind->nsvc)); osmo_fr_link_free(priv->link); - osmo_fd_close(&priv->fd); + osmo_fd_close(&priv->wqueue.bfd); talloc_free(priv); } @@ -238,22 +239,9 @@ return rc; } -static int handle_netif_write(struct osmo_fd *bfd) +static int handle_netif_write(struct osmo_fd *ofd, struct msgb *msg) { - /* FIXME */ - return -EIO; -} - -static int fr_fd_cb(struct osmo_fd *bfd, unsigned int what) -{ - int rc = 0; - - if (what & OSMO_FD_READ) - rc = handle_netif_read(bfd); - if (what & OSMO_FD_WRITE) - rc = handle_netif_write(bfd); - - return rc; + return write(ofd->fd, msgb_data(msg), msgb_length(msg)); } /*! determine if given bind is for FR-GRE encapsulation. */ @@ -276,13 +264,15 @@ { struct gprs_ns2_vc_bind *bind = data; struct priv_bind *priv = bind->priv; - int rc; - /* FIXME half writes */ - rc = write(priv->fd.fd, msg->data, msg->len); - msgb_free(msg); + if (osmo_wqueue_enqueue(&priv->wqueue, msg)) { + LOGP(DLNS, LOGL_ERROR, "frame relay %s: failed to enqueue message\n", + priv->netif); + msgb_free(msg); + return -EINVAL; + } - return rc; + return 0; } static int devname2ifindex(const char *ifname) @@ -492,8 +482,6 @@ goto err_name; } - priv->fd.cb = fr_fd_cb; - priv->fd.data = bind; if (strlen(netif) > IF_NAMESIZE) { rc = -EINVAL; goto err_priv; @@ -520,12 +508,16 @@ goto err_fr; } - priv->fd.fd = rc = open_socket(priv->ifindex); + osmo_wqueue_init(&priv->wqueue, 10); + priv->wqueue.write_cb = handle_netif_write; + priv->wqueue.read_cb = handle_netif_read; + priv->wqueue.bfd.data = bind; + priv->wqueue.bfd.fd = rc = open_socket(priv->ifindex); if (rc < 0) goto err_fr; - priv->fd.when = OSMO_FD_READ; - rc = osmo_fd_register(&priv->fd); + priv->wqueue.bfd.when = OSMO_FD_READ; + rc = osmo_fd_register(&priv->wqueue.bfd); if (rc < 0) goto err_fd; @@ -545,7 +537,7 @@ return rc; err_fd: - close(priv->fd.fd); + close(priv->wqueue.bfd.fd); err_fr: osmo_fr_link_free(fr_link); err_priv: -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/21751 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Id6eba04d5fb744f791b333c168729bbbd28cabd9 Gerrit-Change-Number: 21751 Gerrit-PatchSet: 1 Gerrit-Owner: lynxis lazus <lyn...@fe80.eu> Gerrit-MessageType: newchange