现在,我编写了一个C ++程序来获取带有特定URL的每个页面(就像搜索引擎的Spider程序一样),因此将以下内容发送给主机:“ GET / HTTP/1.1\r\nHost:www.163.com\r\nConnection:close\r\n\r\n
”,但是当我从主机中接收所有软件包时,连接没有立即关闭。那么我现在可以使用HTTP / 1.1做什么?
当发生READ事件时,我使用epoll检查套接字。
void* NetService::epoll_process ( void* arg )
{
NetService* netservice = ( NetService* ) arg;
int nfds;
int sockfd;
for ( ; ; )
{
// return the nums of sockfds which there can be read or write now.
nfds=epoll_wait ( netservice->epollfd,netservice->events,20,200 );
//process the active sockfds
for ( int i=0; i < nfds; ++i )
{
if ( netservice->events[i].events&EPOLLIN )
{
if ( ( sockfd = netservice->events[i].data.fd ) < 0 )
continue;
netservice->recv_pkg ( sockfd );
}
}
/*there should to check all the sockfds of their timeouts;*/
if ( nfds == 0 )
{
//cout<<"**********time out***********"<<endl;
}
} //(for(;;))
close ( netservice->epollfd );
return NULL;
}
最佳答案
使用Connection: Close
标头。