1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/*
** $Id: Iterative_Logging_Server.h 80826 2008-03-04 14:51:23Z wotte $
**
** Copyright 2001 Addison Wesley. All Rights Reserved.
*/
#ifndef _ITERATIVE_LOGGING_SERVER_H
#define _ITERATIVE_LOGGING_SERVER_H
#include "ace/FILE_IO.h"
#include "ace/INET_Addr.h"
#include "ace/Log_Msg.h"
#include "Logging_Handler.h"
#include "Logging_Server.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_SOCK_Stream;
ACE_END_VERSIONED_NAMESPACE_DECL
class Iterative_Logging_Server : public Logging_Server
{
protected:
ACE_FILE_IO log_file_;
Logging_Handler logging_handler_;
public:
Iterative_Logging_Server () : logging_handler_ (log_file_) {}
virtual ~Iterative_Logging_Server () { log_file_.close (); }
Logging_Handler &logging_handler () { return logging_handler_; }
protected:
// Override inherited open() from Logging_Server
virtual int open (u_short port) {
if (make_log_file (log_file_) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "make_log_file()"), -1);
return Logging_Server::open (port);
}
virtual int handle_connections () {
ACE_INET_Addr logging_peer_addr;
if (acceptor ().accept (logging_handler_.peer (),
&logging_peer_addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "acceptor.accept()"), -1);
ACE_DEBUG ((LM_DEBUG, "Accepted connection from %s\n",
logging_peer_addr.get_host_name ()));
return 0;
}
virtual int handle_data (ACE_SOCK_Stream *) {
while (logging_handler_.log_record () != -1)
continue;
logging_handler_.close (); // Close the socket handle.
return 0;
}
};
#endif /* _ITERATIVE_LOGGING_SERVER_H */
|