summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Albrecht <prom@berlin.ccc.de>2010-03-07 06:04:10 +0100
committerHarald Welte <laforge@gnumonks.org>2010-03-07 12:04:16 +0100
commita731ef52980f1c31008688f9d451b7d0fdd49e7e (patch)
treeb5ea160031d1f01a559d93eabd05865efe04c810
parent7af3c99091c460b93ac3aad8faa881d61f84442a (diff)
Fixed transmit path of osmocon in various ways.
-rw-r--r--src/host/osmocon/osmocon.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index d979110a..6376e3d1 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -516,30 +516,42 @@ static int version(const char *name)
static int un_tool_read(struct bsc_fd *fd, unsigned int flags)
{
- int rc;
+ int rc, c;
u_int16_t length = 0xffff;
u_int8_t buf[4096];
struct tool_connection *con = (struct tool_connection *)fd->data;
-
- rc = read(fd->fd, &length, sizeof(length));
- if (rc == 0) {
- // client disconnected
- goto close;
- }
- if (rc < 0 || ntohs(length) > 512) {
- fprintf(stderr, "Unexpected result from socket. rc: %d len: %d\n",
- rc, ntohs(length));
- goto close;
+ c = 0;
+ while(c < 2) {
+ rc = read(fd->fd, &buf + c, 2 - c);
+ if(rc == 0) {
+ // disconnect
+ goto close;
+ }
+ if(rc < 0) {
+ fprintf(stderr, "Err from socket: \n", strerror(errno));
+ goto close;
+ }
+ c += rc;
}
- rc = read(fd->fd, buf, ntohs(length));
- if (rc != ntohs(length)) {
- fprintf(stderr, "Could not read data.\n");
- goto close;
+ length = ntohs(*(u_int16_t*)buf);
+
+ c = 0;
+ while(c < length) {
+ rc = read(fd->fd, &buf + c, length - c);
+ if(rc == 0) {
+ // disconnect
+ goto close;
+ }
+ if(rc < 0) {
+ fprintf(stderr, "Err from socket: \n", strerror(errno));
+ goto close;
+ }
+ c += rc;
}
- hdlc_send_to_phone(con->server->dlci, buf, ntohs(length));
+ hdlc_send_to_phone(con->server->dlci, buf, length);
return 0;
close: