summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/ECG_UDP_EH.cpp
blob: b47650a3a8b0dfc92a4aba6a79ea5a45df972ac9 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// $Id$

#include "orbsvcs/Event/ECG_UDP_EH.h"
#include "ace/Reactor.h"
#include "ace/INET_Addr.h"

#if !defined(__ACE_INLINE__)
#include "orbsvcs/Event/ECG_UDP_EH.inl"
#endif /* __ACE_INLINE__ */



TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_ECG_UDP_EH::TAO_ECG_UDP_EH (TAO_ECG_Dgram_Handler *recv)
  :  receiver_ (recv)
{
  ACE_ASSERT (this->receiver_);
}

TAO_ECG_UDP_EH::~TAO_ECG_UDP_EH (void)
{
}

int
TAO_ECG_UDP_EH::open (const ACE_INET_Addr& ipaddr,
                      int reuse_addr)
{
  // Check that we haven't been closed already.
  if (!this->receiver_)
    return -1;

  if (this->dgram_.open (ipaddr, PF_INET, 0, reuse_addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Unable to open udp handler: "
                       "error opening receiving dgram.\n"),
                       -1);

  if (!this->reactor ()
      || 0 != this->reactor ()->register_handler (this->dgram_.get_handle (),
                                                  this,
                                                  ACE_Event_Handler::READ_MASK))
    {
      this->dgram_.close ();
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Cannot register handler with reactor.\n"),
                        -1);
    }

  return 0;
}

int
TAO_ECG_UDP_EH::shutdown (void)
{
  // Already shut down.
  if (!this->receiver_)
    return -1;

  int result = 0;
  if (this->reactor ())
    {
      result = this->reactor ()->remove_handler (this->dgram_.get_handle (),
                                                 ACE_Event_Handler::READ_MASK);
    }
  if (result != 0)
    ACE_ERROR ((LM_ERROR,
                "Unable to deregister handler from reactor "
                "on shutdown.\n"));

  result = this->dgram_.close ();
  if (result != 0)
    ACE_ERROR ((LM_ERROR,
                "Unable to close receiving dgram on shutdown.\n"));

  this->receiver_ = 0;

  return result;
}

int
TAO_ECG_UDP_EH::handle_input (ACE_HANDLE)
{
  return this->receiver_->handle_input (this->dgram_);
}

TAO_END_VERSIONED_NAMESPACE_DECL

// ****************************************************************