ECG_Simple_Mcast_EH.cpp

Go to the documentation of this file.
00001 // ECG_Simple_Mcast_EH.cpp,v 1.6 2006/03/14 06:14:25 jtc Exp
00002 
00003 #include "orbsvcs/Event/ECG_Simple_Mcast_EH.h"
00004 #include "ace/Log_Msg.h"
00005 #include "ace/Reactor.h"
00006 #include "ace/os_include/os_fcntl.h"
00007 
00008 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 TAO_ECG_Simple_Mcast_EH::TAO_ECG_Simple_Mcast_EH (TAO_ECG_Dgram_Handler *recv)
00011   : receiver_ (recv)
00012 {
00013   ACE_ASSERT (this->receiver_);
00014 }
00015 
00016 TAO_ECG_Simple_Mcast_EH::~TAO_ECG_Simple_Mcast_EH (void)
00017 {
00018 }
00019 
00020 int
00021 TAO_ECG_Simple_Mcast_EH::open (const char * mcast_addr,
00022                                const ACE_TCHAR *net_if)
00023 {
00024   // Check that we haven't been closed already.
00025   if (!this->receiver_)
00026     return -1;
00027 
00028   if (mcast_addr == 0)
00029     return -1;
00030 
00031   ACE_INET_Addr mcast_group;
00032   if (mcast_group.set (mcast_addr) != 0)
00033     ACE_ERROR_RETURN ((LM_ERROR,
00034                        "Unable to open mcast handler: "
00035                        "error using specified address %s "
00036                        "in ACE_INET.set ().\n",
00037                        mcast_addr),
00038                       -1);
00039 
00040   if (this->dgram_.subscribe (mcast_group, 1, net_if) != 0)
00041     ACE_ERROR_RETURN ((LM_ERROR,
00042                       "Unable to open mcast handler: error "
00043                       "subscribing to %s\n",
00044                        mcast_addr),
00045                       -1);
00046 
00047   (void) dgram_.enable(ACE_NONBLOCK);
00048 
00049   if (!this->reactor ()
00050       || 0 != this->reactor ()->register_handler (this->dgram_.get_handle (),
00051                                                   this,
00052                                                   ACE_Event_Handler::READ_MASK))
00053     {
00054       this->dgram_.close ();
00055       ACE_ERROR_RETURN ((LM_ERROR,
00056                          "Cannot register handler with reactor.\n"),
00057                         -1);
00058     }
00059 
00060   return 0;
00061 }
00062 
00063 int
00064 TAO_ECG_Simple_Mcast_EH::shutdown (void)
00065 {
00066   // Already shut down.
00067   if (!this->receiver_)
00068     return -1;
00069 
00070   int result = 0;
00071   if (this->reactor ())
00072     {
00073       result = this->reactor ()->remove_handler (this->dgram_.get_handle (),
00074                                                  ACE_Event_Handler::READ_MASK);
00075     }
00076   if (result != 0)
00077     ACE_ERROR ((LM_ERROR,
00078                 "Unable to deregister handler from reactor "
00079                 "on shutdown.\n"));
00080 
00081   result = this->dgram_.close ();
00082   if (result != 0)
00083     ACE_ERROR ((LM_ERROR,
00084                 "Unable to close mcast receiving dgram "
00085                 "on shutdown.\n"));
00086 
00087   this->receiver_ = 0;
00088 
00089   return result;
00090 }
00091 
00092 int
00093 TAO_ECG_Simple_Mcast_EH::handle_input (ACE_HANDLE /* fd */)
00094 {
00095   return this->receiver_->handle_input (this->dgram_);
00096 }
00097 
00098 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 13:11:10 2006 for TAO_RTEvent by doxygen 1.3.6