|
int ACE_TMAIN(int,ACE_TCHAR* [])
{
ACE_INET_Addr port("5000");
ACE_SOCK_Acceptor acceptor;
if(acceptor.open(port,1)==-1)
ACE_ERROR_RETURN((LM_ERROR,ACE_TEXT("%p\n"),ACE_TEXT("acceptor.open")),100);
while(1)
{
ACE_SOCK_Stream peer;
ACE_INET_Addr peer_addr;
ACE_Time_Value timeout(30,0);
#if 0
if(acceptor.accept(peer)==-1)
ACE_ERROR_TRTURN((LM_ERROR,ACE_TEXT("(%P|%t) failed to accept "),ACE_TEXT("client connection\n")),100);
#endif //if 0 此处是什么意思啊。何时才是0的情况啊?
if(acceptor.accept(peer,&peer_addr,&timeout,0)==-1)
{
if(ACE_OS::last_error()==EINTR)
ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) interrupted while "),ACE_TEXT("waiting for connection\n")));
else
if(ACE_OS::last_error()==ETIMEDOUT)
ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t) timeout while"),ACE_TEXT("waiting for conncection\n")));
}
else
{
ACE_TCHAR peer_name[200];
peer_addr.addr_to_string(peer_name,200);
ACE_DEBUG((LM_DEBUG,ACE_TEXT("(%P|%t ) connection from %s\n"),peer_name));
char buf[4096];
ssize_t bytes_received;
while((bytes_received=peer.recv(buf,sizeof(buf)))!=-1)
{
peer.send_n(buf,bytes_received);
}
peer.close();
}
}
} |
|