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);
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;