1 #include "ace/Log_Msg.h"
2 #include "ace/Get_Opt.h"
4 #include "ace/HTBP/HTBP_Session.h"
5 #include "ace/HTBP/HTBP_Stream.h"
6 #include "ace/HTBP/HTBP_Addr.h"
8 #include "ace/SOCK_Acceptor.h"
9 #include "ace/SOCK_Stream.h"
10 #include "ace/OS_NS_stdio.h"
11 #include "ace/OS_NS_sys_socket.h"
12 #include "ace/os_include/os_netdb.h"
14 const size_t Send_Size
= 4*1024;
15 const size_t Loops
= 10;
16 const size_t Total_Size
= Send_Size
* Loops
;
18 const ACE_TCHAR
*notifier_file
= 0;
21 parse_args (int argc
, ACE_TCHAR
*argv
[])
23 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:p:"));
26 while ((c
= get_opts ()) != -1)
30 notifier_file
= get_opts
.opt_arg();
33 port
= static_cast<unsigned>(ACE_OS::atoi (get_opts
.opt_arg()));
37 ACE_ERROR_RETURN ((LM_ERROR
,
44 // Indicates successful parsing of the command line
49 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
53 ACE_OS::socket_init (ACE_WSOCK_VERSION
);
55 if (parse_args (argc
, argv
) != 0)
58 ACE_TCHAR host
[MAXHOSTNAMELEN
+1];
59 if (ACE_OS::hostname (host
,MAXHOSTNAMELEN
) != 0)
60 ACE_ERROR_RETURN ((LM_ERROR
,
61 ACE_TEXT ("(%P|%t) Server failure: %p\n"),
62 ACE_TEXT ("hostname")),
65 ACE_INET_Addr
local (port
, host
);
66 ACE_SOCK_Stream sock
[2];
67 ACE::HTBP::Channel
*channels
[2];
68 ACE_SOCK_Acceptor
acc(local
,1);
70 ACE_TEXT("(%P|%t) Server: ")
71 ACE_TEXT("server is ready\n")));
73 if (notifier_file
!= 0)
75 FILE *f
= ACE_OS::fopen (notifier_file
,ACE_TEXT("w+"));
76 const char *msg
= "server ready";
77 ACE_OS::fwrite (msg
,ACE_OS::strlen(msg
),1,f
);
82 channels
[0] = new ACE::HTBP::Channel (sock
[0]);
84 ACE_TEXT("(%P|%t) Server: ")
85 ACE_TEXT("Got sock[0], handle = %d\n"),
86 sock
[0].get_handle()));
88 channels
[1] = new ACE::HTBP::Channel(sock
[1]);
90 ACE_TEXT("(%P|%t) Server: ")
91 ACE_TEXT("Got sock[1], handle = %d\n"),
92 sock
[1].get_handle()));
94 while ((res
= channels
[0]->pre_recv()) != 0)
97 ACE_TEXT("(%P|%t) Server: ")
98 ACE_TEXT("res = %d. waiting 1 sec. %p\n"),
100 ACE_TEXT("stream.pre_recv()")));
104 ACE_DEBUG ((LM_DEBUG
,
105 ACE_TEXT("(%P|%t) Server: ")
106 ACE_TEXT("Read from channel2\n")));
107 while ((res
= channels
[1]->pre_recv()) != 0)
109 ACE_DEBUG ((LM_DEBUG
,
110 ACE_TEXT("(%P|%t) Server: ")
111 ACE_TEXT("res = %d, waiting 1 sec. %p\n"),
113 ACE_TEXT("stream2.pre_recv()")));
117 ACE::HTBP::Session
*session
= channels
[0]->session();
118 ACE::HTBP::Stream
stream (session
);
120 ACE_DEBUG ((LM_DEBUG
,
121 ACE_TEXT("(%P|%t) Server: ")
122 ACE_TEXT("using streams %d, %d. Got session = %x\n"),
123 sock
[0].get_handle(),sock
[1].get_handle(),session
));
126 ssize_t total_recv
= 0;
131 got
= stream
.recv (buffer
, sizeof (buffer
));
132 ACE_DEBUG ((LM_DEBUG
,
133 ACE_TEXT("(%P|%t) Server: ")
134 ACE_TEXT("got = %b\n"), got
));
141 ACE_DEBUG ((LM_DEBUG
,
142 ACE_TEXT("(%P|%t) Server: ")
143 ACE_TEXT("received %b\n"),total_recv
));
146 ACE_OS::strcpy (buffer
,"I hear you !");
147 ssize_t n
= stream
.send (buffer
, ACE_OS::strlen (buffer
)+1);
149 ACE_ERROR_RETURN ((LM_ERROR
,
150 ACE_TEXT("(%P|%t) Server: ")
152 ACE_TEXT("stream.send")),-1);
154 ACE_DEBUG ((LM_DEBUG
,
155 ACE_TEXT("(%P|%t) Server: ")
156 ACE_TEXT("send returned %b\n"),
159 ACE_OS::sleep(1); // prevent test failure on windows when the connection
161 ACE_DEBUG ((LM_DEBUG
,
162 ACE_TEXT("(%P|%t) Server: ")
163 ACE_TEXT("deleting channels[1]\n")));
165 ACE_DEBUG ((LM_DEBUG
,
166 ACE_TEXT("(%P|%t) Server: ")
167 ACE_TEXT("deleting channels[0]\n")));