Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / apps / drwho / CM_Server.cpp
blob5844a915378c1fcd985df6ddf255e0f788318900
1 #include "global.h"
2 #include "Options.h"
3 #include "CM_Server.h"
4 #include "ace/ACE.h"
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...
12 int
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);
19 if (this->sokfd_ < 0)
20 return -1;
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)
31 return -1;
33 if (ACE_OS::setsockopt (this->sokfd_,
34 SOL_SOCKET,
35 SO_SNDBUF,
36 (char *) &max_packet_size,
37 sizeof max_packet_size) < 0)
38 return -1;
40 return 1;
43 int
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_,
52 this->recv_packet_,
53 UDP_PACKET_SIZE,
55 reinterpret_cast<sockaddr *> (&this->sin_),
56 (int *) &sin_len);
57 if (n == -1)
58 return -1;
60 if (Options::get_opt (Options::DEBUGGING) != 0)
61 ACE_DEBUG ((LM_DEBUG,
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)
66 return -1;
68 return 1;
71 int
72 CM_Server::send ()
74 int packet_length = 0;
76 if (this->mux (this->send_packet_,
77 packet_length) < 0)
78 return -1;
80 if (Options::get_opt (Options::DEBUGGING) != 0)
81 ACE_DEBUG ((LM_DEBUG,
82 "sending to client host %s\n",
83 ACE_OS::inet_ntoa (this->sin_.sin_addr)));
85 if (ACE_OS::sendto (this->sokfd_,
86 this->send_packet_,
87 packet_length,
89 reinterpret_cast<sockaddr *> (&this->sin_),
90 sizeof this->sin_) < 0)
91 return -1;
93 return 1;
96 CM_Server::CM_Server ()
100 CM_Server::~CM_Server ()
102 if (Options::get_opt (Options::DEBUGGING))
103 ACE_DEBUG ((LM_DEBUG,
104 "CM_Server\n"));
106 ACE_OS::closesocket (this->sokfd_);