From: teodor Date: Thu, 30 Sep 2004 10:58:24 +0000 (+0000) Subject: Clean up code X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=ea6b79f72f7f5d3854d890c992e87f2cf6adc52c;p=tedtools.git Clean up code --- diff --git a/tcp.c b/tcp.c index df10a46..d65060c 100644 --- a/tcp.c +++ b/tcp.c @@ -157,6 +157,8 @@ TC_Connection * TC_fillConnection(TC_Connection *sc, char *name, u_int32_t port) { if ( !sc ) sc = (TC_Connection *)t0malloc(sizeof(TC_Connection)); + else + memset(sc, 0, sizeof(TC_Connection)); sc->serv_addr.sin_family = AF_INET; sc->serv_addr.sin_addr.s_addr = (name) ? inet_addr(name) : htonl(INADDR_ANY); sc->serv_addr.sin_port = htons(port); @@ -423,18 +425,20 @@ TC_FreeConnection( TC_Connection *cs ) { u_int32_t TC_Talk( TC_Connection *cs ) { - u_int32_t ret = TC_ServerInitConnect( cs ); + if ( cs->state==CS_NOTINITED ) + TC_ServerInitConnect( cs ); - while( ret == CS_INPROCESS ) { - ret = TC_ServerConnect(cs, 100); - } + while( cs->state == CS_INPROCESS ) + TC_ServerConnect(cs, 100); - if ( ret != CS_CONNECTED ) - return ret; + if ( cs->state != CS_CONNECTED ) + return cs->state; - while( ret != CS_FINISHSEND ) { - ret = TC_Send(cs); - if ( ret == CS_ERROR ) return ret; + cs->state = CS_SEND; + cs->ptr = cs->buf; + while( cs->state != CS_FINISHSEND ) { + while( !TC_ReadyIO( &cs, 1, 100) ); + if ( TC_Send(cs) == CS_ERROR ) return CS_ERROR; } cs->state = CS_READ;