add .gitignore
[remotetop.git] / td_lmsg.c
index 7f27280..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;
        }
 }
@@ -89,7 +91,7 @@ ConnectionWorks() {
                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 );
@@ -102,7 +104,7 @@ ConnectionWorks() {
                                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;