aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2011-10-17 12:28:12 +0200
committerPablo Neira Ayuso <pablo@gnumonks.org>2011-10-17 12:34:40 +0200
commitc43bb089067ca05af4992fbafe46827a1f0a6e9b (patch)
tree86f7c957f654b261d8fcbcebaa01cac325d75a58 /examples
parent60eb9839645ab93b11d2d09767ee6dc21e51ad2d (diff)
datagram: add osmo_dgram_conn_recv
We provide osmo_dgram_conn_recv(...) which allows you to take control on the message allocation and receival process. Instead of hiding this details inside the datagram infrastructure. Providing more control to clients of this code means more flexibility.
Diffstat (limited to 'examples')
-rw-r--r--examples/lapd-over-datagram-network.c12
-rw-r--r--examples/lapd-over-datagram-user.c14
2 files changed, 24 insertions, 2 deletions
diff --git a/examples/lapd-over-datagram-network.c b/examples/lapd-over-datagram-network.c
index 58ee3fa..fb94515 100644
--- a/examples/lapd-over-datagram-network.c
+++ b/examples/lapd-over-datagram-network.c
@@ -44,12 +44,22 @@ void sighandler(int foo)
exit(EXIT_SUCCESS);
}
-int read_cb(struct osmo_dgram_conn *conn, struct msgb *msg)
+int read_cb(struct osmo_dgram_conn *conn)
{
int error;
+ struct msgb *msg;
LOGP(DLAPDTEST, LOGL_DEBUG, "received message from datagram\n");
+ msg = msgb_alloc(1200, "LAPD/test");
+ if (msg == NULL) {
+ LOGP(DLAPDTEST, LOGL_ERROR, "cannot allocate message\n");
+ return -1;
+ }
+ if (osmo_dgram_conn_recv(conn, msg) < 0) {
+ LOGP(DLAPDTEST, LOGL_ERROR, "cannot receive message\n");
+ return -1;
+ }
if (lapd_receive(lapd, msg, &error) < 0) {
LOGP(DLAPDTEST, LOGL_ERROR, "lapd_receive returned error!\n");
return -1;
diff --git a/examples/lapd-over-datagram-user.c b/examples/lapd-over-datagram-user.c
index 68fa424..601d12c 100644
--- a/examples/lapd-over-datagram-user.c
+++ b/examples/lapd-over-datagram-user.c
@@ -55,11 +55,23 @@ void sighandler(int foo)
exit(EXIT_SUCCESS);
}
-static int read_cb(struct osmo_dgram_conn *conn, struct msgb *msg)
+static int read_cb(struct osmo_dgram_conn *conn)
{
int error;
+ struct msgb *msg;
+ msg = msgb_alloc(1200, "LAPD/test");
+ if (msg == NULL) {
+ LOGP(DLAPDTEST, LOGL_ERROR, "cannot allocate message\n");
+ return -1;
+ }
+ if (osmo_dgram_conn_recv(conn, msg) < 0) {
+ msgb_free(msg);
+ LOGP(DLAPDTEST, LOGL_ERROR, "cannot receive message\n");
+ return -1;
+ }
if (lapd_receive(lapd, msg, &error) < 0) {
+ msgb_free(msg);
LOGP(DLINP, LOGL_ERROR, "lapd_receive returned error!\n");
return -1;
}