- 论坛徽章:
- 0
|
本帖最后由 liyandong106 于 2011-04-17 20:19 编辑
求帮助、- nrecv = recv(fd, bp, data_len, 0);
- //debug(255)("->%s\n", data);
- printf("nrecv data_count = %d\n",nrecv);
- if (nrecv == -1)
- {
- if( (errno == EAGAIN)||(errno==EWOULDBLOCK) )
- {
- debug(255)("recv error1\n");
- //CloseConn(channel);
- //return -1;
- break;
- }
- else
- {
- debug(255)("recv error2\n");
- CloseConn(channel);
- return -1;
- }
- }
- else if (nrecv == 0 )
- {
- CloseConn(channel);
- return -1;
- }
- // data_len-=nrecv;
- // bp+=nrecv;
- // }
- if(virus == 1)
- {
- /*
- if(check_buf_virus(data, nrecv, "TCP PROXY") == 0)
- {
- CloseConn(channel);
- return -1;
- }
- */
- if(clamav_scan_buf(data_count, count_len, "TCP PROXY") == 0)
- {
- CloseConn(channel);
- return -1;
- }
- }
- //sleep(30);
- if(logo == 1)
- {
- printf("come in BDProtocolParse\n");
- ret = BDProtocolParse(data_count,&count_len,&struBase26Info);
- printf("ret = %d\n",ret);
-
-
- total_send = 0;
- while (total_send!=count_len)
- {
- nsend = send(other_fd, data_count+total_send, count_len-total_send, 0);
- // nsend = send(other_fd, data_count, count_len, 0);
- if (nsend <= 0)
- {
- if( errno == EAGAIN )
- {
- continue;
- }
- perror("send");
- CloseConn(channel);
- return -1;
- }
- total_send += nsend;
- }
- printf("nsen = %d\n",nsend);
- }
- else
- {
- //sleep(30);
- total_send = 0;
- while (total_send!=nrecv)
- {
- nsend = send(other_fd, data_count+total_send, nrecv-total_send, 0);
- if (nsend <= 0)
- {
- if( errno == EAGAIN )
- {
- continue;
- }
- perror("send");
- CloseConn(channel);
- return -1;
- }
- total_send += nsend;
- }
- printf("nsen = %d\n",nsend);
- }
- FD_ZERO(&rfds);
- FD_SET(channel->conn_sd, &rfds);
- FD_SET(channel->server_sd, &rfds);
- sd_max = channel->conn_sd>channel->server_sd? channel->conn_sd : channel->server_sd ;
- tv.tv_sec = 2;
- tv.tv_usec = 0;
- ret = select( sd_max+1, &rfds, NULL, NULL, &tv);
- if (ret < 0)
- {
- perror("2. Select:");
- debug(1)("2. select() error\n");
- CloseConn(channel);
- return -1;
- }
- else if(ret == 0)
- {
- debug(255)("timeout\n");
- break;
- }
- if ( FD_ISSET(channel->conn_sd, &rfds) )
- {
- channel->status = ST_CLIENT_READ_READY;
- }
- if ( FD_ISSET(channel->server_sd, &rfds) )
- {
- channel->status = ST_SERVER_READ_READY;
- }
- }
- free(data_count);
- notify.sd_local = channel->conn_sd;
- notify.sd_remote = channel->server_sd;
- notify.from = THREAD_WORK;
- notify.context = channel->context;
- move_to_spare_pool(channel);
- dispatch_local_ev(notify, thread_info);
- return 0;
- }
复制代码 |
|