3 #include "ace/SPIPE_Stream.h"
5 #if defined (ACE_HAS_STREAM_PIPES)
7 #include "ace/Reactor.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/OS_NS_stdio.h"
10 #include "ace/OS_NS_unistd.h"
11 #include "ace/OS_NS_string.h"
15 Handle_L_SPIPE::Handle_L_SPIPE ()
20 Handle_L_SPIPE::open (const ACE_SPIPE_Addr &rendezvous_spipe)
22 if (this->ACE_SPIPE_Acceptor::open (rendezvous_spipe) == -1)
29 Handle_L_SPIPE::info (ACE_TCHAR **strp, size_t length) const
31 ACE_TCHAR buf[BUFSIZ];
34 if (ACE_SPIPE_Acceptor::get_local_addr (sa) == -1)
37 ACE_OS::strcpy (buf, sa.get_path_name ());
38 ACE_OS::strcat (buf, ACE_TEXT (" # tests local STREAM pipe\n"));
40 if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
43 ACE_OS::strncpy (*strp, buf, length);
44 return ACE_OS::strlen (buf);
48 Handle_L_SPIPE::init (int argc, ACE_TCHAR *argv[])
51 const ACE_TCHAR *rendezvous = Handle_L_SPIPE::DEFAULT_RENDEZVOUS;
52 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0);
54 for (int c; (c = get_opt ()) != -1; )
58 rendezvous = get_opt.opt_arg ();
64 ACE_OS::unlink (rendezvous);
65 susp.set (rendezvous);
66 if (this->open (susp) == -1)
67 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);
68 else if (ACE_Reactor::instance ()->register_handler
69 (this, ACE_Event_Handler::ACCEPT_MASK) == -1)
70 ACE_ERROR_RETURN ((LM_ERROR,
72 ACE_TEXT ("registering service with ACE_Reactor")),
78 Handle_L_SPIPE::fini ()
80 return ACE_Reactor::instance ()->remove_handler
81 (this, ACE_Event_Handler::ACCEPT_MASK);
85 Handle_L_SPIPE::get_handle () const
87 return ACE_SPIPE::get_handle();
91 Handle_L_SPIPE::handle_input (int)
93 ACE_SPIPE_Stream new_spipe;
95 ACE_Str_Buf msg (buf, 0, sizeof buf);
98 /* Accept communication requests */
99 if (this->ACE_SPIPE_Acceptor::accept (new_spipe) == -1)
105 new_spipe.get_remote_addr (sa);
108 ACE_TEXT ("accepted request from %s (gid = %d, uid = %d)\n"),
109 sa.get_path_name (), sa.group_id (), sa.user_id ()));
112 while (new_spipe.recv ((ACE_Str_Buf *) 0, &msg, &flags) >= 0)
114 ACE_OS::write (ACE_STDOUT, (const char *) msg.buf, (int) msg.len);
118 if (new_spipe.close () == -1)
124 Handle_L_SPIPE::handle_close (int, ACE_Reactor_Mask)
126 return this->ACE_SPIPE_Acceptor::remove ();
128 #endif /* ACE_HAS_STREAM_PIPES */