[Info-vax] VMS databases
Arne Vajhøj
arne at vajhoej.dk
Sat Nov 18 19:57:20 EST 2023
On 11/18/2023 7:04 PM, Craig A. Berry wrote:
> On a semi-related note, I once wrote wrappers around some of the socket
> routines so I could call them from BASIC. recv looked like this:
>
> #define BASIC_True -1
> #define BASIC_False 0
>
> int
> mytcp_recv( int *sockfd,
> struct dsc$descriptor_d *msg_dsc,
> int *bytes_read,
> struct dsc$descriptor_d *errmsg_dsc ) {
>
> *bytes_read = recv( *sockfd,
> msg_dsc->dsc$a_pointer,
> msg_dsc->dsc$w_length,
> 0 );
>
> if ( *bytes_read < 0 ) {
> /* other error reporting */
> return(BASIC_False);
> }
>
> return(BASIC_True);
> }
>
> Call it from BASIC like so:
>
> EXTERNAL LONG FUNCTION MYTCP_RECV( LONG BY REF, STRING BY DESC, LONG
> BY REF, STRING BY DESC )
> SOCKET_SUCCESS = MYTCP_RECV( SOCKET, MESSAGE, DATA_LENGTH, ERRMSG )
>
> I think it took me a bit to wise up to the fact that BASIC's descriptors
> are dynamic and needed the dsc$descriptor_d declarations.
I know that.
For moving data into the Basic string I use:
static void bstr(char *buf, int buflen, struct dsc$descriptor_d *d)
{
lib$sget1_dd(&buflen, d);
d->dsc$b_dtype = DSC$K_DTYPE_T;
memcpy(d->dsc$a_pointer, buf, buflen);
}
Some code I had on the shelf. Not sure where I got it from.
Arne
More information about the Info-vax
mailing list