Merge pull request #2254 from esohns/fstat_size_64_bits
[ACE_TAO.git] / ACE / examples / Service_Configurator / IPC-tests / server / Handle_L_Pipe.inl
blob34cca37478b76c88181905b71faa4f3c46c96cd8
1 /* -*- C++ -*- */
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"
7 ACE_INLINE
8 Handle_L_Pipe::~Handle_L_Pipe ()
12 ACE_INLINE
13 Handle_L_Pipe::Handle_L_Pipe ()
17 ACE_INLINE int
18 Handle_L_Pipe::open (const ACE_UNIX_Addr &suap, int async)
20   if (this->ACE_LSOCK_Acceptor::open (suap) == -1)
21     return -1;
22   else if (async && this->ACE_LSOCK_Acceptor::enable (ACE_SIGIO) == -1)
23     return -1;
24   else
25     return 0;
28 ACE_INLINE int
29 Handle_L_Pipe::info (ACE_TCHAR **strp, size_t length) const
31   ACE_TCHAR buf[BUFSIZ];
32   ACE_UNIX_Addr sa;
34   if (ACE_LSOCK_Acceptor::get_local_addr (sa) == -1)
35     return -1;
37   ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ()));
38   ACE_OS::strcat (buf, ACE_TEXT (" # tests local pipe\n"));
40   if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0)
41     return -1;
42   else
43     ACE_OS::strncpy (*strp, buf, length);
44   return ACE_OS::strlen (buf);
47 ACE_INLINE int
48 Handle_L_Pipe::init (int argc, ACE_TCHAR *argv[])
50   ACE_UNIX_Addr sup;
51   const ACE_TCHAR *r = Handle_L_Pipe::DEFAULT_RENDEZVOUS;
52   ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0);
54   for (int c; (c = get_opt ()) != -1; )
55     switch (c)
56       {
57       case 'r':
58         r = get_opt.opt_arg ();
59         break;
60       default:
61         break;
62       }
64   ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN);
65   ACE_OS::unlink (this->rendezvous);
66   sup.set (this->rendezvous);
67   if (this->open (sup) == -1)
68     ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1);
69   else if (ACE_Reactor::instance ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK) == -1)
70     ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
71                        ACE_TEXT ("registering service with ACE_Reactor")), -1);
72   return 0;
75 ACE_INLINE int
76 Handle_L_Pipe::fini ()
78   return ACE_Reactor::instance ()->remove_handler
79     (this, ACE_Event_Handler::ACCEPT_MASK);
82 ACE_INLINE int
83 Handle_L_Pipe::get_handle () const
85   return ACE_LSOCK_Acceptor::get_handle ();
88 ACE_INLINE int
89 Handle_L_Pipe::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
91   this->ACE_LSOCK_Acceptor::close ();
92   return ACE_OS::unlink (this->rendezvous);