1 #include "ace/OS_main.h"
2 #include "ace/SPIPE_Addr.h"
3 #include "ace/SPIPE_Acceptor.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "ace/OS_NS_poll.h"
7 #include "ace/OS_NS_unistd.h"
10 #if defined (ACE_HAS_STREAM_PIPES)
14 // Maximum per-process open I/O descriptors.
15 const int MAX_HANDLES
= 200;
18 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
20 ACE_SPIPE_Acceptor peer_acceptor
;
21 ACE_SPIPE_Stream new_stream
;
22 struct pollfd poll_array
[MAX_HANDLES
];
25 for (handle
= 0; handle
< MAX_HANDLES
; handle
++)
27 poll_array
[handle
].fd
= -1;
28 poll_array
[handle
].events
= POLLIN
;
34 ACE_OS::fdetach (ACE_TEXT_ALWAYS_CHAR (rendezvous
));
35 ACE_SPIPE_Addr
addr (rendezvous
);
37 ACE_HANDLE s_handle
= peer_acceptor
.open (addr
);
40 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "peer_acceptor.open"), -1);
42 poll_array
[0].fd
= s_handle
;
46 // Block waiting for client I/O events (handle interrupts).
47 while (ACE_OS::poll (poll_array
, width
) == -1 && errno
== EINTR
)
50 // Handle pending logging messages first (s_handle + 1 is
51 // guaranteed to be lowest client descriptor).
53 for (handle
= s_handle
+ 1; handle
< width
; handle
++)
54 if (ACE_BIT_ENABLED (poll_array
[handle
].revents
, POLLIN
)
55 || ACE_BIT_ENABLED (poll_array
[handle
].revents
, POLLHUP
))
58 ssize_t n
= ACE_OS::read (handle
, buf
, sizeof buf
);
60 // recv will not block in this case!
62 ACE_DEBUG ((LM_DEBUG
, "%p\n", "read failed"));
65 // Handle client connection shutdown.
66 if (ACE_OS::close (poll_array
[handle
].fd
) == -1)
67 ACE_DEBUG ((LM_DEBUG
, "%p\n", "close"));
68 poll_array
[handle
].fd
= -1;
70 if (handle
+ 1 == width
)
72 while (poll_array
[handle
].fd
== -1)
78 ACE_DEBUG ((LM_DEBUG
, "%*s\n", n
, buf
));
81 if (ACE_BIT_ENABLED (poll_array
[0].revents
, POLLIN
))
83 if (peer_acceptor
.accept (new_stream
) == -1)
84 ACE_DEBUG ((LM_DEBUG
, "%p\n", "accept failed"));
86 ACE_SPIPE_Addr client
;
87 ACE_HANDLE n_handle
= new_stream
.get_handle ();
89 if (new_stream
.get_remote_addr (client
) == -1)
90 ACE_DEBUG ((LM_DEBUG
, "%p\n",
91 "get_remote_addr failed"));
94 "n_handle = %d, uid = %d, gid = %d\n",
99 int arg
= RMSGN
| RPROTDAT
;
101 if (ACE_OS::ioctl (n_handle
,
102 I_SRDOPT
, (void *) arg
) == -1)
103 ACE_DEBUG ((LM_DEBUG
, "%p\n", "ioctl failed"));
105 poll_array
[n_handle
].fd
= n_handle
;
107 if (n_handle
>= width
)
108 width
= n_handle
+ 1;
112 ACE_NOTREACHED (return 0;)
116 int ACE_TMAIN (int, ACE_TCHAR
*[])
118 ACE_OS::fprintf (stderr
, "This feature is not supported\n");
121 #endif /* ACE_HAS_STREAM_PIPES */