File: Logging_Event_Handler.cpp

package info (click to toggle)
ace 6.2.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 49,348 kB
  • ctags: 42,082
  • sloc: cpp: 342,284; perl: 32,718; ansic: 20,838; sh: 3,759; python: 828; exp: 787; yacc: 511; xml: 330; lex: 158; lisp: 116; makefile: 82; csh: 20; tcl: 5
file content (45 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download
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
/*
** $Id: Logging_Event_Handler.cpp 91813 2010-09-17 07:52:52Z johnnyw $
**
** Copyright 2002 Addison Wesley. All Rights Reserved.
*/

#include "ace/FILE_Connector.h"

#include "Logging_Event_Handler.h"
#include "ace/OS_NS_string.h"
#include "ace/os_include/os_netdb.h"

int Logging_Event_Handler::open () {

  static const char LOGFILE_SUFFIX[] = ".log";
  char filename[MAXHOSTNAMELEN + sizeof (LOGFILE_SUFFIX)];
  ACE_INET_Addr logging_peer_addr;

  logging_handler_.peer ().get_remote_addr (logging_peer_addr);
  logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN);
  ACE_OS::strcat (filename, LOGFILE_SUFFIX);

  ACE_FILE_Connector connector;
  connector.connect (log_file_,
                     ACE_FILE_Addr (filename),
                     0, // No timeout.
                     ACE_Addr::sap_any, // Ignored.
                     0, // Don't try to reuse the addr.
                     O_RDWR|O_CREAT|O_APPEND,
                     ACE_DEFAULT_FILE_PERMS);

  return reactor ()->register_handler
    (this, ACE_Event_Handler::READ_MASK);
}

int Logging_Event_Handler::handle_input (ACE_HANDLE)
{ return logging_handler_.log_record (); }

int Logging_Event_Handler::handle_close (ACE_HANDLE,
                                         ACE_Reactor_Mask) {
  logging_handler_.close ();
  log_file_.close ();
  delete this;
  return 0;
}