Adapt for changes in tedtools
authorteodor <teodor>
Fri, 30 Nov 2007 18:08:56 +0000 (18:08 +0000)
committerteodor <teodor>
Fri, 30 Nov 2007 18:08:56 +0000 (18:08 +0000)
rtop.c
sendtop.c
td_lmsg.c
top.h

diff --git a/rtop.c b/rtop.c
index 59b1664..a9f7260 100644 (file)
--- a/rtop.c
+++ b/rtop.c
@@ -67,7 +67,6 @@ main( int argc, char *argv[] ) {
        int port=TOPD_SERVER_DEFAULT_PORT;
        int i;
 
-       MassiveUnit *mu;
        TCMsg   *pmsg;
        TC_Connection  cs;
 
@@ -100,13 +99,16 @@ main( int argc, char *argv[] ) {
        pmsg = (TCMsg*)tmalloc( TCMSGHDRSZ );
        pmsg->type = TOPGETTYPE;
        pmsg->len = TCMSGHDRSZ;
-       cs.buf = (char*)pmsg;
-       cs.len = pmsg->len;
+       cs.buf = pmsg;
 
        if ( TC_Talk(&cs, 0) == CS_OK ) {       
-               pmsg = (TCMsg*) cs.buf;
+               MassiveUnit *mu;
+
+               pmsg = cs.buf;
                mu = (MassiveUnit*)pmsg->data;
 
+               tlog(TL_DEBUG,"Got packet len:%db type:%08x n:%d", pmsg->len, pmsg->type, mu->number);
+
                printf("\tIP\tLoad\tFree\tTotal\tDate\n");
                for(i=0; i<mu->number; i++) 
                        printf("%s\t%.2f\t%.1fM\t%.1fM\t%s",
index ce24d62..9b41b22 100644 (file)
--- a/sendtop.c
+++ b/sendtop.c
@@ -169,17 +169,17 @@ fillMsgTop(TCMsgTop *m) {
 static int
 sendTop(Msg *msg) {
        TCMsg *pmsg;
+       int msglen = TCMSGHDRSZ + sizeof(TCMsgTop);
 
        if ( !msg->msg ) {
-               int msglen = TCMSGHDRSZ + sizeof(TCMsgTop);
                pmsg = (TCMsg*)tmalloc(msglen);
-               pmsg->len = msglen;
-               pmsg->type=TOPMSGTYPE;
                msg->msg = pmsg;
        } else {
                pmsg = msg->msg;
        }
 
+       pmsg->len = msglen;
+       pmsg->type=TOPMSGTYPE;
        fillMsgTop( (TCMsgTop*)(pmsg->data) );
 
        return TC_sendMsg(msg);
index cd6e6ad..22cd925 100644 (file)
--- a/td_lmsg.c
+++ b/td_lmsg.c
 static void 
 getTopData(TC_Connection *conn) {
        TCMsg *pmsg;
+
        conn->len = TCMSGHDRSZ + MUHDRSZ + cfg.mu->number * sizeof(UnitInfo);
        conn->buf = trealloc( conn->buf, conn->len );
-       pmsg = (TCMsg*) conn->buf;
-       
+       pmsg = conn->buf;
+
        pmsg->len = conn->len;
        pmsg->type = TOPGETTYPE;
        memcpy( pmsg->data, cfg.mu, pmsg->len - TCMSGHDRSZ );
        ((MassiveUnit*)pmsg->data)->maxnumber = cfg.mu->number;
+       
        TC_Send(conn);   
 }
        
 static void 
 gotLongMessage( TC_Connection *conn ) {
-       TCMsg *pmsg = (TCMsg*) conn->buf;
+       TCMsg *pmsg = conn->buf;
 
-       if ( conn->ptr - conn->buf < TCMSGHDRSZ ) {
-               tlog(TL_ALARM,"Wrong size of long message (%d bytes)", conn->ptr - conn->buf);
+       if ( conn->ptr -(char*) conn->buf < TCMSGHDRSZ ) {
+               tlog(TL_ALARM,"Wrong size of long message (%d bytes)", conn->ptr - (char*)conn->buf);
                conn->state = CS_ERROR;
                return;
        }
@@ -63,20 +65,20 @@ gotLongMessage( TC_Connection *conn ) {
                        getTopData(conn);
                        break;
                default:
-                       tlog(TL_ALARM,"Got unknown packet type: %d", pmsg->type);
+                       tlog(TL_ALARM,"Got unknown packet type: %u (%08x)", pmsg->type, pmsg->type);
                        conn->state = CS_ERROR;
        }
 }
 
 static void
 sendedLongMessage( TC_Connection *conn ) {
-       TCMsg *pmsg = (TCMsg*) conn->buf;
+       TCMsg *pmsg = conn->buf;
        switch(pmsg->type) {
                case TOPGETTYPE:
                        conn->state = CS_FINISH;
                        break;
                default:
-                       tlog(TL_ALARM,"Send unknown packet type: %d", pmsg->type);
+                       tlog(TL_ALARM,"Send unknown packet type: %u(0x%08x)", pmsg->type, pmsg->type);
                        conn->state = CS_ERROR;
        }
 }
diff --git a/top.h b/top.h
index 64a8f1b..8fb1dd3 100644 (file)
--- a/top.h
+++ b/top.h
@@ -55,7 +55,7 @@ typedef struct {
         UnitInfo   units[1];
 } MassiveUnit;
 
-#define MUHDRSZ         (2*sizeof(u_int32_t))
+#define MUHDRSZ         offsetof( MassiveUnit, units )
 
 MassiveUnit *allocUnits(int n);
 void fillUnit( MassiveUnit* mu, UnitInfo *unit );