1
/* $Id: test_ncbi_service_connector.c,v 6.15 2001/09/24 20:36:22 lavr Exp $
2
* ===========================================================================
5
* National Center for Biotechnology Information
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government have not placed any restriction on its use or reproduction.
14
* Although all reasonable efforts have been taken to ensure the accuracy
15
* and reliability of the software and data, the NLM and the U.S.
16
* Government do not and cannot warrant the performance or results that
17
* may be obtained by using this software or data. The NLM and the U.S.
18
* Government disclaim all warranties, express or implied, including
19
* warranties of performance, merchantability or fitness for any particular
22
* Please cite the author in any work or product based on this material.
24
* ===========================================================================
26
* Author: Anton Lavrentiev
29
* Standard test for the service connector
31
* --------------------------------------------------------------------------
32
* $Log: test_ncbi_service_connector.c,v $
33
* Revision 6.15 2001/09/24 20:36:22 lavr
34
* Adjusted parameters in SERVICE_CreateConnectorEx()
36
* Revision 6.14 2001/06/11 22:17:28 lavr
37
* Wait-for-reading timeout made finite
39
* Revision 6.13 2001/06/07 17:53:47 lavr
40
* Persistent reading from test connection
42
* Revision 6.12 2001/06/01 16:19:10 lavr
43
* Added (ifdef'ed out) an internal test connection to service ID1
45
* Revision 6.11 2001/05/11 16:05:41 lavr
46
* Change log message corrected
48
* Revision 6.10 2001/05/11 15:38:01 lavr
49
* Print connector type along with read data
51
* Revision 6.9 2001/04/24 21:42:43 lavr
52
* Brushed code to use CORE_LOG facility only.
54
* Revision 6.8 2001/01/25 17:13:22 lavr
55
* Added: close/free everything on program exit: useful to check memory leaks
57
* Revision 6.7 2001/01/23 23:22:34 lavr
58
* debug_printout was given an enum value (instead of "boolean" 1)
60
* Revision 6.6 2001/01/09 15:35:20 lavr
61
* Removed header <unistd.h>, unknown on WinNT
63
* Revision 6.5 2001/01/08 23:13:19 lavr
66
* Revision 6.4 2001/01/08 22:42:42 lavr
67
* Further development of the test-suite
69
* Revision 6.3 2001/01/03 22:40:24 lavr
72
* Revision 6.2 2000/12/29 18:25:27 lavr
73
* More tests added (still not yet complete).
75
* Revision 6.1 2000/10/20 17:31:07 lavr
78
* ==========================================================================
85
#include "../ncbi_priv.h"
86
#include <connect/ncbi_util.h>
87
#include <connect/ncbi_service_connector.h>
93
int main(int argc, const char* argv[])
95
static char obuf[128] = "UUUUUZZZZZZUUUUUUZUZUZZUZUZUZUZUZ\n";
96
const char* service = argc > 1 ? argv[1] : "bounce";
97
const char* host = argc > 2 ? argv[2] : "ray";
105
CORE_SetLOGFILE(stderr, 0/*false*/);
107
info = ConnNetInfo_Create(service);
108
strcpy(info->host, host);
110
strncpy(obuf, argv[3], sizeof(obuf) - 2);
111
obuf[sizeof(obuf) - 2] = 0;
112
obuf[n = strlen(obuf)] = '\n';
116
connector = SERVICE_CreateConnectorEx(service, fSERV_Any, info, 0);
117
ConnNetInfo_Destroy(info);
120
CORE_LOG(eLOG_Fatal, "Failed to create service connector");
122
if (CONN_Create(connector, &conn) != eIO_Success)
123
CORE_LOG(eLOG_Fatal, "Failed to create connection");
126
timeout.usec = 123456;
128
CONN_SetTimeout(conn, eIO_ReadWrite, &timeout);
130
if (CONN_Write(conn, obuf, strlen(obuf), &n) != eIO_Success ||
133
CORE_LOG(eLOG_Fatal, "Error writing to connection");
136
if (CONN_Wait(conn, eIO_Read, &timeout) != eIO_Success) {
138
CORE_LOG(eLOG_Fatal, "Error waiting for reading");
141
if (CONN_Read(conn, ibuf, n, &n, eIO_Persist) != eIO_Success) {
143
CORE_LOG(n ? eLOG_Error : eLOG_Fatal, "Error reading from connection");
147
("%d bytes read from service (%s):\n%.*s",
148
(int)n, CONN_GetType(conn), (int)n, ibuf));
152
CORE_LOG(eLOG_Note, "Trying ID1 service");
154
info = ConnNetInfo_Create(service);
155
connector = SERVICE_CreateConnectorEx("ID1", fSERV_Any, info);
156
ConnNetInfo_Destroy(info);
159
CORE_LOG(eLOG_Fatal, "Service ID1 not available");
161
if (CONN_Create(connector, &conn) != eIO_Success)
162
CORE_LOG(eLOG_Fatal, "Failed to create connection");
164
if (CONN_Write(conn, "\xA4\x80\x02\x01\x02\x00\x00", 7, &n) !=
165
eIO_Success || n != 7) {
167
CORE_LOG(eLOG_Fatal, "Error writing to service ID1");
170
if (CONN_Read(conn, ibuf, sizeof(ibuf), &n, eIO_Plain) != eIO_Success) {
172
CORE_LOG(eLOG_Fatal, "Error reading from service ID1");
175
CORE_LOGF(eLOG_Note, ("%d bytes read from service ID1", n));