- #include <ace/Task.h>
- #include <ace/streams.h>
- #include <ace/Time_Value.h>
- #include <ace/Handle_Set.h>
- #include <ace/Log_Msg.h>
- #include <ace/INET_Addr.h>
- #include <ace/SOCK_Connector.h>
- #include <ace/SOCK_Acceptor.h>
- #include <ace/SOCK_Stream.h>
- #include <ace/Thread_Manager.h>
- #include <ace/Thread.h>
- #include <ace/Synch.h>
- #include <ace/Condition_T.h>
- #include <ace/Message_Block.h>
- #include <ace/Reactor.h>
- #include <ace/Dev_Poll_Reactor.h>
- #include <ace/Event_Handler.h>
- //typedef ACE_Acceptor<Sock_Handler, ACE_SOCK_Acceptor> AcceptHandler;
- class server : public ACE_Event_Handler
- {
- public:
- server(int clientCount = 10000);
- ~server();
- bool start(int port);
- ACE_HANDLE get_handle(void) const { return acceptor.get_handle(); }
- int handle_input(ACE_HANDLE handle) { /* ... */ }
- int handle_close(ACE_HANDLE handle) { /* ... */ }
- private:
- ACE_SOCK_Acceptor acceptor;
- ACE_Reactor *reactor;;
- };
- ACE_THR_FUNC_RETURN runThreadReactor(void *arg)
- {
- ACE_TRACE("runThreadReactor\n");
- ACE_Reactor *reactor = (ACE_Reactor *)arg;
- reactor->run_reactor_event_loop();
- return NULL;
- }
- server::server(int clientCount)
- {
- ACE_Dev_Poll_Reactor *ePoll_reactor = new ACE_Dev_Poll_Reactor(clientCount);
- reactor = new ACE_Reactor(ePoll_reactor);
- }
- server::~server()
- {
- }
- bool server::start(int port,
- bool isPacket)
- {
- ACE_INET_Addr addr(port);
- if (acceptor.open(addr, 1) == -1)
- {
- ACE_ERROR((LM_ERROR, "failed to open port:%d to linsten\n", port));
- return false;
- }
- if (reactor->register_handler(this, ACE_Event_Handler::ACCEPT_MASK) == -1)
- {
- ACE_ERROR((LM_ERROR, "failed to register handler\n"));
- if (-1 == acceptor.close())
- ACE_ERROR((LM_ERROR, "failed to close acceptor\n"));
- return false;
- }
- ACE_Thread_Manager::instance()->spawn_n(10, runThreadReactor, &reactor);
- ACE_DEBUG((LM_DEBUG, "server(%d) start completed\n", port));
- return true;
- }
- int main()
- {
- server *srv;
- ACE_NEW_NORETURN(srv, server(1000));
- srv->start(9688);
- while(1) usleep(1);
- return 0;
- }
复制代码 一运行到reactor->run_reactor_event_loop()就段错误,就算什么都不做,reactor什么事件都不注册。
找了很久都没想明白。 |