mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
send dev-targeted messages pulled from db by rewriting their headers
with a new packetID.
This commit is contained in:
parent
de125eb9a6
commit
b80051cc73
1 changed files with 33 additions and 3 deletions
|
@ -523,6 +523,22 @@ assemble_packet( vector<uint8_t>& packet, uint32_t* packetIDP, XWRelayReg cmd,
|
||||||
va_end( ap );
|
va_end( ap );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make a new packet out of an old, stealing its cmd field
|
||||||
|
static void
|
||||||
|
assemble_packet( vector<uint8_t>& newPacket, uint32_t* packetID,
|
||||||
|
const vector<uint8_t>& oldPacket )
|
||||||
|
{
|
||||||
|
UDPHeader header;
|
||||||
|
const uint8_t* ptr = oldPacket.data();
|
||||||
|
size_t len = oldPacket.size();
|
||||||
|
if ( !getHeader( &ptr, ptr + len, &header ) ) {
|
||||||
|
assert( 0 );
|
||||||
|
}
|
||||||
|
assert( XWPDEV_PROTO_VERSION_1 == header.proto );
|
||||||
|
len -= ptr - oldPacket.data(); // subtract off header length
|
||||||
|
assemble_packet( newPacket, packetID, header.cmd, ptr, len, NULL );
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
get_addr_info_if( const AddrInfo* addr, int* sockp,
|
get_addr_info_if( const AddrInfo* addr, int* sockp,
|
||||||
const struct sockaddr** dest_addr )
|
const struct sockaddr** dest_addr )
|
||||||
|
@ -1507,10 +1523,24 @@ retrieveMessages( DevID& devID, const AddrInfo* addr )
|
||||||
|
|
||||||
vector<DBMgr::MsgInfo>::const_iterator iter;
|
vector<DBMgr::MsgInfo>::const_iterator iter;
|
||||||
for ( iter = msgs.begin(); iter != msgs.end(); ++iter ) {
|
for ( iter = msgs.begin(); iter != msgs.end(); ++iter ) {
|
||||||
DBMgr::MsgInfo msg = *iter;
|
const DBMgr::MsgInfo& msg = *iter;
|
||||||
uint32_t packetID;
|
uint32_t packetID;
|
||||||
if ( !send_msg_via_udp( addr, msg.token, msg.msg.data(),
|
bool success = false;
|
||||||
msg.msg.size(), &packetID ) ) {
|
if ( AddrInfo::NULL_TOKEN == msg.token ) {
|
||||||
|
int socket;
|
||||||
|
const struct sockaddr* dest_addr;
|
||||||
|
if ( get_addr_info_if( addr, &socket, &dest_addr ) ) {
|
||||||
|
vector<uint8_t> newPacket;
|
||||||
|
assemble_packet( newPacket, &packetID, msg.msg );
|
||||||
|
success = 0 < send_packet_via_udp_impl( newPacket, socket,
|
||||||
|
dest_addr );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
success = send_msg_via_udp( addr, msg.token, msg.msg.data(),
|
||||||
|
msg.msg.size(), &packetID );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !success ) {
|
||||||
logf( XW_LOGERROR, "%s: unable to send to devID %d",
|
logf( XW_LOGERROR, "%s: unable to send to devID %d",
|
||||||
__func__, devID.asRelayID() );
|
__func__, devID.asRelayID() );
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue