1752818 Members
4055 Online
108789 Solutions
New Discussion

Cobol Sockets

 
SOLVED
Go to solution
Anonymous
Not applicable

Re: Cobol Sockets

In case anyone's interested, as a follow-up to my previous post, yes, the world of LIBCURL is available to COBOL programs...with one caveat - a C wrapper routine is apparently required. See below.

Here are the results of testing on an AlphaStation running OpenVMS 8.4 with LIBCURL 7.47 installed.

Before we begin, we must define our C compiler include logical name to handle "#include <curl.h>". Then, create an options file for the linker to reference the LIBCURL installed shareable image.

$DEFINE/PROCESS DECC$SYSTEM_INCLUDE GNV$CURL_INCLUDE

$EDIT LIBCURL.OPT
GNV$LIBCURL/SHAREABLE
<CTRL-Z>

First test - can we call one of the LIBCURL functions from C? Keep it simple; curl_version returns a pointer to an informational, null-delimited string. If this works, we have the ability to create a wrapper routine around the various LIBCURL functions.

$EDIT C2CCTEST1.C
#include <curl.h>
#include <stdio.h>

extern char *curl_version();

int main()
{
    char *verstr;

    verstr = curl_version();
    printf("Curl version: %s\n",verstr);

    return(0);
}
<CTRL-Z>

$CC C2CTEST1.C
$LINK C2CTEST1,LIBCURL/OPT
RUN C2CTEST1
Curl version: libcurl/7.47.0 OpenSSL/0.9.8h zlib/1.2.8

Second test - can we call the wrapper routine from our COBOL program? The answer is yes, but some manipulation of the LIBCURL results are necessary, as COBOL apparently cannot dereference pointers to access the data. C is exquisitely equipped to handle said dereferencing... :-) Are there better ways to pass data between two character pointer variables?

$EDIT C2C_TEST2_C.C
#include <curl.h>
#include <stdio.h>
#include <string.h>

extern char *curl_version();

int c2c_curl_version(char *ver_str_ptr)
{
    strcpy(ver_str_ptr, curl_version());

    printf("C program version    : %s\n",ver_str_ptr);

    return(0);
}
<CTRL-Z>


$EDIT C2C_TEST2_COBOL.COB
       Identification Division.
       Program-ID.    C2C_TEST2_COBOL.

       Environment Division.
       Configuration Section.
       Source-Computer. AXP.
       Object-Computer. AXP.

       Data Division.
       Working-Storage Section.
       01   General-Variables.
            03 Version-String     Pic X(100) Value Spaces.
            03 Status-Code        Pic S9(9) Comp.

       Procedure Division.
       Main-Routine.

            Call 'c2c_curl_version' Using By Reference Version-String
                                   Giving Status-Code

            Display 'COBOL program version: ' Version-String

            Exit Program
            .
<CTRL-Z>

$CC C2C_TEST2_C.C
$COBOL/ANSI C2C_TEST2_COBOL.COB
$LINK C2C_TEST2_COBOL,C2C_TEST2_C,LIBCURL/OPT
$RUN C2C_TEST2_COBOL

C program version    : libcurl/7.47.0 OpenSSL/0.9.8h zlib/1.2.8
COBOL program version: libcurl/7.47.0 OpenSSL/0.9.8h zlib/1.2.8

Yes! We are able to obtain the desired result. Of course, the more complex functions require more thought and code, but at least we know it's possible. HTH...

Anonymous
Not applicable

Re: Cobol Sockets

>> That's a pretty limited interpretation of "can handle".  ("page 245
of the COBOL Reference Manual" is not a useful reference, by the way.)

Sorry, I omitted my laboriously-typed out quote! Doesn't everyone have a copy of the gi-normous Reference Manuals handy? LOL I don't either...PDF. Here's the quote:

""You can also use an appropriate system service or the Run-Time Library routine LIB$GET_VM_64 to allocate data and store the address in the pointer variable. Because COBOL does not support dynamic allocation, there is no way to dereference the pointer and access the allocated data. However, you can pass the pointer to other languages that require a 64-bit pointer in a 64-bit address space."

> Does FORTRAN?

>> After a fashion, at least.  Without using a POINTER statement, you
can have a function/subroutine which believes that it's getting an
argument by reference, but you can pass it an address by value.

>>The POINTER statement seems to add a more natural way to deal with
pointers, but it's still too new to me for me to explain it.  (And
there's an old DEC-language-extension style, and a new Fortran-99 style.
I largely quit using Fortran before '99, so I know nothing.  My example
programs in that other topic already exceed my understanding.)

Appreciate the info. I barely scratched the surface with FORTRAN years ago, but good to know.