2 #include "Multicast_Manager.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/OS_NS_sys_socket.h"
7 #include "ace/OS_NS_sys_select.h"
8 #include "ace/OS_NS_netdb.h"
9 #include "ace/OS_NS_arpa_inet.h"
10 #include "ace/os_include/os_string.h"
12 // Creates and binds a UDP socket...
15 CM_Client::open (short port_number
)
17 Comm_Manager::sokfd_
= ACE_OS::socket (PF_INET
, SOCK_DGRAM
, 0);
19 if (Comm_Manager::sokfd_
== ACE_INVALID_HANDLE
)
22 ACE_OS::memset ((char *) &this->sin_
,
25 this->sin_
.sin_family
= AF_INET
;
26 this->sin_
.sin_port
= htons (port_number
);
32 CM_Client::receive (int timeout
)
34 FD_ZERO (&this->read_fd_
);
35 FD_SET (Comm_Manager::sokfd_
, &this->read_fd_
);
39 this->time_out_
.sec (timeout
);
40 this->time_out_
.usec (0);
41 this->top_
= &time_out_
;
44 while (Multicast_Manager::outstanding_hosts_remain ())
46 if (ACE_OS::select (Comm_Manager::sokfd_
+ 1,
54 int sin_len
= sizeof this->sin_
;
55 int n
= ACE_OS::recvfrom ((int)Comm_Manager::sokfd_
,
59 reinterpret_cast<sockaddr
*> (&this->sin_
),
65 if (Options::get_opt (Options::DEBUGGING
) != 0)
67 hostent
*np
= ACE_OS::gethostbyaddr ((char *) &this->sin_
.sin_addr
,
68 sizeof this->sin_
.sin_addr
,
72 "receiving from server host %s (%s)\n",
74 ACE_OS::inet_ntoa (this->sin_
.sin_addr
)));
77 if (this->demux (this->recv_packet_
, n
) < 0)
80 Multicast_Manager::checkoff_host (this->sin_
.sin_addr
);
85 for (const char *host_name
;
86 Multicast_Manager::get_next_non_responding_host (host_name
);
89 "%s did not respond\n",
97 int packet_length
= 0;
99 if (this->mux (this->send_packet_
, packet_length
) < 0)
102 // Ship off the info to all the hosts.
104 while (Multicast_Manager::get_next_host_addr (this->sin_
.sin_addr
) != 0)
106 if (Options::get_opt (Options::DEBUGGING
) != 0)
108 hostent
*np
= ACE_OS::gethostbyaddr ((char *) &this->sin_
.sin_addr
,
109 sizeof this->sin_
.sin_addr
,
112 ACE_DEBUG ((LM_DEBUG
,
113 "sending to server host %s (%s)\n",
115 ACE_OS::inet_ntoa (this->sin_
.sin_addr
)));
118 if (ACE_OS::sendto (Comm_Manager::sokfd_
,
122 reinterpret_cast<sockaddr
*> (&this->sin_
),
123 sizeof this->sin_
) < 0)
129 CM_Client::CM_Client ()
134 CM_Client::~CM_Client ()
136 if (Options::get_opt (Options::DEBUGGING
))
137 ACE_DEBUG ((LM_DEBUG
,
138 "disposing CM_Client\n"));
140 ACE_OS::closesocket ((int)Comm_Manager::sokfd_
);