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_L_Dgram::Handle_L_Dgram ()
13 Handle_L_Dgram::open (const ACE_UNIX_Addr &suad, int async)
15 if (this->ACE_LSOCK_Dgram::open (suad) == -1)
17 else if (async && this->ACE_LSOCK_Dgram::enable (ACE_SIGIO) == -1)
24 Handle_L_Dgram::info (ACE_TCHAR **strp, size_t length) const
26 ACE_TCHAR buf[BUFSIZ];
29 if (this->ACE_LSOCK_Dgram::get_local_addr (sa) == -1)
32 ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ()));
33 ACE_OS::strcat (buf, ACE_TEXT (" # tests local datagram\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_L_Dgram::init (int argc, ACE_TCHAR *argv[])
46 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0);
47 const ACE_TCHAR *r = Handle_L_Dgram::DEFAULT_RENDEZVOUS;
49 for (int c; (c = get_opt ()) != -1; )
53 r = get_opt.opt_arg ();
59 ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN);
60 ACE_OS::unlink (this->rendezvous);
61 sudg.set (this->rendezvous);
62 if (this->open (sudg) == -1)
63 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);
64 else if (ACE_Reactor::instance ()->register_handler (this,
65 ACE_Event_Handler::ACCEPT_MASK) == -1)
66 ACE_ERROR_RETURN ((LM_ERROR,
68 ACE_TEXT ("registering service with ACE_Reactor")),
74 Handle_L_Dgram::fini ()
76 return ACE_Reactor::instance ()->remove_handler (this, ACE_Event_Handler::ACCEPT_MASK);
80 Handle_L_Dgram::get_handle () const
82 return this->ACE_LSOCK_Dgram::get_handle ();
86 Handle_L_Dgram::handle_input (int)
89 char buf[8 * 1024]; /* 8 k buffer */
92 if ((n = this->recv (buf, sizeof buf, sa)) == -1)
95 ACE_DEBUG ((LM_INFO, ACE_TEXT ("received datagram from %s\n"),
96 sa.get_path_name ()));
98 ACE_OS::puts ("----------------------------------------");
99 ACE_OS::write (ACE_STDOUT, buf, n);
101 if (buf[n - 1] != '\n')
104 ACE_OS::puts ("----------------------------------------");
110 Handle_L_Dgram::handle_close (int, ACE_Reactor_Mask)
112 this->ACE_LSOCK_Dgram::close ();
113 return ACE_OS::unlink (this->rendezvous);