Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / apps / drwho / CM_Client.cpp
blobde5551c06cf3d4dfd3dbd9d4d9e88f7b7205547c
1 #include "Options.h"
2 #include "Multicast_Manager.h"
3 #include "CM_Client.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...
14 int
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)
20 return -1;
22 ACE_OS::memset ((char *) &this->sin_,
24 sizeof this->sin_);
25 this->sin_.sin_family = AF_INET;
26 this->sin_.sin_port = htons (port_number);
28 return 1;
31 int
32 CM_Client::receive (int timeout)
34 FD_ZERO (&this->read_fd_);
35 FD_SET (Comm_Manager::sokfd_, &this->read_fd_);
37 if (timeout > 0)
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,
47 &this->read_fd_,
50 this->top_) <= 0)
51 break;
52 else
54 int sin_len = sizeof this->sin_;
55 int n = ACE_OS::recvfrom ((int)Comm_Manager::sokfd_,
56 this->recv_packet_,
57 UDP_PACKET_SIZE,
59 reinterpret_cast<sockaddr *> (&this->sin_),
60 &sin_len);
61 if (n < 0)
62 return -1;
63 else
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,
69 AF_INET);
71 ACE_DEBUG ((LM_DEBUG,
72 "receiving from server host %s (%s)\n",
73 np->h_name,
74 ACE_OS::inet_ntoa (this->sin_.sin_addr)));
77 if (this->demux (this->recv_packet_, n) < 0)
78 return -1;
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);
88 ACE_DEBUG ((LM_DEBUG,
89 "%s did not respond\n",
90 host_name));
91 return 1;
94 int
95 CM_Client::send ()
97 int packet_length = 0;
99 if (this->mux (this->send_packet_, packet_length) < 0)
100 return -1;
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,
110 AF_INET);
112 ACE_DEBUG ((LM_DEBUG,
113 "sending to server host %s (%s)\n",
114 np->h_name,
115 ACE_OS::inet_ntoa (this->sin_.sin_addr)));
118 if (ACE_OS::sendto (Comm_Manager::sokfd_,
119 this->send_packet_,
120 packet_length,
122 reinterpret_cast<sockaddr *> (&this->sin_),
123 sizeof this->sin_) < 0)
124 return -1;
126 return 1;
129 CM_Client::CM_Client ()
130 : top_ (0)
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_);