- 论坛徽章:
- 0
|
怎么从sock读出的字节个数总为0
FD_ZERO(&(fst.rset));
FD_SET(fst.ias_sockfd, &(fst.rset));
maxfd = fst.ias_sockfd + 1;
while(1)
{
FD_ZERO(&(fst.rset));
FD_SET(fst.ias_sockfd, &(fst.rset));
maxfd = fst.ias_sockfd + 1;
printf("!!!!!!!!!!\n" ;
rtn = select(maxfd, &(fst.rset), NULL, NULL, &time_interval);
if (rtn < 0)
{
log_write(fst.logfile, "Select failed!" ;
break;
}
if( FD_ISSET(fst.ias_sockfd, &(fst.rset)) )
{
memset(left_buf, 0x00, sizeof(left_buf));
memset(read_buf, 0x00, sizeof(read_buf));
read_len = 0;
left_len = 0;
printf("sockfd = %d\n", fst.ias_sockfd);
read_len = read(fst.ias_sockfd, read_buf, BUF_MAX_LEN);
/* read_len = readn(fst.ias_sockfd, read_buf, BUF_MAX_LEN); */
printf("read_len = %d\n", read_len);
if (read_len >; 0)
{
formatbuftostr(printbuf, read_buf, read_len, ;
log_write(fst.logfile, "\n%s", printbuf);
if ( read_len >;= 4)
{
if (processdata(read_buf, read_len) < 0)
break;/*FD_CLR(fst.ias_sockfd, &(fst.rset));*/
}
}
else if (read_len == 0)
{
FD_CLR(fst.ias_sockfd, &(fst.rset));
}
else /* read_len<0 */
{
log_write(fst.logfile, "Read Error data from socket. Data length=
%d\n", read_len);
FD_CLR(fst.ias_sockfd, &(fst.rset));
closeconnection(&fst);
break;
}
}/* FD_ISSET */
/*
sleep(5);
rtn = sendtdata(&fst, testmjf, 23);
if (rtn < 0)
{
log_write(fst.logfile, "test: send data failed." ;
}
*/ |
|