1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
//=============================================================================
/**
* @file SOCK_SEQPACK_Association_Test.cpp
*
* $Id: SOCK_SEQPACK_Association_Test.cpp 93640 2011-03-24 18:36:12Z johnnyw $
*
*
* Tests the methods get_local_addrs and get_remote_addrs of class
* ACE_SOCK_SEQPACK_Association.
*
* This is not an automated "one-button" test. Rather, it prints
* some output to a log file, so that an interested human can
* inspect the output and get a vague notion of whether or not
* the methods are working properly.
*
*
* @author Edward Mulholland (emulholl@atl.lmco.com)
*/
//=============================================================================
#include "ace/SOCK_SEQPACK_Association.h"
#include "ace/SOCK_SEQPACK_Connector.h"
#include "ace/INET_Addr.h"
#include "ace/Log_Msg.h"
void dump_names(const ACE_SOCK_SEQPACK_Association& assoc);
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
int status = 0; // Innocent until proven guilty
// object that manages the connection to the server
ACE_SOCK_SEQPACK_Connector connector;
// object that manages the data xfer between the client and server
ACE_SOCK_SEQPACK_Association dataStream;
// object that represents the server's IP address and port
ACE_INET_Addr serverAddr;
if (argc < 2) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Usage: SOCK_SEQPACK_Association_Test hostname:port\n")));
status = 1;
} else if (serverAddr.set(argv[1])) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_INET_Addr::set")));
status = 1;
} else if (connector.connect (dataStream, serverAddr)) {
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("ACE_SOCK_SEQPACK_Connector::connect")));
status = 1;
} else {
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Connected to server at %s\n"),
argv[1]));
dump_names(dataStream);
}
dataStream.close();
return status;
}
void dump_names(const ACE_SOCK_SEQPACK_Association& assoc)
{
// Pre-declare for-loop index
size_t i = 0;
size_t in_out_size = 100;
ACE_INET_Addr in_out[100];
// Output char buffer
const size_t outbuf_size = 1024;
ACE_TCHAR outbuf[outbuf_size];
// Get local addresses of the association
if (assoc.get_local_addrs(in_out, in_out_size)) {
ACE_ERROR((LM_ERROR,
"%p\n",
"get_local_addrs"));
return;
}
ACE_DEBUG((LM_DEBUG, "Called get_local_addrs\n"));
// Print individual results of get_local_addrs
for (i = 0; i < in_out_size; ++i) {
if (in_out[i].addr_to_string(outbuf, outbuf_size)) {
ACE_ERROR((LM_ERROR,
"%p\n",
"addr_to_string"));
return;
}
ACE_DEBUG((LM_DEBUG,
"get_local_addrs[%i] = %s\n",
i,
outbuf));
}
// Reset in_out_size
in_out_size = 100;
// Get remote addresses of the association
if (assoc.get_remote_addrs(in_out, in_out_size)) {
ACE_ERROR((LM_ERROR,
"%p\n",
"get_remote_addrs"));
return;
}
ACE_DEBUG((LM_DEBUG, "Called get_remote_addrs\n"));
// Print individual results of get_remote_addrs
for (i = 0; i < in_out_size; ++i) {
if (in_out[i].addr_to_string(outbuf, outbuf_size)) {
ACE_ERROR((LM_ERROR,
"%p\n",
"addr_to_string"));
return;
}
ACE_DEBUG((LM_DEBUG,
"get_remote_addrs[%i] = %s\n",
i,
outbuf));
}
}
|