2 //=============================================================================
4 * @file Svc_Handler_Test.cpp
6 * This tests illustrates the "buffering" strategy of the
7 * <ACE_Buffered_Svc_Handler>. This test also illustrates how the
8 * <ACE_FILE_IO> classes work.
10 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
12 //=============================================================================
15 #include "test_config.h"
16 #include "ace/OS_NS_string.h"
17 #include "ace/FILE_Connector.h"
18 #include "ace/Null_Condition.h"
19 #include "ace/Null_Mutex.h"
20 #include "ace/Svc_Handler.h"
21 #include "ace/Synch_Traits.h"
23 using SVC_HANDLER
= ACE_Buffered_Svc_Handler
<ACE_FILE_IO
, ACE_NULL_SYNCH
>;
26 run_test (SVC_HANDLER
&svc_handler
,
29 // Create a whole slew of message blocks and pass them to the
31 for (size_t i
= 0; i
< iterations
; i
++)
33 ACE_Message_Block
*mb
= 0;
35 ACE_Message_Block (sizeof (ACE_TEXT("hello "))));
37 ACE_Message_Block
*cb1
= 0;
39 ACE_Message_Block (sizeof (ACE_TEXT("there\n"))));
41 ACE_Message_Block
*cb2
= 0;
43 ACE_Message_Block (sizeof (ACE_TEXT("there\n"))));
46 ACE_OS::strlen (ACE_TEXT("hello ")));
48 ACE_OS::strlen (ACE_TEXT("there ")));
51 ACE_OS::strlen (ACE_TEXT("doug\n")));
54 // Note that this is a buffered call!
55 if (svc_handler
.put (mb
) == -1)
62 ACE_TEXT ("final flush\n")));
64 // Make sure to flush everything out before we exit.
65 if (svc_handler
.flush () == -1)
72 run_main (int argc
, ACE_TCHAR
*argv
[])
74 ACE_START_TEST (ACE_TEXT ("Svc_Handler_Test"));
76 size_t max_buffer_size
= BUFSIZ
;
77 size_t iterations
= 10;
80 max_buffer_size
= ACE_OS::atoi (argv
[1]);
82 iterations
= ACE_OS::atoi (argv
[2]);
84 ACE_FILE_Connector connector
;
86 // Create a temporary filename.
88 // Open up a temp file.
89 if (connector
.connect (file_io
, ACE_sap_any_cast (ACE_FILE_Addr
&)) == -1)
90 ACE_ERROR_RETURN ((LM_ERROR
,
92 ACE_TEXT ("connect")),
94 // Find the name of the temp file
96 if (file_io
.get_local_addr (file
) == -1)
97 ACE_ERROR_RETURN ((LM_ERROR
,
99 ACE_TEXT ("get_local_addr")),
102 // Create the service handler and assign it <file_io> as its data
104 SVC_HANDLER
svc_handler (0,
109 svc_handler
.peer () = file_io
;
112 run_test (svc_handler
, iterations
);
116 // Open up the temp file.
117 if (connector
.connect (file_io
, file
) == -1)
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 ACE_TEXT ("connect failed for %p\n"),
120 file
.get_path_name ()),
122 char buf
[ACE_MAXLOGMSGLEN
+ 1];
123 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::VERBOSE_LITE
);
126 file_io
.get_info (info
);
127 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("file size = %d\n"), info
.size_
));
129 for (ssize_t n_bytes
; (n_bytes
= file_io
.recv (buf
, ACE_MAXLOGMSGLEN
)) > 0; )
132 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("%C"), buf
));
135 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("\n")));
139 if (file_io
.unlink () == -1)
140 ACE_ERROR_RETURN ((LM_ERROR
,
141 ACE_TEXT ("unlink failed for %p\n"),
142 file
.get_path_name ()),