From 2c26fc03e3fc7f153d9b16f7eb6e8fafd28451ac Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 17 Aug 2011 18:09:10 -0700 Subject: [PATCH] Track messages sent via proxy and credit nsent (accumulator) if successful. Previously messages sent via proxy were not counted. --- xwords4/relay/xwrelay.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index 1215442db..72d3a56b5 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -720,19 +720,21 @@ pushShort( vector& out, unsigned short num ) static void pushMsgs( vector& out, DBMgr* dbmgr, const char* connName, - HostID hid, int msgCount ) + HostID hid, int msgCount, vector& msgIDs ) { int ii; for ( ii = 0; ii < msgCount; ++ii ) { unsigned char buf[1024]; size_t buflen = sizeof(buf); + int msgID; if ( !dbmgr->GetNthStoredMessage( connName, hid, ii, buf, - &buflen, NULL ) ) { + &buflen, &msgID ) ) { logf( XW_LOGERROR, "%s: %dth message not there", __func__, ii ); break; } pushShort( out, buflen ); out.insert( out.end(), buf, buf + buflen ); + msgIDs.push_back( msgID ); } } @@ -746,6 +748,7 @@ handleMsgsMsg( int sock, bool sendFull, DBMgr* dbmgr = DBMgr::Get(); vector out(4); /* space for len and n_msgs */ assert( out.size() == 4 ); + vector msgIDs; for ( ii = 0; ii < nameCount && bufp < end; ++ii ) { // See NetUtils.java for reply format @@ -770,7 +773,7 @@ handleMsgsMsg( int sock, bool sendFull, int msgCount = dbmgr->PendingMsgCount( connName, hid ); pushShort( out, msgCount ); if ( sendFull ) { - pushMsgs( out, dbmgr, connName, hid, msgCount ); + pushMsgs( out, dbmgr, connName, hid, msgCount, msgIDs ); } } @@ -778,9 +781,13 @@ handleMsgsMsg( int sock, bool sendFull, memcpy( &out[0], &tmp, sizeof(tmp) ); tmp = htons( nameCount ); memcpy( &out[2], &tmp, sizeof(tmp) ); - write( sock, &out[0], out.size() ); + ssize_t nwritten = write( sock, &out[0], out.size() ); + if ( sendFull && nwritten >= 0 && (size_t)nwritten == out.size() ) { + dbmgr->RecordSent( &msgIDs[0], msgIDs.size() ); + // dbmgr->RemoveStoredMessages( &msgIDs[0], msgIDs.size() ); + } } -} +} // handleMsgsMsg static void handleProxyMsgs( int sock, unsigned char* bufp, unsigned char* end )