summaryrefslogtreecommitdiff
path: root/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.i
blob: 50cd399cae2ca5745416478ad5b00e0018670292 (plain)
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
65
66
67
68
69
70
71
72
73
74
/* -*- C++ -*- */
// $Id$


#include "ace/Service_Config.h"
#include "ace/Get_Opt.h"

ACE_INLINE
Handle_Timeout::Handle_Timeout (void): count (0)
{
}

ACE_INLINE int
Handle_Timeout::info (char **strp, size_t length) const
{
  char buf[BUFSIZ];

  ACE_OS::sprintf (buf, "%s", "# tests timeout facility\n");

  if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
    return -1;
  else
    ACE_OS::strncpy (*strp, buf, length);
  return ACE_OS::strlen (buf);
}

ACE_INLINE int
Handle_Timeout::init (int argc, char *argv[])
{
  ACE_Time_Value delta (10);
  ACE_Time_Value interval (1);
  ACE_Get_Opt    get_opt (argc, argv, "a:d:i:", 0);
  int	     arg = 0;

  for (int c; (c = get_opt ()) != -1; )
     switch (c)
       {
       case 'd': 
	 delta.sec (ACE_OS::atoi (get_opt.optarg));
	 break;
       case 'i':
	 interval.sec (ACE_OS::atoi (get_opt.optarg));
	 break;
       case 'a':
	 arg = atoi (get_opt.optarg);
	 break;
       default:
	 break;
       }
  
  return ACE_Service_Config::reactor ()->schedule_timer (this, (void *) arg, delta, interval);
}

ACE_INLINE int 
Handle_Timeout::fini (void) 
{
  return 0;
}

ACE_INLINE int
Handle_Timeout::get_handle (void) const
{
  return -1;
}

ACE_INLINE int
Handle_Timeout::handle_timeout (const ACE_Time_Value &tv, const void *arg)
{
  if (this->count++ >= 10)
    return -1; /* Automatically cancel periodic timer... */
  ACE_DEBUG ((LM_INFO, "time for this(%u) expired at (%d, %d) with arg = %d\n",
	     this, tv.sec (), tv.usec (), int (arg)));
  return 0;
}