mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
Deal with incoming fragmented rfcomm packets; log packet contents.
This commit is contained in:
parent
0cdd8a41c4
commit
476e164aa1
1 changed files with 25 additions and 15 deletions
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "linuxbt.h"
|
#include "linuxbt.h"
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
|
#include "strutils.h"
|
||||||
|
|
||||||
#define MAX_CLIENTS 3
|
#define MAX_CLIENTS 3
|
||||||
|
|
||||||
|
@ -447,6 +448,7 @@ linux_bt_send( const XP_U8* buf, XP_U16 buflen,
|
||||||
LinBtStuff* btStuff;
|
LinBtStuff* btStuff;
|
||||||
|
|
||||||
XP_LOGF( "%s(len=%d)", __FUNCTION__, buflen );
|
XP_LOGF( "%s(len=%d)", __FUNCTION__, buflen );
|
||||||
|
LOG_HEX( buf, buflen, __func__ );
|
||||||
|
|
||||||
btStuff = globals->btStuff;
|
btStuff = globals->btStuff;
|
||||||
if ( !!btStuff ) {
|
if ( !!btStuff ) {
|
||||||
|
@ -483,6 +485,23 @@ linux_bt_send( const XP_U8* buf, XP_U16 buflen,
|
||||||
return nSent;
|
return nSent;
|
||||||
} /* linux_bt_send */
|
} /* linux_bt_send */
|
||||||
|
|
||||||
|
#if defined BT_USE_RFCOMM
|
||||||
|
static void
|
||||||
|
read_all( int sock, unsigned char* buf, const int len )
|
||||||
|
{
|
||||||
|
int totalRead = 0;
|
||||||
|
while ( totalRead < len ) {
|
||||||
|
int nRead = read( sock, buf+totalRead, len-totalRead );
|
||||||
|
if ( nRead < 0 ) {
|
||||||
|
XP_LOGF( "%s: read->%s", __FUNCTION__, strerror(errno) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
totalRead += nRead;
|
||||||
|
XP_ASSERT( totalRead <= len );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XP_S16
|
XP_S16
|
||||||
linux_bt_receive( int sock, XP_U8* buf, XP_U16 buflen )
|
linux_bt_receive( int sock, XP_U8* buf, XP_U16 buflen )
|
||||||
{
|
{
|
||||||
|
@ -491,22 +510,13 @@ linux_bt_receive( int sock, XP_U8* buf, XP_U16 buflen )
|
||||||
XP_ASSERT( sock >= 0 );
|
XP_ASSERT( sock >= 0 );
|
||||||
|
|
||||||
#if defined BT_USE_RFCOMM
|
#if defined BT_USE_RFCOMM
|
||||||
unsigned short len;
|
read_all( sock, (unsigned char*)&nRead, sizeof(nRead) );
|
||||||
int totalRead = 0;
|
nRead = ntohs(nRead);
|
||||||
nRead = read( sock, &len, sizeof(len) );
|
XP_LOGF( "nRead=%d", nRead );
|
||||||
assert( nRead == 2 );
|
XP_ASSERT( nRead < buflen );
|
||||||
len = ntohs(len);
|
|
||||||
XP_ASSERT( len < buflen );
|
|
||||||
|
|
||||||
while ( totalRead < len ) {
|
read_all( sock, buf, nRead );
|
||||||
nRead = read( sock, buf+totalRead, len-totalRead );
|
LOG_HEX( buf, nRead, __func__ );
|
||||||
if ( nRead < 0 ) {
|
|
||||||
XP_LOGF( "%s: read->%s", __FUNCTION__, strerror(errno) );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
totalRead += nRead;
|
|
||||||
XP_ASSERT( totalRead <= buflen );
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
nRead = read( sock, buf, buflen );
|
nRead = read( sock, buf, buflen );
|
||||||
if ( nRead < 0 ) {
|
if ( nRead < 0 ) {
|
||||||
|
|
Loading…
Reference in a new issue