From ea6b79f72f7f5d3854d890c992e87f2cf6adc52c Mon Sep 17 00:00:00 2001 From: teodor Date: Thu, 30 Sep 2004 10:58:24 +0000 Subject: [PATCH] Clean up code --- tcp.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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; -- 2.46.1