diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2011-06-21 14:15:46 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@gnumonks.org> | 2011-06-21 14:15:46 +0200 |
commit | 7a249408056c5375030cd0cf171caa17a6715cb8 (patch) | |
tree | fd39dd0eae1dca201d8602ac3035eefb83c44158 /src/input/ipaccess.c | |
parent | 9b3a33cba9c7a72d53b5c1634666758a485f060c (diff) |
input: use generic ipa_msg_recv() instead of ipaccess_read_msg()
We use the new generic function to receive messages, instead of
ipaccess_read_msg.
It's a mere renaming, but it's the first step before the rework
that will happen soon to avoid calling read() twice.
Diffstat (limited to 'src/input/ipaccess.c')
-rw-r--r-- | src/input/ipaccess.c | 59 |
1 files changed, 2 insertions, 57 deletions
diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 38e942f..e5c00a1 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -117,61 +117,6 @@ int ipaccess_send_id_req(int fd) return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg)); } -/* - * read one ipa message from the socket - * return NULL in case of error - */ -struct msgb *ipaccess_read_msg(struct osmo_fd *bfd, int *error) -{ - struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "Abis/IP"); - struct ipaccess_head *hh; - int len, ret = 0; - - if (!msg) { - *error = -ENOMEM; - return NULL; - } - - /* first read our 3-byte header */ - hh = (struct ipaccess_head *) msg->data; - ret = recv(bfd->fd, msg->data, sizeof(*hh), 0); - if (ret == 0) { - msgb_free(msg); - *error = ret; - return NULL; - } else if (ret != sizeof(*hh)) { - if (errno != EAGAIN) - LOGP(DINP, LOGL_ERROR, "recv error %d %s\n", ret, strerror(errno)); - msgb_free(msg); - *error = ret; - return NULL; - } - - msgb_put(msg, ret); - - /* then read te length as specified in header */ - msg->l2h = msg->data + sizeof(*hh); - len = ntohs(hh->len); - - if (len < 0 || TS1_ALLOC_SIZE < len + sizeof(*hh)) { - LOGP(DINP, LOGL_ERROR, "Can not read this packet. %d avail\n", len); - msgb_free(msg); - *error = -EIO; - return NULL; - } - - ret = recv(bfd->fd, msg->l2h, len, 0); - if (ret < len) { - LOGP(DINP, LOGL_ERROR, "short read! Got %d from %d\n", ret, len); - msgb_free(msg); - *error = -EIO; - return NULL; - } - msgb_put(msg, ret); - - return msg; -} - /* base handling of the ip.access protocol */ int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd) @@ -227,8 +172,8 @@ static int handle_ts1_read(struct osmo_fd *bfd) struct msgb *msg; int ret = 0, error; - msg = ipaccess_read_msg(bfd, &error); - if (!msg) { + error = ipa_msg_recv(bfd->fd, &msg); + if (error <= 0) { if (e1i_ts->line->ops.error) e1i_ts->line->ops.error(NULL, error); if (error == 0) { |