|
楼主 |
发表于 2008-11-11 19:32:10
|
显示全部楼层
这是我额外创建的另一个程序,现象一样,仍然会报错。DLL和Lib都是最新的。
#ifndef WINVER // 允许使用 Windows 95 和 Windows NT 4 或更高版本的特定功能。
#define WINVER 0x0500 //为 Windows98 和 Windows 2000 及更新版本改变为适当的值。
#endif
#ifndef _WIN32_WINNT // 允许使用 Windows NT 4 或更高版本的特定功能。
#define _WIN32_WINNT 0x0500 //为 Windows98 和 Windows 2000 及更新版本改变为适当的值。
#endif
#ifndef _WIN32_WINDOWS // 允许使用 Windows 98 或更高版本的特定功能。
#define _WIN32_WINDOWS 0x0510 //为 Windows Me 及更新版本改变为适当的值。
#endif
#ifndef _WIN32_IE // 允许使用 IE 4.0 或更高版本的特定功能。
#define _WIN32_IE 0x0600 //为 IE 5.0 及更新版本改变为适当的值。
#endif
#include "ace/streams.h"
#include "ace/Log_Msg.h"
#include "ace/Log_Msg_Callback.h"
#include "ace/Log_Record.h"
#include "ace/SOCK_Stream.h"
#include "ace/SOCK_Connector.h"
#include "ace/INET_Addr.h"
#include "ace/Singleton.h"
#include "ace/Message_Block.h"
#include "ace/Svc_Handler.h"
#include "ace/SOCK_Acceptor.h"
#include "ace/Reactor.h"
#include "ace/Acceptor.h"
#include "ace/Connector.h"
#include "ace/Reactor_Notification_Strategy.h"
#include "ace/Select_Reactor.h"
/************************************************************************
* *
* CLASS OF ClientService *
* *
************************************************************************/
class ClientService :
public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> super;
public:
int open(void * = 0);
// Called when input is available from the client.
virtual int handle_input(ACE_HANDLE fd = ACE_INVALID_HANDLE);
// Called when output is possible.
virtual int handle_output(ACE_HANDLE fd = ACE_INVALID_HANDLE);
// Called when this handler is removed from the ACE_Reactor.
virtual int handle_close(ACE_HANDLE handle, ACE_Reactor_Mask close_mask);
void send(int p_length, char * p_buffer);
//FEZ::ClientHandler * m_handler;
ACE_TCHAR m_peer_name[255];
ACE_INET_Addr m_peer_addr;
char m_log[1024];
};
/************************************************************************
* *
* CLASS OF ClientService *
* *
************************************************************************/
/*********************************************************************************************
Method :doExecute
Summary :线程主体函数
Parameters:NULL
return :void
2008-07-05 added by doug han
********************************************************************************************/
int ClientService::open(void *p)
{
if ( super::open(p) == -1 )
return -1;
//m_handler = SysCoreClientHandler::instance();
if ( this->peer().get_remote_addr(m_peer_addr) == 0 &&
m_peer_addr.addr_to_string(m_peer_name, 255) == 0 )
{
sprintf(m_log,
"Client Service Connection from %s\r\n",
m_peer_name);
//FEZCoreUtil::WriteLog(m_log);
}
std::string addr;
addr = m_peer_name;
int i = addr.find_first_of(':');
addr = addr.substr(0, i);
strcpy(m_peer_name, addr.c_str());
//SysCoreClientAddr::instance()->AddClient(this, m_peer_name, m_peer_addr.get_port_number());
return 0;
}
/*********************************************************************************************
Method :doExecute
Summary :线程主体函数
Parameters:NULL
return :void
2008-07-05 added by doug han
********************************************************************************************/
int ClientService::handle_input(ACE_HANDLE)
{
const size_t INPUT_SIZE = 4096;
char buffer[INPUT_SIZE];
ssize_t recv_cnt, send_cnt;
recv_cnt = this->peer().recv(buffer, sizeof(buffer));
if ( recv_cnt <= 0 )
{
sprintf(m_log,
"Client Service Connection closed %s\r\n",
m_peer_name);
//FEZCoreUtil::WriteLog(m_log);
return -1;
}
//m_handler->Extract(m_peer_name, m_peer_addr.get_port_number(), recv_cnt, buffer);
return 0;
}
/*********************************************************************************************
Method :doExecute
Summary :线程主体函数
Parameters:NULL
return :void
2008-07-05 added by doug han
********************************************************************************************/
int ClientService::handle_output (ACE_HANDLE)
{
ACE_Message_Block * mb;
ACE_Time_Value nowait(ACE_OS::gettimeofday());
while ( -1 != this->getq(mb, &nowait) )
{
ssize_t send_cnt = this->peer().send(mb->rd_ptr (), mb->length ());
if ( send_cnt == -1 )
{
ACE_ERROR((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("send")));
//FEZCoreUtil::WriteLog("Client Service Send err\r\n");
}
else
mb->rd_ptr(ACE_static_cast(size_t, send_cnt));
if ( mb->length() > 0 )
{
this->ungetq(mb);
break;
}
mb->release ();
}
return (this->msg_queue()->is_empty()) ? -1 : 0;
}
/*********************************************************************************************
Method :doExecute
Summary :线程主体函数
Parameters:NULL
return :void
2008-07-05 added by doug han
********************************************************************************************/
int ClientService::handle_close(ACE_HANDLE h, ACE_Reactor_Mask mask)
{
if ( mask == ACE_Event_Handler::WRITE_MASK )
return 0;
if ( this->peer().get_remote_addr(m_peer_addr) == 0 &&
m_peer_addr.addr_to_string(m_peer_name, 255) == 0 )
{
sprintf(m_log,
"Client Service Connection from %s closed\r\n",
m_peer_name);
//FEZCoreUtil::WriteLog(m_log);
}
std::string addr;
addr = m_peer_name;
int i = addr.find_first_of(':');
addr = addr.substr(0, i);
strcpy(m_peer_name, addr.c_str());
//SysCoreClientAddr::instance()->RemoveClient(m_peer_name, m_peer_addr.get_port_number());
return super::handle_close(h, mask);
}
/*********************************************************************************************
Method :doExecute
Summary :线程主体函数
Parameters:NULL
return :void
2008-07-05 added by doug han
********************************************************************************************/
void ClientService::send(int p_length, char * p_buffer)
{
ssize_t send_cnt;
send_cnt = this->peer().send(p_buffer, ACE_static_cast(size_t, p_length));
if ( send_cnt == p_length )
return;
if ( send_cnt == -1 && ACE_OS::last_error() != EWOULDBLOCK )
ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) %p\n"), ACE_TEXT ("send")));
if ( send_cnt == -1 )
send_cnt = 0;
ACE_Message_Block * mb;
size_t remaining = ACE_static_cast(size_t, (p_length - send_cnt));
ACE_NEW(mb, ACE_Message_Block(&p_buffer[send_cnt], remaining));
int output_off = this->msg_queue()->is_empty();
ACE_Time_Value nowait(ACE_OS::gettimeofday());
if ( this->putq(mb, &nowait) == -1 )
{
ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) %p; discarding data\n"), ACE_TEXT ("enqueue failed")));
mb->release ();
return;
}
if ( output_off )
this->reactor()->register_handler(this, ACE_Event_Handler::WRITE_MASK);
}
typedef ACE_Acceptor<ClientService, ACE_SOCK_ACCEPTOR> ClientAcceptor;
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Acceptor<ClientService, ACE_SOCK_ACCEPTOR>;
template class ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Acceptor<ClientService, ACE_SOCK_ACCEPTOR>
#pragma instantiate \
ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
ClientAcceptor g_clientAcceptor;
int main(int argc, char * argv[])
{
ACE::init();
ACE_Select_Reactor * selectReactor = new ACE_Select_Reactor();
ACE_Reactor * coreReactor = new ACE_Reactor(selectReactor, 1);
ACE_Reactor::instance(coreReactor, 1);
ACE_INET_Addr port_to_listen(1999);
if ( g_clientAcceptor.open(port_to_listen) == -1 )
{
return FALSE;
}
ACE::fini();
return 0;
} |
|