summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/Bug_1269_Regression/Server_Timer.cpp
blob: f099a972b94d26f5ace25edf8c0dee6aa25455d0 (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
/**
 * @file Server_Timer.cpp
 *
 * $Id$
 *
 * @author Carlos O'Ryan <coryan@atdesk.com>
 *
 */
#include "Server_Timer.h"
#include "ace/Reactor.h"
#include "ace/OS_NS_string.h"

ACE_RCSID(Bug_1269_Regression, Server_Timer, "$Id$")

Server_Timer::Server_Timer(Test::Echo_ptr echo,
                           ACE_Reactor * reactor)
  : ACE_Event_Handler (reactor)
  , echo_(Test::Echo::_duplicate(echo))
{
}

void
Server_Timer::activate (void)
{
  ACE_Time_Value tv (0, 20000);
  this->reactor()->schedule_timer (this, 0, tv);
}

int
Server_Timer::handle_timeout (ACE_Time_Value const &, void const *)
{
  Test::Payload pload(1024);
  pload.length(1024);

  ACE_OS::memset(pload.get_buffer(), pload.length(), 0);

  try
  {
    Test::Echo_var echo =
      Test::Echo::_duplicate (this->echo_.in());

    if(CORBA::is_nil (echo.in()))
      return 0;

    echo->echo_payload (pload);

    ACE_Time_Value tv (0, 20000);
    this->reactor()->schedule_timer (this, 0, tv);
  }
  catch (const CORBA::Exception&)
  {
    this->echo_ = Test::Echo::_nil ();

    this->reactor()->cancel_timer(this);

    return -1;
  }

  return 0;
}

int
Server_Timer::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
{
  delete this;
  return 0;
}