00001
00002
00003 #include "orbsvcs/Event/ECG_UDP_EH.h"
00004 #include "ace/Reactor.h"
00005 #include "ace/INET_Addr.h"
00006
00007 #if !defined(__ACE_INLINE__)
00008 #include "orbsvcs/Event/ECG_UDP_EH.i"
00009 #endif
00010
00011 ACE_RCSID(Event, ECG_UDP_EH, "ECG_UDP_EH.cpp,v 1.4 2006/03/14 06:14:25 jtc Exp")
00012
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015 TAO_ECG_UDP_EH::TAO_ECG_UDP_EH (TAO_ECG_Dgram_Handler *recv)
00016 : receiver_ (recv)
00017 {
00018 ACE_ASSERT (this->receiver_);
00019 }
00020
00021 TAO_ECG_UDP_EH::~TAO_ECG_UDP_EH (void)
00022 {
00023 }
00024
00025 int
00026 TAO_ECG_UDP_EH::open (const ACE_INET_Addr& ipaddr,
00027 int reuse_addr)
00028 {
00029
00030 if (!this->receiver_)
00031 return -1;
00032
00033 if (this->dgram_.open (ipaddr, PF_INET, 0, reuse_addr) == -1)
00034 ACE_ERROR_RETURN ((LM_ERROR,
00035 "Unable to open udp handler: "
00036 "error opening receiving dgram.\n"),
00037 -1);
00038
00039 if (!this->reactor ()
00040 || 0 != this->reactor ()->register_handler (this->dgram_.get_handle (),
00041 this,
00042 ACE_Event_Handler::READ_MASK))
00043 {
00044 this->dgram_.close ();
00045 ACE_ERROR_RETURN ((LM_ERROR,
00046 "Cannot register handler with reactor.\n"),
00047 -1);
00048 }
00049
00050 return 0;
00051 }
00052
00053 int
00054 TAO_ECG_UDP_EH::shutdown (void)
00055 {
00056
00057 if (!this->receiver_)
00058 return -1;
00059
00060 int result = 0;
00061 if (this->reactor ())
00062 {
00063 result = this->reactor ()->remove_handler (this->dgram_.get_handle (),
00064 ACE_Event_Handler::READ_MASK);
00065 }
00066 if (result != 0)
00067 ACE_ERROR ((LM_ERROR,
00068 "Unable to deregister handler from reactor "
00069 "on shutdown.\n"));
00070
00071 result = this->dgram_.close ();
00072 if (result != 0)
00073 ACE_ERROR ((LM_ERROR,
00074 "Unable to close receiving dgram on shutdown.\n"));
00075
00076 this->receiver_ = 0;
00077
00078 return result;
00079 }
00080
00081 int
00082 TAO_ECG_UDP_EH::handle_input (ACE_HANDLE)
00083 {
00084 return this->receiver_->handle_input (this->dgram_);
00085 }
00086
00087 TAO_END_VERSIONED_NAMESPACE_DECL
00088
00089