Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / examples / Naming / test_open.cpp
blobcdaf3323ca445201589c91b4ae9473f08b10b246
1 #include "ace/OS_main.h"
2 #include "ace/Naming_Context.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_unistd.h"
7 int
8 ACE_TMAIN (int argc, ACE_TCHAR **argv)
10 const ACE_TCHAR *host = argc > 1 ? argv[1] : ACE_TEXT("-hlocalhost");
11 const ACE_TCHAR *port = argc > 2 ? argv[2] : ACE_TEXT("-p20012");
13 ACE_STATIC_SVC_REGISTER(ACE_Naming_Context);
15 ACE_Naming_Context ns;
16 ACE_Name_Options *name_options = ns.name_options ();
18 const ACE_TCHAR *m_argv[] =
20 ACE_TEXT("MyName"),
21 ACE_TEXT("-cNET_LOCAL"),
22 host,
23 port,
26 int m_argc =
27 sizeof (m_argv) / sizeof (ACE_TCHAR *) -1;
29 name_options->parse_args (m_argc,
30 (ACE_TCHAR **) m_argv);
32 int result = ns.open (ACE_Naming_Context::NET_LOCAL);
33 ACE_DEBUG ((LM_DEBUG,
34 "ACE_Naming_Context::open returned %d\n",
35 result));
36 if (result != 0)
37 return result;
38 else
40 char key[128];
41 char val[32];
42 char type[2];
44 type[0] = '-';
45 type[1] = '\0';
47 int i = 0;
49 for (int l = 1; l <= 1000 ; l++)
51 ACE_OS::sprintf (key,
52 "K_%05d_%05d",
53 (int) ACE_OS::getpid (),
54 l);
55 ACE_OS::sprintf (val,
56 "Val%05d",
57 l);
58 i = ns.bind (key,
59 val,
60 type);
61 ACE_DEBUG ((LM_DEBUG,
62 "%d: bind of %s: %d\n",
63 ACE_OS::getpid (),
64 key,
65 i));
67 if (i != 0)
68 return -1;
71 result = ns.close ();
72 ACE_DEBUG ((LM_DEBUG,
73 "ACE_Naming_Context::close returned %d\n",
74 result));
77 return result;