Sample code for 30+ languages & platforms
Unicode C

Poll a Socket for Available Data

See more Socket/SSL/TLS Examples

Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.

Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkSocketW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSocketW socket;
    BOOL bTls;
    int maxWaitMs;
    BOOL bAvailable;

    success = FALSE;

    socket = CkSocketW_Create();

    //  Connect to the server using TLS.
    bTls = TRUE;
    maxWaitMs = 5000;
    success = CkSocketW_Connect(socket,L"example.com",5000,bTls,maxWaitMs);
    if (success == FALSE) {
        wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
        CkSocketW_Dispose(socket);
        return;
    }

    //  Perform a nonblocking check for readable data.  Returns TRUE when data or another read-ready
    //  condition is present, and FALSE when nothing is immediately available.
    bAvailable = CkSocketW_PollDataAvailable(socket);
    if (bAvailable != TRUE) {
        wprintf(L"No data is immediately available.\n");
    }
    else {
        wprintf(L"Data is available to read.\n");
    }



    CkSocketW_Dispose(socket);

    }