ds_get problems

I’ve been trying to write an application that uses ds/slinger to push and
pull data from an html page. I wrote a simple test application that
periodically loops and builds an shtml file that can be pulled in by my
browser. Data is sent to the shtml page perfectly.

Commands are sent from the browser using a cgi (C compiled code) that does a
ds_set. The same program that is building the shtml file also echoes the
value of this variable when it’s filling the other stuff. This part works
fine. Pushing and pulling from a single process seems to be as advertised.

The problem that I’m seeing is when I take the commanding part of this
application and stuff it in a pthread. Reading the value of the variable
returns a good status indication, until the cgi is called and the variable
gets set to something. At this point the error “Invalid Argument” is
returned by ds_get in the thread indefinitely.

What am I doing wrong? The ds_ library documentation is very limited.
Eventually, if I could poll this thing correctly, then I would like to try
using the signalling capability of ds to wake up this thread when a new
“command” is present.

Any ideas?

John

I gather from the lack of response that I didn’t describe this problem very
well. There is a “test” program that creates a shared memory variable named
“cmd”. The “cmd” variable should be valid until the test program returns.
What I have observed is not the case. My browser issues the command to the
server using the following
URL:http://servername.grc.nasa.gov/cgi-bin/command.cgi?aasd. The cgi
program connects to the variable (returns an error if it doesn’t exist) and
sets the value to whatever the CGI QUERY_STRING value is.

In the output below, the test program is receiving bad return status from
ds_get after the cgi program returns, even though the cgi program did not
create the variable.

Any ideas or comments would be greatly appreciated!

  1. The test program (see below) returns the following:
    $ ./test
    ds_get(3,cmd,UNINIT,80)
    ds_get(3,cmd,UNINIT,80)
    ds_get(3,cmd,UNINIT,80)
    ds_get: Invalid argument <— cgi program invoked
    here from browser
    ds_get: Invalid argument
    ds_get: Invalid argument
    ds_get: Invalid argument
    ds_get: Invalid argument
    ds_get: Invalid argument
    ds_get: Invalid argument
    $

  2. If I put a delay in the cgi program before it exits, I see the following:
    $ ./test
    ds_get(3,cmd,UNINIT,80)
    ds_get(3,cmd,UNINIT,80)
    ds_get(3,cmd,aasd,80) <----cgi script invoked here from browser,
    good data!
    ds_get(3,cmd,aasd,80)
    ds_get(3,cmd,aasd,80)
    ds_get(3,cmd,aasd,80)
    ds_get(3,cmd,aasd,80)
    ds_get: Invalid argument <---- cgi program exits
    ds_get: Invalid argument
    ds_get: Invalid argument
    $

Here is some source code to help clarify
//---------------------------- cgi program ----------------------------
#include <ds.h>
#include <stdio.h>
#include <errno.h>
#include “cgi-lib.h” /* include the cgi-lib.h header file /
#include “html-lib.h” /
include the html-lib.h header file */

#define BUFLEN 80

int main()
{
LIST *head;
ds_t ds_descriptor;
char *commandID = “cmd”;
char buffer[BUFLEN];
int buflen;

memset(buffer, 0, BUFLEN); // zap the character buffer

/* need to call this function at the beginning to initiate and setup out
list */
head = cgi_input_parse();

/* send the mime header to the server using our function in html-lib */
mime_header(“text/html”);

/* send break lines */
printf("\n");

if(head != NULL)
{
// echo out the query string to HTML
printf(“QUERY_STRING:%s
”, QUERY_STRING);

// register the application with the data server
ds_descriptor = ds_register();
if(ds_descriptor!=-1)
{
// display the previous value of the variable
if (ds_get(ds_descriptor, commandID, buffer, BUFLEN) == -1)
{
printf(“ds_get error:%d
”, errno);
}
else
{
printf(“ds_get(%d,”%s","%s",%d)
", ds_descriptor,
commandID, buffer, BUFLEN);

strncpy(buffer, QUERY_STRING, BUFLEN);

printf(“ds_set(%d,”%s","%s",%d)
", ds_descriptor,
commandID, buffer, BUFLEN);
if (ds_set(ds_descriptor, commandID, buffer, strlen(buffer)) == -1)
{
printf(“ds_set error:%d\n”, errno);
}
else
{
if (ds_get(ds_descriptor, commandID, buffer, BUFLEN) == -1)
printf(“ds_get error:%d
”, errno);
else
printf(“ds_get(%d,”%s","%s",%d)
", ds_descriptor,
commandID, buffer, BUFLEN);
}
}
}
else
printf(“ds_register error:%d\n”, errno);
}

/* send the html closing tags */
html_end();

return 0;
}

//---------------------------- test program ----------------------------
#include <ds.h>
#include <stdio.h>
#include <errno.h>

extern int errno;

#define BUFLEN 80

int main(int argc, char** argv)
{
char buffer[BUFLEN];
ds_t ds_descriptor;
char *commandID=“cmd”;
int i, result, buflen;

ds_descriptor = ds_register();
if(ds_descriptor==-1)
{
perror(“ds_register”);
exit(1);
}

if(ds_create(ds_descriptor, commandID, DS_PERM, 0)==-1)
{
perror(“ds_create”);
exit(1);
}

memset(buffer, 0, BUFLEN);
strcpy(buffer, “UNINIT”);
ds_set(ds_descriptor, commandID, buffer, BUFLEN);

for (i=0; i<10; i++)
{
memset(buffer, 0, BUFLEN);
result = ds_get(ds_descriptor, commandID, buffer, BUFLEN);
if (result != -1)
printf(“ds_get(%d,%s,%s,%d)\n”, ds_descriptor, commandID, buffer,
BUFLEN);
else
perror(“ds_get”);
delay (1000);
}

ds_clear(ds_descriptor, commandID);
ds_deregister(ds_descriptor);

return 0;
}

“John Bowen” <John.Bowen@grc.nasa.gov> wrote in message
news:99nn0i$ltf$1@inn.qnx.com

I’ve been trying to write an application that uses ds/slinger to push and
pull data from an html page. I wrote a simple test application that
periodically loops and builds an shtml file that can be pulled in by my
browser. Data is sent to the shtml page perfectly.

Commands are sent from the browser using a cgi (C compiled code) that does
a
ds_set. The same program that is building the shtml file also echoes the
value of this variable when it’s filling the other stuff. This part works
fine. Pushing and pulling from a single process seems to be as
advertised.

The problem that I’m seeing is when I take the commanding part of this
application and stuff it in a pthread. Reading the value of the variable
returns a good status indication, until the cgi is called and the variable
gets set to something. At this point the error “Invalid Argument” is
returned by ds_get in the thread indefinitely.

What am I doing wrong? The ds_ library documentation is very limited.
Eventually, if I could poll this thing correctly, then I would like to try
using the signalling capability of ds to wake up this thread when a new
“command” is present.

Any ideas?

John