Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Logger / simple-server / Logging_Acceptor.cpp
blob5b0c7b1db918188fbcc7568ad04d8e86a0afb2a2
1 #include "ace/WFMO_Reactor.h"
2 #include "ace/Log_Msg.h"
4 #include "Logging_Acceptor.h"
5 #include "Logging_Handler.h"
6 #include "Reactor_Singleton.h"
8 // Initialize peer_acceptor object.
9 int
10 Logging_Acceptor::open (const ACE_INET_Addr &addr)
12 // Reuse addr if already in use.
13 if (this->peer_acceptor_.open (addr, 1) == -1)
14 return -1;
15 else
16 return 0;
19 // Performs termination activities.
20 int
21 Logging_Acceptor::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
23 this->peer_acceptor_.close ();
24 // Note, this object MUST be allocated dynamically!
25 delete this;
26 return 0;
29 // Returns underlying device descriptor.
30 ACE_HANDLE
31 Logging_Acceptor::get_handle () const
33 return this->peer_acceptor_.get_handle ();
36 // Accepts connections from client and registers new object with the
37 // ACE_Reactor.
38 int
39 Logging_Acceptor::handle_input (ACE_HANDLE)
41 Logging_Handler *svc_handler;
43 ACE_NEW_RETURN (svc_handler, Logging_Handler, -1);
45 // Accept the connection from a client client daemon.
47 // Try to find out if the implementation of the reactor that we are
48 // using requires us to reset the event association for the newly
49 // created handle. This is because the newly created handle will
50 // inherit the properties of the listen handle, including its event
51 // associations.
52 int const reset_new_handle = this->reactor ()->uses_event_associations ();
54 if (this->peer_acceptor_.accept (svc_handler->peer (), // stream
55 0, // remote address
56 0, // timeout
57 1, // restart
58 reset_new_handle // reset new handler
59 ) == -1
60 || svc_handler->open () == -1)
62 svc_handler->close ();
63 ACE_ERROR_RETURN ((LM_ERROR, "%p", "accept/open failed"), -1);
66 return 0;