summaryrefslogtreecommitdiffstats
path: root/src/host/osmocon
diff options
context:
space:
mode:
authorIngo Albrecht2010-03-07 06:04:10 +0100
committerHarald Welte2010-03-07 12:04:16 +0100
commita731ef52980f1c31008688f9d451b7d0fdd49e7e (patch)
treeb5ea160031d1f01a559d93eabd05865efe04c810 /src/host/osmocon
parentLoader communications support in osmocon. Generalized tool connections. (diff)
downloadosmocom-a731ef52980f1c31008688f9d451b7d0fdd49e7e.tar.gz
osmocom-a731ef52980f1c31008688f9d451b7d0fdd49e7e.tar.xz
osmocom-a731ef52980f1c31008688f9d451b7d0fdd49e7e.zip
Fixed transmit path of osmocon in various ways.
Diffstat (limited to 'src/host/osmocon')
-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 d979110..6376e3d 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: