>Brian, if there is no data avalible, NetLibReceive call will block until at
>least one byte arrives.

I figured out that much - so I do a select first to see if there is data,
and then try to peek.

>If you use Codeworrier, there is a sample program at Symbol SDK
>Support\Samples\S24 Sampels\NdkLib\SrcNdkLib.c
>A fucntion "ReadN" that read "n" byte from a descriptor.  I am no sure that
>will help you.

Thanks, I'll check that out.

>By the way,  I am testing "telnet" from NetSample onemultor and I can't type
>data as soon as I login, any idea what went wrong?

Nope - although that much works in my own app ;-)

I just end up reading 1 byte at a time!

I'll attach my routine to this message, perhaps you'll notice something.

brian

--


// Return the number of bytes available for reading
Err CNetConnection::ReceiveCheck(UInt32 *numBytesP)
{
        Err                             err;
        Int16                   numFDs;
        Int16                   nfds;
        NetFDSetType    arfds;
        NetFDSetType    awfds;

        // Create our file descriptor set for checking input from the socket
        nfds = 0;
        netFDZero(&arfds);
        netFDZero(&awfds);
        netFDSet(fSocket, &arfds);
        nfds = fSocket + 1;

        // Assume no data
        *numBytesP = 0;

        // Check for activity
        // Wait for any one of the descriptors to be ready.
        numFDs = NetLibSelect(
                fNetLibRefNum,
                nfds,                   // width: # of descriptor bits to check
                &arfds,                 // read FDs
                &awfds,                 // write FDs
                0,                              // NetFDSetType* exceptFDs,
                0,                              // timeout -1 = forever
                &err);

        // Just a signal?
        if (err == netErrTimeout) { err = 0; goto out; }

        // If there is an error, bail
        if (err) goto out;

        // Return number of bytes found
        if (numFDs > 0 && (netFDIsSet(fSocket, &arfds))) {
#if 1
                // NOTE: This current code will just return 1, since we
only check for data present,
                // and NOT the number of bytes, as one would expect. How
will we do that?!?
                *numBytesP = 1;
#else
        Err             err;
        Int16   numRead;
        UInt16  fromLen = 0;
        char    buf[64];

        numRead = NetLibReceive(
                fNetLibRefNum,
                fSocket,
                buf,                    // bufP,
                sizeof(buf),    // bufLen, - Must be non-zero, or 0
returned by OS
                netIOFlagPeek,  // AHHH! Peek so we can find # in buffer
                // flags
                0,                              // Address to send to
(NetSocketAddrType*), or 0,
                &fromLen,               // len of above address
                0, // fAppNetTimeout,   // timeout -1 = forever
                &err);

        if (numRead >= 0) *numBytesP = numRead;
        else *numBytesP = 0;
#endif
        }

        // No error (could check for numFDs < 0, but then need to take into
account timeout)
out:
        return err;
}

_____________________________________________________________________
Mark/Space Softworks                               voice 408-293-7299
111 West Saint John, 3rd Floor                       fax 408-293-7298
San Jose, CA 95113                         <http://www.markspace.com>

        PalmOS, Mac OS, Windows and Web Software & Solutions:

         PageNOW! Wireless Messaging, PhoneWatcher Caller ID,
     Online & Communicate terminal emulation and serial debugging

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to