5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_sys_socket.h"
8 #include "ace/OS_NS_arpa_inet.h"
10 // Creates and binds a UDP socket...
13 CM_Server::open (short port_number
)
15 int max_packet_size
= UDP_PACKET_SIZE
;
17 this->sokfd_
= ACE_OS::socket (PF_INET
, SOCK_DGRAM
, 0);
22 ACE_OS::memset (&this->sin_
, 0, sizeof this->sin_
);
23 this->sin_
.sin_family
= AF_INET
;
24 this->sin_
.sin_port
= htons (port_number
);
25 this->sin_
.sin_addr
.s_addr
= INADDR_ANY
;
27 // This call fails if an rflo daemon is already running.
28 if (ACE_OS::bind (this->sokfd_
,
29 reinterpret_cast<sockaddr
*> (&this->sin_
),
30 sizeof this->sin_
) < 0)
33 if (ACE_OS::setsockopt (this->sokfd_
,
36 (char *) &max_packet_size
,
37 sizeof max_packet_size
) < 0)
44 CM_Server::receive (int)
46 int sin_len
= sizeof this->sin_
;
48 if (Options::get_opt (Options::DEBUGGING
) != 0)
49 ACE_DEBUG ((LM_DEBUG
, "waiting for client to send...\n"));
51 int n
= ACE_OS::recvfrom (this->sokfd_
,
55 reinterpret_cast<sockaddr
*> (&this->sin_
),
60 if (Options::get_opt (Options::DEBUGGING
) != 0)
62 "receiving from client host %s\n",
63 ACE_OS::inet_ntoa (this->sin_
.sin_addr
)));
65 if (this->demux (this->recv_packet_
, n
) < 0)
74 int packet_length
= 0;
76 if (this->mux (this->send_packet_
,
80 if (Options::get_opt (Options::DEBUGGING
) != 0)
82 "sending to client host %s\n",
83 ACE_OS::inet_ntoa (this->sin_
.sin_addr
)));
85 if (ACE_OS::sendto (this->sokfd_
,
89 reinterpret_cast<sockaddr
*> (&this->sin_
),
90 sizeof this->sin_
) < 0)
96 CM_Server::CM_Server ()
100 CM_Server::~CM_Server ()
102 if (Options::get_opt (Options::DEBUGGING
))
103 ACE_DEBUG ((LM_DEBUG
,
106 ACE_OS::closesocket (this->sokfd_
);