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;
}
}
conn = cfg.pool.conn[i];
switch( conn->state ) {
case CS_INPROCESS:
- TC_ServerConnect( conn );
+ TC_ServerConnect( conn, 0 );
break;
case CS_CONNECTED: /* we have connected to remote host */
TC_Send( conn );
break;
case CS_READ:
if ( conn->readyio ) {
- TC_Read( conn );
+ TC_Read( conn, TCMSGHDRSZ );
if ( conn->state != CS_READ ) i--; /* check it one more time */
}
break;