TAO_AV_UDP_Connection_Setup Class Reference

This class is a helper for the TAO_AV_UDP_Acceptor and TAO_AV_UDP_Connector. It basically just reduces duplicate code. It takes the address of the peer in the connection, whether or not it is a multicast connection, and whether it is a connector or acceptor; and creates the local address and flow handler associated with the connection. More...

#include <UDP.h>

List of all members.

Public Types

 CONNECTOR
 ACCEPTOR
enum  ConnectionType { CONNECTOR, ACCEPTOR }
 Indicates whether this setup is for a Connector or an Acceptor. More...

Static Public Member Functions

static int setup (TAO_AV_Flow_Handler *&flow_handler, ACE_INET_Addr *inet_addr, ACE_INET_Addr *&local_addr, int is_multicast, ConnectionType ct)


Detailed Description

This class is a helper for the TAO_AV_UDP_Acceptor and TAO_AV_UDP_Connector. It basically just reduces duplicate code. It takes the address of the peer in the connection, whether or not it is a multicast connection, and whether it is a connector or acceptor; and creates the local address and flow handler associated with the connection.

Definition at line 216 of file UDP.h.


Member Enumeration Documentation

enum TAO_AV_UDP_Connection_Setup::ConnectionType

Indicates whether this setup is for a Connector or an Acceptor.

Enumerator:
CONNECTOR 
ACCEPTOR 

Definition at line 220 of file UDP.h.

00220 {CONNECTOR, ACCEPTOR};


Member Function Documentation

int TAO_AV_UDP_Connection_Setup::setup ( TAO_AV_Flow_Handler *&  flow_handler,
ACE_INET_Addr inet_addr,
ACE_INET_Addr *&  local_addr,
int  is_multicast,
ConnectionType  ct 
) [static]

Definition at line 797 of file UDP.cpp.

References ACCEPTOR, ACE_DEBUG, ACE_DEFAULT_MAX_SOCKET_BUFSIZ, ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_INET_Addr::addr_to_string(), CONNECTOR, ENOTSUP, ACE_INET_Addr::get_host_name(), ACE_SOCK::get_local_addr(), TAO_AV_UDP_MCast_Flow_Handler::get_mcast_socket(), ACE_INET_Addr::get_port_number(), TAO_AV_UDP_Flow_Handler::get_socket(), inet_addr(), IP_MULTICAST_LOOP, ACE_SOCK_Dgram_Mcast::join(), LM_DEBUG, LM_ERROR, TAO_AV_UDP_Flow_Handler::open(), ACE_OS::perror(), ACE_INET_Addr::set(), ACE_SOCK::set_option(), ACE_SOCK_Dgram_Mcast::set_option(), TAO_AV_UDP_MCast_Flow_Handler::set_peer_addr(), TAO_AV_UDP_Flow_Handler::set_remote_address(), SO_RCVBUF, SO_SNDBUF, SOL_SOCKET, and TAO_debug_level.

Referenced by TAO_AV_UDP_Connector::connect(), and TAO_AV_UDP_Acceptor::open_i().

00802 {
00803   int result;
00804 
00805   if (is_multicast)
00806     {
00807       TAO_AV_UDP_MCast_Flow_Handler *handler;
00808       ACE_NEW_RETURN (handler,
00809                       TAO_AV_UDP_MCast_Flow_Handler,
00810                       -1);
00811 
00812       flow_handler = handler;
00813 
00814       result = handler->get_mcast_socket ()->join (*inet_addr);
00815       if (result < 0)
00816         ACE_ERROR_RETURN ((LM_ERROR,"TAO_AV_UDP_MCast_connector::open failed\n"),-1);
00817 
00818       // Now disable Multicast loopback.
00819       // @@Should we make this a policy?
00820 #if defined (ACE_HAS_IP_MULTICAST)
00821       if (handler->get_mcast_socket ()->set_option (IP_MULTICAST_LOOP,
00822                                                     0) < 0)
00823         if (TAO_debug_level > 0)
00824           ACE_DEBUG ((LM_DEBUG,"TAO_AV_UDP_MCast_Acceptor::multicast loop disable failed\n"));
00825       // @@ This should also be policies.
00826 #endif /*ACE_HAS_IP_MULTICAST*/
00827 
00828       int bufsize = 80 * 1024;
00829       if (handler->get_mcast_socket ()->ACE_SOCK::set_option (SOL_SOCKET,
00830                                                               SO_RCVBUF,
00831                                                               (char *)&bufsize,
00832                                                               sizeof(bufsize)) < 0)
00833         {
00834           bufsize = 32 * 1024;
00835           if (handler->get_mcast_socket ()->ACE_SOCK::set_option (SOL_SOCKET,
00836                                                                   SO_RCVBUF,
00837                                                                   (char *)&bufsize,
00838                                                                   sizeof(bufsize)) < 0)
00839             ACE_OS::perror("SO_RCVBUF");
00840         }
00841       ACE_NEW_RETURN (local_addr,
00842                       ACE_INET_Addr ("0"),
00843                       -1);
00844 
00845       if (ct == ACCEPTOR)
00846         {
00847           result = handler->get_mcast_socket ()->get_local_addr (*local_addr);
00848           if (result < 0)
00849             ACE_ERROR_RETURN ((LM_ERROR,"TAO_AV_Dgram_Connector::open: get_local_addr failed\n"),result);
00850 
00851           local_addr->set (local_addr->get_port_number (),
00852                            local_addr->get_host_name ());
00853           handler->set_peer_addr (local_addr);
00854         }
00855     }
00856   else
00857     {
00858       if (local_addr == 0)
00859         ACE_NEW_RETURN (local_addr,
00860                         ACE_INET_Addr ("0"),
00861                         -1);
00862 
00863       TAO_AV_UDP_Flow_Handler *handler;
00864       ACE_NEW_RETURN (handler,
00865                       TAO_AV_UDP_Flow_Handler,
00866                       -1);
00867 
00868       flow_handler = handler;
00869 
00870       if (ct == ACCEPTOR)
00871         result = handler->open (*inet_addr);
00872       else
00873         result = handler->open (*local_addr);
00874       if (result < 0)
00875         ACE_ERROR_RETURN ((LM_ERROR,"handler::open failed\n"),-1);
00876 
00877       // set the socket buffer sizes to 64k.
00878       int sndbufsize = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
00879       int rcvbufsize = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
00880 
00881       if (handler->get_socket ()->set_option (SOL_SOCKET,
00882                                               SO_SNDBUF,
00883                                               (void *) &sndbufsize,
00884                                               sizeof (sndbufsize)) == -1
00885           && errno != ENOTSUP)
00886         return 0;
00887       else if (handler->get_socket ()->set_option (SOL_SOCKET,
00888                                                    SO_RCVBUF,
00889                                                    (void *) &rcvbufsize,
00890                                                    sizeof (rcvbufsize)) == -1
00891                && errno != ENOTSUP)
00892         return 0;
00893 
00894       if (ct == CONNECTOR)
00895         handler->set_remote_address  (inet_addr);
00896 
00897       result = handler->get_socket ()->get_local_addr (*local_addr);
00898 
00899       local_addr->set (local_addr->get_port_number (),
00900                local_addr->get_host_name ());
00901 
00902       char buf [BUFSIZ];
00903       local_addr->addr_to_string (buf, BUFSIZ);
00904 
00905       if (result < 0)
00906         ACE_ERROR_RETURN ((LM_ERROR,"TAO_AV_Dgram_Connector::open: get_local_addr failed\n"),result);
00907     }
00908 
00909   return 1;
00910 }


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:48:06 2010 for TAO_AV by  doxygen 1.4.7