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_time.h"
6 #include "ace/OS_NS_unistd.h"
9 Handle_L_Stream::~Handle_L_Stream ()
14 Handle_L_Stream::Handle_L_Stream ()
16 if (Handle_L_Stream::login_name == 0) {
17 #if !defined(ACE_LACKS_CUSERID)
18 Handle_L_Stream::login_name = ACE_OS::cuserid (Handle_L_Stream::login);
20 Handle_L_Stream::login[0] = '.';
21 Handle_L_Stream::login[1] = '\0';
22 Handle_L_Stream::login_name = Handle_L_Stream::login;
28 Handle_L_Stream::open (const ACE_UNIX_Addr &suas,
31 if (this->ACE_LSOCK_Acceptor::open (suas) == -1)
33 else if (async && this->ACE_LSOCK_Acceptor::enable (ACE_SIGIO) == -1)
40 Handle_L_Stream::info (ACE_TCHAR **strp, size_t length) const
42 ACE_TCHAR buf[BUFSIZ];
45 if (this->get_local_addr (sa) == -1)
48 ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ()));
49 ACE_OS::strcat (buf, ACE_TEXT (" # tests local ACE_Stream\n"));
51 if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
54 ACE_OS::strncpy (*strp, buf, length);
55 return ACE_OS::strlen (buf);
59 Handle_L_Stream::init (int argc, ACE_TCHAR *argv[])
62 const ACE_TCHAR *r = Handle_L_Stream::DEFAULT_RENDEZVOUS;
63 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0);
65 for (int c; (c = get_opt ()) != -1; )
69 r = get_opt.opt_arg ();
75 ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN);
76 ACE_OS::unlink (this->rendezvous);
77 sus.set (this->rendezvous);
79 if (this->open (sus) == -1)
80 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);
81 else if (ACE_Reactor::instance ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK) == -1)
82 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
83 ACE_TEXT ("registering service with ACE_Reactor")), -1);
88 Handle_L_Stream::fini ()
90 return ACE_Reactor::instance ()->remove_handler
91 (this, ACE_Event_Handler::ACCEPT_MASK);
95 Handle_L_Stream::get_handle () const
97 return ACE_LSOCK_Acceptor::get_handle ();
101 Handle_L_Stream::handle_input (ACE_HANDLE)
103 ACE_LSOCK_Stream new_local_stream;
105 ACE_HANDLE handle = ACE_INVALID_HANDLE;
108 if (this->accept (new_local_stream, &sa) == -1)
110 else if (new_local_stream.recv_handle (handle) == -1)
114 ACE_TEXT ("received file descriptor %d on ACE_Stream %s\n"),
115 handle, sa.get_path_name ()));
117 ACE_OS::puts ("----------------------------------------");
121 ssize_t n = ACE_OS::read (handle, buf, sizeof buf);
126 ACE_OS::write (ACE_STDOUT, buf, n);
129 ACE_OS::puts ("----------------------------------------");
131 time_t t = ACE_OS::time (0L);
132 ACE_TCHAR *cs = ACE_OS::ctime (&t);
134 if (new_local_stream.send (4,
135 Handle_L_Stream::login_name,
136 ACE_OS::strlen (Handle_L_Stream::login_name),
137 ACE_TEXT_ALWAYS_CHAR (cs),
138 ACE_OS::strlen (cs)) == -1)
140 else if (ACE_OS::close (handle) == -1)
142 else if (new_local_stream.close () == -1)
149 Handle_L_Stream::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
151 this->ACE_LSOCK_Acceptor::close ();
152 return ACE_OS::unlink (this->rendezvous);