generate XWRELAY_OTHERCONNECT message

This commit is contained in:
ehouse 2005-09-03 18:35:34 +00:00
parent 8072bc687c
commit 4882c92a07
2 changed files with 40 additions and 20 deletions

View file

@ -265,10 +265,10 @@ CookieRef::pushReconnectEvent( int socket, HostID srcID )
{ {
CRefEvent evt; CRefEvent evt;
evt.type = XW_EVENT_RECONNECTMSG; evt.type = XW_EVENT_RECONNECTMSG;
evt.u.recon.socket = socket; evt.u.con.socket = socket;
evt.u.recon.srcID = srcID; evt.u.con.srcID = srcID;
m_eventQueue.push_back( evt ); m_eventQueue.push_back( evt );
} /* pushConnectEvent */ } /* pushReconnectEvent */
void void
CookieRef::pushHeartbeatEvent( HostID id, int socket ) CookieRef::pushHeartbeatEvent( HostID id, int socket )
@ -382,8 +382,12 @@ CookieRef::handleEvents()
switch( takeAction ) { switch( takeAction ) {
case XW_ACTION_SEND_1ST_RSP: case XW_ACTION_SEND_1ST_RSP:
setAllConnectedTimer(); setAllConnectedTimer();
/* fallthru */ sendResponse( &evt );
break;
case XW_ACTION_SENDRSP: case XW_ACTION_SENDRSP:
notifyOthers( evt.u.con.socket, XWRELAY_OTHERCONNECT,
XWRELAY_ERROR_NONE );
sendResponse( &evt ); sendResponse( &evt );
break; break;
@ -403,7 +407,8 @@ CookieRef::handleEvents()
disconnectSockets( 0, XWRELAY_ERROR_TIMEOUT ); disconnectSockets( 0, XWRELAY_ERROR_TIMEOUT );
break; break;
case XW_ACTION_HEARTDISCONNECT: case XW_ACTION_HEARTDISCONNECT:
notifyOthers( evt.u.heart.socket, XWRELAY_ERROR_HEART_OTHER ); notifyOthers( evt.u.heart.socket, XWRELAY_DISCONNECT_OTHER,
XWRELAY_ERROR_HEART_OTHER );
disconnectSockets( evt.u.heart.socket, disconnectSockets( evt.u.heart.socket,
XWRELAY_ERROR_HEART_YOU ); XWRELAY_ERROR_HEART_YOU );
break; break;
@ -551,7 +556,32 @@ CookieRef::checkFromServer( const CRefEvent* evt )
} }
void void
CookieRef::notifyOthers( int socket, XWREASON why ) CookieRef::send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why )
{
unsigned char buf[10];
short tmp;
int len = 0;
buf[len++] = msg;
switch ( msg ) {
case XWRELAY_DISCONNECT_OTHER:
buf[len++] = why;
tmp = htons( id );
memcpy( &buf[len], &tmp, 2 );
len += 2;
break;
case XWRELAY_OTHERCONNECT:
break;
default:
logf( "not handling message %d", msg );
assert(0);
}
send_with_length( socket, buf, sizeof(buf) );
} /* send_msg */
void
CookieRef::notifyOthers( int socket, XWRelayMsg msg, XWREASON why )
{ {
assert( socket != 0 ); assert( socket != 0 );
@ -561,15 +591,7 @@ CookieRef::notifyOthers( int socket, XWREASON why )
while ( iter != m_hostSockets.end() ) { while ( iter != m_hostSockets.end() ) {
int other = iter->second.m_socket; int other = iter->second.m_socket;
if ( other != socket ) { if ( other != socket ) {
unsigned char buf[4]; send_msg( other, iter->first, msg, why );
buf[0] = XWRELAY_DISCONNECT_OTHER;
buf[1] = why;
HostID id = iter->first;
short tmp = htons( id );
memcpy( &buf[2], &tmp, 2 );
send_with_length( other, buf, sizeof(buf) );
} }
++iter; ++iter;
} }

View file

@ -101,10 +101,6 @@ class CookieRef {
int socket; int socket;
HostID srcID; HostID srcID;
} con; } con;
struct {
int socket;
HostID srcID;
} recon;
struct { struct {
HostID id; HostID id;
int socket; int socket;
@ -128,6 +124,8 @@ class CookieRef {
} CRefEvent; } CRefEvent;
void send_with_length( int socket, unsigned char* buf, int bufLen ); void send_with_length( int socket, unsigned char* buf, int bufLen );
void send_msg( int socket, HostID id, XWRelayMsg msg, XWREASON why );
void RecordSent( int nBytes, int socket ) { void RecordSent( int nBytes, int socket ) {
m_totalSent += nBytes; m_totalSent += nBytes;
} }
@ -157,7 +155,7 @@ class CookieRef {
void forward( const CRefEvent* evt ); void forward( const CRefEvent* evt );
void checkDest( const CRefEvent* evt ); void checkDest( const CRefEvent* evt );
void checkFromServer( const CRefEvent* evt ); void checkFromServer( const CRefEvent* evt );
void notifyOthers( int socket, XWREASON why ); void notifyOthers( int socket, XWRelayMsg msg, XWREASON why );
void disconnectSockets( int socket, XWREASON why ); void disconnectSockets( int socket, XWREASON why );
void noteHeartbeat(const CRefEvent* evt); void noteHeartbeat(const CRefEvent* evt);