2 ** Copyright 2001 Addison Wesley. All Rights Reserved.
5 #ifndef _REACTIVE_LOGGING_SERVER_EX_H
6 #define _REACTIVE_LOGGING_SERVER_EX_H
9 #include "ace/FILE_IO.h"
10 #include "ace/Handle_Set.h"
11 #include "ace/Hash_Map_Manager.h"
12 #include "ace/INET_Addr.h"
13 #include "ace/Log_Record.h"
14 #include "ace/SOCK_Acceptor.h"
15 #include "ace/SOCK_Stream.h"
16 #include "Logging_Server.h"
17 #include "Logging_Handler.h"
18 #include "ace/Null_Mutex.h"
19 #include "ace/Truncate.h"
20 #include "ace/os_include/os_fcntl.h"
22 typedef ACE_Hash_Map_Manager
<ACE_HANDLE
,
24 ACE_Null_Mutex
> LOG_MAP
;
26 class Reactive_Logging_Server_Ex
: public Logging_Server
29 // Associate an active handle to an <ACE_FILE_IO> pointer.
32 // Keep track of acceptor socket and all the connected
33 // stream socket handles.
34 ACE_Handle_Set master_handle_set_
;
36 // Keep track of read handles marked as active by <select>.
37 ACE_Handle_Set active_read_handles_
;
39 virtual int open (u_short port
) {
40 Logging_Server::open (port
);
41 master_handle_set_
.set_bit (acceptor ().get_handle ());
42 acceptor ().enable (ACE_NONBLOCK
);
46 virtual int wait_for_multiple_events () {
47 active_read_handles_
= master_handle_set_
;
48 int width
= ACE_Utils::truncate_cast
<int> ((intptr_t)active_read_handles_
.max_set ()) + 1;
50 return ACE::select (width
, active_read_handles_
);
53 virtual int handle_connections () {
54 ACE_SOCK_Stream logging_peer
;
56 while (acceptor ().accept (logging_peer
) != -1) {
57 ACE_FILE_IO
*log_file
= new ACE_FILE_IO
;
59 // Use the client's hostname as the logfile name.
60 make_log_file (*log_file
, &logging_peer
);
62 // Add the new <logging_peer>'s handle to the map and
63 // to the set of handles we <select> for input.
64 log_map_
.bind (logging_peer
.get_handle (), log_file
);
65 master_handle_set_
.set_bit (logging_peer
.get_handle ());
67 active_read_handles_
.clr_bit (acceptor ().get_handle ());
71 virtual int handle_data (ACE_SOCK_Stream
*) {
72 ACE_Handle_Set_Iterator
peer_iterator (active_read_handles_
);
74 for (ACE_HANDLE handle
;
75 (handle
= peer_iterator ()) != ACE_INVALID_HANDLE
;
77 ACE_FILE_IO
*log_file
= 0;
78 log_map_
.find (handle
, log_file
);
79 Logging_Handler
logging_handler (*log_file
, handle
);
81 if (logging_handler
.log_record () == -1) {
82 logging_handler
.close ();
83 master_handle_set_
.clr_bit (handle
);
84 log_map_
.unbind (handle
);
93 #endif /* _REACTIVE_LOGGING_SERVER_EX_H */