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.
This commit is contained in:
Andy2 2011-01-27 06:37:36 -08:00
parent 481a533e58
commit 57ec020330
2 changed files with 23 additions and 13 deletions

View file

@ -189,18 +189,28 @@ do_fetch( int sockfd, const char** connNames, int nConnNames )
assert( count == nConnNames ); assert( count == nConnNames );
fprintf( stderr, "got count: %d\n", count ); fprintf( stderr, "got count: %d\n", count );
/* Now we have an array of <len><len bytes> pairs. Just write em as /* Now we have an array of <countPerDev> <len><len bytes> pairs. Just
long as it makes sense.*/ 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 ) { while ( bufp < end ) {
unsigned short len; unsigned short countPerDev;
memcpy( &len, bufp, sizeof( len ) ); memcpy( &countPerDev, bufp, sizeof( countPerDev ) );
len = ntohs( len ) + sizeof( len ); bufp += sizeof( countPerDev );
if ( bufp + len > end ) { countPerDev = ntohs( countPerDev );
break;
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 ) { if ( bufp != end ) {
fprintf( stderr, "error: message not internally as expected\n" ); fprintf( stderr, "error: message not internally as expected\n" );

View file

@ -77,8 +77,6 @@
#include "dbmgr.h" #include "dbmgr.h"
static int s_nSpawns = 0; static int s_nSpawns = 0;
#define MAX_PROXY_LEN 64
#define MAX_PROXY_COUNT 48
void void
logf( XW_LogLevel level, const char* format, ... ) logf( XW_LogLevel level, const char* format, ... )
@ -729,6 +727,7 @@ handleMsgsMsg( int sock, bool sendFull,
char* in = (char*)bufp; char* in = (char*)bufp;
DBMgr* dbmgr = DBMgr::Get(); DBMgr* dbmgr = DBMgr::Get();
unsigned short count; unsigned short count;
/* This is wrong now */
/* reply format: PRX_GET_MSGS case: <message len><n_msgs>[<len><msg>]* /* reply format: PRX_GET_MSGS case: <message len><n_msgs>[<len><msg>]*
* PRX_HAS_MSGS case: <message len><n_msgs><count>* * PRX_HAS_MSGS case: <message len><n_msgs><count>*
*/ */
@ -747,11 +746,12 @@ handleMsgsMsg( int sock, bool sendFull,
break; break;
} }
/* For each relayID, write the number of messages and then each
message (in the getmsg case) */
int msgCount = dbmgr->PendingMsgCount( connName, hid ); int msgCount = dbmgr->PendingMsgCount( connName, hid );
pushShort( out, msgCount );
if ( sendFull ) { if ( sendFull ) {
pushMsgs( out, dbmgr, connName, hid, msgCount ); pushMsgs( out, dbmgr, connName, hid, msgCount );
} else {
pushShort( out, msgCount );
} }
in = NULL; in = NULL;