2 ** Copyright 2001 Addison Wesley. All Rights Reserved.
5 #ifndef _REACTIVE_LOGGING_SERVER_H
6 #define _REACTIVE_LOGGING_SERVER_H
8 #include "ace/INET_Addr.h"
9 #include "ace/SOCK_Acceptor.h"
10 #include "ace/SOCK_Stream.h"
11 #include "ace/Log_Record.h"
12 #include "ace/Handle_Set.h"
13 #include "ace/Basic_Types.h"
14 #include "ace/Truncate.h"
15 #include "ace/os_include/os_fcntl.h"
16 #include "Iterative_Logging_Server.h"
18 class Reactive_Logging_Server
: public Iterative_Logging_Server
21 // Keep track of the acceptor socket handle and all the
22 // connected stream socket handles.
23 ACE_Handle_Set master_handle_set_
;
25 // Keep track of handles marked as active by <select>.
26 ACE_Handle_Set active_handles_
;
28 virtual int open (u_short logger_port
) {
29 Iterative_Logging_Server::open (logger_port
);
30 master_handle_set_
.set_bit (acceptor ().get_handle ());
31 acceptor ().enable (ACE_NONBLOCK
);
35 virtual int wait_for_multiple_events () {
36 active_handles_
= master_handle_set_
;
37 int width
= ACE_Utils::truncate_cast
<int> ((intptr_t)active_handles_
.max_set ()) + 1;
39 active_handles_
.fdset (),
42 0) == -1) // no timeout
45 ((ACE_HANDLE
) ((intptr_t) active_handles_
.max_set () + 1));
49 virtual int handle_connections () {
50 if (active_handles_
.is_set (acceptor ().get_handle ())) {
51 while (acceptor ().accept (logging_handler ().peer ()) == 0)
52 master_handle_set_
.set_bit
53 (logging_handler ().peer ().get_handle ());
55 // Remove acceptor handle from further consideration.
56 active_handles_
.clr_bit (acceptor ().get_handle ());
61 virtual int handle_data (ACE_SOCK_Stream
*) {
62 ACE_Handle_Set_Iterator
peer_iterator (active_handles_
);
64 for (ACE_HANDLE handle
;
65 (handle
= peer_iterator ()) != ACE_INVALID_HANDLE
;
67 logging_handler ().peer ().set_handle (handle
);
68 if (logging_handler ().log_record () == -1) {
69 // Handle connection shutdown or comm failure.
70 master_handle_set_
.clr_bit (handle
);
71 logging_handler ().close ();
78 #endif /* _REACTIVE_LOGGING_SERVER_H */