From 57ec0203301fe46b7b436f5970da86fee78e2955 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 27 Jan 2011 06:37:36 -0800 Subject: [PATCH] change format of reply to MSG_GET: include number of messages per device to support fetching for more than one at once. This is meaningless for rq as written now but a device will want to do this. --- xwords4/relay/rq.c | 28 +++++++++++++++++++--------- xwords4/relay/xwrelay.cpp | 8 ++++---- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/xwords4/relay/rq.c b/xwords4/relay/rq.c index 8cc46af85..1999349b5 100644 --- a/xwords4/relay/rq.c +++ b/xwords4/relay/rq.c @@ -189,18 +189,28 @@ do_fetch( int sockfd, const char** connNames, int nConnNames ) assert( count == nConnNames ); fprintf( stderr, "got count: %d\n", count ); - /* Now we have an array of pairs. Just write em as - long as it makes sense.*/ + /* Now we have an array of pairs. Just + write em as long as it makes sense. countPerDev makes no sense as + other than 1 unless the UI is changed so I don't have to write to + STDOUT -- e.g. by passing in named pipes to correspond to each + deviceid provided */ while ( bufp < end ) { - unsigned short len; - memcpy( &len, bufp, sizeof( len ) ); - len = ntohs( len ) + sizeof( len ); - if ( bufp + len > end ) { - break; + unsigned short countPerDev; + memcpy( &countPerDev, bufp, sizeof( countPerDev ) ); + bufp += sizeof( countPerDev ); + countPerDev = ntohs( countPerDev ); + + while ( bufp < end && countPerDev-- > 0 ) { + unsigned short len; + memcpy( &len, bufp, sizeof( len ) ); + len = ntohs( len ) + sizeof( len ); + if ( bufp + len > end ) { + break; + } + write( STDOUT_FILENO, bufp, len ); + bufp += len; } - write( STDOUT_FILENO, bufp, len ); - bufp += len; } if ( bufp != end ) { fprintf( stderr, "error: message not internally as expected\n" ); diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index 18b70a242..7da9f14e2 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -77,8 +77,6 @@ #include "dbmgr.h" static int s_nSpawns = 0; -#define MAX_PROXY_LEN 64 -#define MAX_PROXY_COUNT 48 void logf( XW_LogLevel level, const char* format, ... ) @@ -729,6 +727,7 @@ handleMsgsMsg( int sock, bool sendFull, char* in = (char*)bufp; DBMgr* dbmgr = DBMgr::Get(); unsigned short count; + /* This is wrong now */ /* reply format: PRX_GET_MSGS case: []* * PRX_HAS_MSGS case: * */ @@ -747,11 +746,12 @@ handleMsgsMsg( int sock, bool sendFull, break; } + /* For each relayID, write the number of messages and then each + message (in the getmsg case) */ int msgCount = dbmgr->PendingMsgCount( connName, hid ); + pushShort( out, msgCount ); if ( sendFull ) { pushMsgs( out, dbmgr, connName, hid, msgCount ); - } else { - pushShort( out, msgCount ); } in = NULL;