Include changes memory
[ACE_TAO.git] / ACE / examples / C++NPv2 / Reactor_Logging_Server_Adapter.cpp
blob37e6fd6232537bbedb1558676e5f54dd53fc1e48
1 /*
2 ** Copyright 2002 Addison Wesley. All Rights Reserved.
3 */
5 #ifndef _REACTOR_LOGGING_SERVER_ADAPTER_C
6 #define _REACTOR_LOGGING_SERVER_ADAPTER_C
8 #include "ace/ACE.h"
9 #include "ace/INET_Addr.h"
10 #include "ace/Truncate.h"
11 #include "Reactor_Logging_Server_Adapter.h"
12 #include "ace/OS_NS_string.h"
13 #include "ace/OS_NS_stdio.h"
14 #include <memory>
16 template <class ACCEPTOR> int
17 Reactor_Logging_Server_Adapter<ACCEPTOR>::init (int argc,
18 ACE_TCHAR *argv[]) {
19 int i;
20 char **array = 0;
21 ACE_NEW_RETURN (array, char*[argc], -1);
22 std::unique_ptr<char *[]> char_argv (array);
24 for (i = 0; i < argc; ++i)
25 char_argv[i] = ACE::strnew (ACE_TEXT_ALWAYS_CHAR (argv[i]));
26 ACE_NEW_NORETURN (server_, Reactor_Logging_Server<ACCEPTOR>
27 (i, char_argv.get (),
28 ACE_Reactor::instance ()));
29 for (i = 0; i < argc; ++i) ACE::strdelete (char_argv[i]);
30 return server_ == 0 ? -1 : 0;
33 // NOTE! The (ACCEPTOR*) cast below is NOT technically necessary, but it
34 // works around a bug in IBM XL C++ 9 that resolves to the wrong version of
35 // handle_close().
36 template <class ACCEPTOR> int
37 Reactor_Logging_Server_Adapter<ACCEPTOR>::fini ()
38 { ((ACCEPTOR*)server_)->handle_close (); server_ = 0; return 0; }
41 template <class ACCEPTOR> int
42 Reactor_Logging_Server_Adapter<ACCEPTOR>::info
43 (ACE_TCHAR **bufferp, size_t length) const {
44 ACE_INET_Addr local_addr;
45 server_->acceptor ().get_local_addr (local_addr);
47 ACE_TCHAR buf[BUFSIZ];
48 ACE_OS::sprintf (buf,
49 ACE_TEXT ("%hu"),
50 local_addr.get_port_number ());
51 ACE_OS::strcat
52 (buf, ACE_TEXT ("/tcp # Reactor-based logging server\n"));
53 if (*bufferp == 0)
54 *bufferp = ACE::strnew (buf);
55 else
56 ACE_OS::strncpy (*bufferp, buf, length);
58 return ACE_Utils::truncate_cast<int> (ACE_OS::strlen (*bufferp));
62 template <class ACCEPTOR> int
63 Reactor_Logging_Server_Adapter<ACCEPTOR>::suspend ()
64 { return server_->reactor ()->suspend_handler (server_); }
67 template <class ACCEPTOR> int
68 Reactor_Logging_Server_Adapter<ACCEPTOR>::resume ()
69 { return server_->reactor ()->resume_handler (server_); }
71 #endif /* _REACTOR_LOGGING_SERVER_ADAPTER_C */