2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/OS_NS_string.h"
5 #include "ace/OS_NS_unistd.h"
8 Handle_R_Dgram::Handle_R_Dgram ()
13 Handle_R_Dgram::open (const ACE_INET_Addr &r, int async)
15 if (this->ACE_SOCK_Dgram::open (r) == -1)
17 else if (async && this->ACE_SOCK_Dgram::enable (ACE_SIGIO) == -1)
24 Handle_R_Dgram::info (ACE_TCHAR **strp, size_t length) const
26 ACE_TCHAR buf[BUFSIZ];
29 if (this->get_local_addr (sa) == -1)
32 ACE_OS::sprintf (buf, ACE_TEXT ("%d/"), sa.get_port_number ());
33 ACE_OS::strcat (buf, ACE_TEXT ("udp # tests remote dgram\n"));
35 if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
38 ACE_OS::strncpy (*strp, buf, length);
39 return ACE_OS::strlen (buf);
43 Handle_R_Dgram::init (int argc, ACE_TCHAR *argv[])
45 ACE_INET_Addr sidg (Handle_R_Dgram::DEFAULT_PORT);
46 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:"), 0);
48 for (int c; (c = get_opt ()) != -1; )
52 sidg.set (ACE_OS::atoi (get_opt.opt_arg ()));
58 if (this->open (sidg) == -1)
59 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);
60 else if (ACE_Reactor::instance ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK) == -1)
61 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
62 ACE_TEXT ("registering service with ACE_Reactor")), -1);
67 Handle_R_Dgram::fini ()
69 return ACE_Reactor::instance ()->remove_handler
70 (this, ACE_Event_Handler::ACCEPT_MASK);
74 Handle_R_Dgram::get_handle () const
76 return ACE_SOCK_Dgram::get_handle ();
80 Handle_R_Dgram::handle_input (ACE_HANDLE)
83 char buf[8 * 1024]; /* 8 k buffer */
84 ssize_t n = this->recv (buf, sizeof buf, sa);
90 ACE_TEXT ("received datagram from host %C on port %d\n"),
91 sa.get_host_name (), sa.get_port_number ()));
93 ACE_OS::puts ("----------------------------------------");
94 ACE_OS::write (ACE_STDOUT, buf, n);
96 if (buf[n - 1] != '\n')
99 ACE_OS::puts ("----------------------------------------");
105 Handle_R_Dgram::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
107 return this->ACE_SOCK_Dgram::close ();