source: yaz/trunk/fuentes/doc/comstack.html @ 255

Last change on this file since 255 was 255, checked in by mabarracus, 4 years ago

added trusty code to xenial

File size: 4.5 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 9. The COMSTACK Module</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="index.html" title="YAZ User's Guide and Reference"><link rel="prev" href="odr.debugging.html" title="4. Debugging"><link rel="next" href="comstack.introduction.html" title="2. Introduction"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 9. The COMSTACK Module</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="odr.debugging.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="comstack.introduction.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="comstack"></a>Chapter 9. The COMSTACK Module</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="comstack.html#comstack.synopsis">1. Synopsis (blocking mode)</a></span></dt><dt><span class="sect1"><a href="comstack.introduction.html">2. Introduction</a></span></dt><dt><span class="sect1"><a href="comstack.common.html">3. Common Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="comstack.common.html#comstack.managing.endpoints">3.1. Managing Endpoints</a></span></dt><dt><span class="sect2"><a href="comstack.common.html#comstack.data.exchange">3.2. Data Exchange</a></span></dt></dl></dd><dt><span class="sect1"><a href="comstack.client.html">4. Client Side</a></span></dt><dt><span class="sect1"><a href="comstack.server.html">5. Server Side</a></span></dt><dt><span class="sect1"><a href="comstack.addresses.html">6. Addresses</a></span></dt><dt><span class="sect1"><a href="comstack.ssl.html">7. SSL</a></span></dt><dt><span class="sect1"><a href="comstack.diagnostics.html">8. Diagnostics</a></span></dt><dt><span class="sect1"><a href="comstack.summary.html">9. Summary and Synopsis</a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="comstack.synopsis"></a>1. Synopsis (blocking mode)</h2></div></div></div><pre class="programlisting">
2    COMSTACK stack;
3    char *buf = 0;
4    int size = 0, length_incoming;
5    char server_address_str[] = "localhost:9999";
6    void *server_address_ip;
7    int status;
8
9    char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
10    int protocol_package_length = strlen(protocol_package);
11
12    stack = cs_create(tcpip_type, 1, PROTO_HTTP);
13    if (!stack) {
14        perror("cs_create");  /* use perror() here since we have no stack yet */
15        return -1;
16    }
17
18    server_address_ip = cs_straddr(stack, server_address_str);
19    if (!server_address_ip) {
20        fprintf(stderr, "cs_straddr: address could not be resolved\n");
21        return -1;
22    }
23
24    status = cs_connect(stack, server_address_ip);
25    if (status) {
26        fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
27        return -1;
28    }
29
30    status = cs_rcvconnect(stack);
31    if (status) {
32        fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack));
33        return -1;
34    }
35
36    status = cs_put(stack, protocol_package, protocol_package_length);
37    if (status) {
38        fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
39        return -1;
40    }
41
42    /* Now get a response */
43    length_incoming = cs_get(stack, &amp;buf, &amp;size);
44    if (!length_incoming) {
45        fprintf(stderr, "Connection closed\n");
46        return -1;
47    } else if (length_incoming &lt; 0) {
48        fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
49        return -1;
50    }
51
52    /* Print result */
53    fwrite(buf, length_incoming, 1, stdout);
54
55    /* clean up */
56    cs_close(stack);
57    if (buf)
58        xfree(buf);
59    return 0;
60
61   </pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="odr.debugging.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="comstack.introduction.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Debugging </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2. Introduction</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.