int port=TOPD_SERVER_DEFAULT_PORT;
int i;
- MassiveUnit *mu;
TCMsg *pmsg;
TC_Connection cs;
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",
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;
}
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;
}
}
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 );