Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / IPC_SAP / FILE_SAP / client.cpp
blob1a0f4c4e8cb7437bdbb4fb94cdaac69014188c11
1 #include "ace/OS_main.h"
2 #include "ace/FILE_Addr.h"
3 #include "ace/FILE_Connector.h"
4 #include "ace/FILE_IO.h"
5 #include "ace/Truncate.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_stdio.h"
10 int
11 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
13 if (argc < 3 || argc > 3)
14 ACE_ERROR_RETURN ((LM_ERROR,
15 "usage: %s filename string\n",
16 argv[0]),
17 1);
19 ACE_TCHAR *readback = new ACE_TCHAR[ACE_OS::strlen (argv[1]) + 1];
21 ACE_FILE_Info fileinfo;
22 ACE_FILE_IO cli_file;
23 ACE_FILE_Connector con;
25 if (con.connect (cli_file,
26 ACE_FILE_Addr (argv[1]),
28 ACE_Addr::sap_any, 0,
29 O_RDWR|O_APPEND|O_CREAT,
30 ACE_DEFAULT_FILE_PERMS) == -1)
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "%p\n to %s",
33 "connect",
34 argv[1]),
35 -1);
37 ssize_t len =
38 ACE_Utils::truncate_cast<ssize_t> (ACE_OS::strlen (argv[2]) + 1);
40 if (cli_file.send (argv[2], len) != len)
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "%p\n",
43 "send"),
44 1);
46 if (cli_file.get_info (&fileinfo) == -1)
47 ACE_ERROR_RETURN ((LM_ERROR,
48 "%p\n",
49 "get_info"),
50 1);
51 else
52 ACE_OS::printf ("fileinfo : mode = %o\nno of links = %lu\nsize = %lu\n",
53 (u_int) fileinfo.mode_ & 0777,
54 static_cast<u_long > (fileinfo.nlink_),
55 (u_long) fileinfo.size_);
57 ACE_OFF_T fpos = cli_file.tell ();
59 if (fpos == -1)
60 ACE_ERROR_RETURN ((LM_ERROR,
61 "%p\n",
62 "tell"),
63 1);
64 else
65 ACE_OS::printf ("current filepointer is at %ld\n",
66 (long int) fpos);
68 if (cli_file.seek (0,
69 SEEK_SET) == -1)
70 ACE_ERROR_RETURN ((LM_ERROR,
71 "%p\n",
72 "seek"),
73 1);
74 if (cli_file.recv (readback, len) != len)
75 ACE_ERROR_RETURN ((LM_ERROR,
76 "%p\n",
77 "recv"),
78 1);
80 ACE_OS::printf ("read back :%s\n",
81 ACE_TEXT_ALWAYS_CHAR (readback));
83 if (cli_file.close () == -1)
84 ACE_ERROR_RETURN ((LM_ERROR,
85 "%p\n",
86 "close"),
87 1);
88 return 0;