WSGetData (C Function)

int WSGetData(WSLINK link,char *b,int len,int *count)

gets textual data from the WSTP connection specified by link, storing the result in a buffer b of maximum length len, and storing the actual number of bytes read in count.

Details

  • WSGetData() does not allocate ; must be provided.
  • WSGetData() returns 0 in the event of an error, and a nonzero value if the function succeeds.
  • Use WSError() to retrieve the error code if WSGetData() fails.
  • WSGetData() is declared in the WSTP header file wstp.h.

Examples

Basic Examples  (1)

#include "wstp.h"

/* read data from a link in textual form */

void f(WSLINK lp)
{
    int size, count;
    char *buff;

    switch(WSGetType(lp))
    {
        case WSTKSTR:
            if(! WSBytesToGet(lp, &size))
                {
                    /* unable to read the number of bytes from lp */
                    return;
                }

            buff = (char *)malloc(size * sizeof(char));
            if(buff == (char *)0)
                {
                    /* unable to allocate mmemory */
                    return;
                }

            if(! WSGetData(lp, buff, size &count))
                {
                    /* unable to read the string data from lp */
                    free(buff);
                    return;
                }

            /* ... */

            free(buff);

            break;
    }

    /* ... */
}