2 ** Copyright 2001 Addison Wesley. All Rights Reserved.
5 #include "ace/FILE_Addr.h"
6 #include "ace/FILE_Connector.h"
7 #include "ace/FILE_IO.h"
8 #include "ace/INET_Addr.h"
9 #include "ace/SOCK_Stream.h"
10 #include "Logging_Server.h"
11 #include "ace/OS_NS_string.h"
12 #include "ace/OS_NS_stdlib.h"
13 #include "ace/os_include/os_netdb.h"
15 int Logging_Server::run (int argc
, char *argv
[])
17 if (this->open (argc
> 1 ? ACE_OS::atoi (argv
[1]) : 0) == -1)
21 if (wait_for_multiple_events () == -1)
23 if (handle_connections () == -1)
25 if (handle_data () == -1)
29 ACE_NOTREACHED (return 0;)
33 int Logging_Server::open (u_short logger_port
)
35 ACE_INET_Addr server_addr
;
39 result
= server_addr
.set (logger_port
,
40 (ACE_UINT32
) INADDR_ANY
);
42 result
= server_addr
.set ("ace_logger",
43 (ACE_UINT32
) INADDR_ANY
);
44 if (result
== -1) return -1;
46 // Start listening, enable reuse of listen address for quick restarts.
47 return acceptor_
.open (server_addr
, 1);
51 int Logging_Server::make_log_file (ACE_FILE_IO
&logging_file
,
52 ACE_SOCK_Stream
*logging_peer
)
54 char filename
[MAXHOSTNAMELEN
+ sizeof (".log")];
56 if (logging_peer
!= 0) { // Use client's hostname as log file name.
57 ACE_INET_Addr logging_peer_addr
;
58 logging_peer
->get_remote_addr (logging_peer_addr
);
59 logging_peer_addr
.get_host_name (filename
, MAXHOSTNAMELEN
);
60 ACE_OS::strcat (filename
, ".log");
63 ACE_OS::strcpy (filename
, "logging_server.log");
65 ACE_FILE_Connector connector
;
66 return connector
.connect (logging_file
,
67 ACE_FILE_Addr (filename
),
69 ACE_Addr::sap_any
, // Ignored.
70 0, // Don't try to reuse the addr.
71 O_RDWR
|O_CREAT
|O_APPEND
,
72 ACE_DEFAULT_FILE_PERMS
);