2 //=============================================================================
6 * Simple client application to illustrate the use of the ACE_Blob class
8 * It reads "length" number of bytes, after skipping offset "offset"
9 * from hostname, port and filename as specified. (if -r specified)
11 * It writes "length" number of bytes, after skipping offset "offset"
12 * to hostname, port and filename as specified (if -w specified)
14 * @author Prashant Jain and Sumedh Mungee
16 //=============================================================================
20 #include "ace/OS_main.h"
21 #include "ace/OS_NS_fcntl.h"
22 #include "ace/OS_NS_unistd.h"
25 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
27 // Options is a singleton
28 Options
*options
= Options::instance ();
29 options
->parse_args (argc
, argv
);
31 // Explain what is going to happen
34 ACE_TEXT ("hostname = %C, port = %d, filename = %s, ")
35 ACE_TEXT ("length = %d, offset = %d, operation = %c\n"),
41 options
->operation_
));
46 // User requested a read
47 if (options
->operation_
== 'r')
49 ACE_Message_Block
mb (0, options
->length_
);
52 if (blob
.open (options
->filename_
,
54 options
->port_
) == -1)
55 ACE_ERROR_RETURN ((LM_ERROR
,
57 ACE_TEXT ("open error")),
61 if (blob
.read (&mb
, options
->length_
, options
->offset_
) == -1)
62 ACE_ERROR_RETURN ((LM_ERROR
,
64 ACE_TEXT ("read error")),
68 if (ACE_OS::write (ACE_STDOUT
, mb
.rd_ptr(), mb
.length()) == -1)
69 ACE_ERROR_RETURN ((LM_ERROR
,
71 ACE_TEXT ("write error")),
76 int total
= options
->length_
+ options
->offset_
;
77 ACE_Message_Block
mb (total
);
79 // Open the file to be sent
80 ACE_HANDLE h
= ACE_OS::open (options
->filename_
, O_RDONLY
);
81 if (h
== ACE_INVALID_HANDLE
)
82 ACE_ERROR_RETURN ((LM_ERROR
,
84 ACE_TEXT ("file open error")),
88 if (blob
.open (options
->filename_
, options
->hostname_
, options
->port_
) == -1)
89 ACE_ERROR_RETURN ((LM_ERROR
,
91 ACE_TEXT ("connection open error")),
95 if (ACE_OS::read (h
, mb
.wr_ptr (), total
) != total
)
96 ACE_ERROR_RETURN ((LM_ERROR
,
98 ACE_TEXT ("file read error")),
105 mb
.wr_ptr (mb
.size ());
108 if (blob
.write (&mb
, options
->length_
, options
->offset_
) == -1)
109 ACE_ERROR_RETURN ((LM_ERROR
,
111 ACE_TEXT ("network write error")),