opensubscriber
   Find in this group all groups
 
Unknown more information…

b : bluetooth-forum@palm.lyris.net 1 April 2005 • 9:08PM -0500

Re: BtLibSocketSend(rfcomm socket) usage
by Tom Keel

REPLY TO AUTHOR
 
REPLY TO GROUP




>
>
>I plan to put a limit (maybe around 2500 or xN of the actual MaxTxSize for rfcomm) on the Tx MTU since this might be larger than what I can allocate for the buffer.  Can the current stack buffer accomate this? Can you suggest a value?
>
The system can buffer at least two app-level packets down in the IO
process (one at the stream head, one at the RfComm driver's queue) and
those packets can be really big (like 32KB or something, I'm not sure
what the max really is, but certainlly bigger than 2.5KB). So you would
just have to keep track of how many outstanding RfComm packets there are
for each outstanding app packet:

    int n=0;  // number of outstanding app packets: {0..2}
    int r[2]; // number of outstanding RfComm packets per app packet

When you want to send an app packet that that contains k segments:

    if ( n < 2 ) {
        BtLibSocketSend(...);
        r[n++] = k; // most-recently sent needs k acks
    } else {
        // remember that there is an app packet waiting to be sent
    }

When you see a SendComplete event:

    r[0]--; // one fewer ack needed for least-recently sent
    if ( r[0] == 0 ) {
        n--; // least-recently sent has been completely acked
        r[0] = r[1];
        if ( /* an app packet of k segments is waiting to be sent */ ) {
            BtLibSocketSend(...);
            r[n++] = k;
        }
    }

(Caveat: untested code).

>Maybe I'll try to set the POLLOUT bit from the PbxPoll().
>
If you want to use IOSPoll() rather than counting acks: (1) When you
have a new packet to send you would call IOSPoll() on just the RfComm
file descriptor, with a 0 timeout, and with the POLLOUT event bit set.
If upon return the POLLOUT bit is set in the output event mask, send the
packet, else save it. (2) When you add the RfComm fd to the poll box
that is used in the main event loop, set the POLLOUT bit in the event
mask. When a SendComplete is seen, and there is a packet waiting to
transmit, and the POLLOUT bit is set in the RfComm fd's output event
mask, send the waiting packet.

>How shall I do read/write after pushing the rfcomm socket to stream?
>
After pushing the Serial-on-RfComm module onto the Stream, you use
IOSGetmsg() or IOSRead() to read, and IOSWrite() to write. The call to
IOSGetmsg() in your main event loop will read the data without
modification. When the RfComm channel is disconnected, you will see the
POLLHUP bit in the output event mask from PbxPoll(), and calls to
IOSWrite() or IOSPutmsg() or BtLibSocketSend() on that file descriptor
will fail.


--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.