[go: up one dir, main page]

Menu

[ab7a0e]: / libircu / msg_EB.cc  Maximize  Restore  History

Download this file

144 lines (119 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* msg_EB.cc
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id: msg_EB.cc,v 1.10 2005/03/25 03:07:29 dan_karrels Exp $
*/
#include <sys/types.h>
#include <sys/time.h>
#include <iostream>
#include "gnuworld_config.h"
#include "server.h"
#include "iServer.h"
#include "events.h"
#include "Network.h"
#include "ELog.h"
#include "xparameters.h"
#include "ServerCommandHandler.h"
RCSTAG( "$Id: msg_EB.cc,v 1.10 2005/03/25 03:07:29 dan_karrels Exp $" ) ;
namespace gnuworld
{
using std::clog ;
using std::endl ;
CREATE_HANDLER(msg_EB)
// Q EB
// Q: Remote server numeric
// EB: End Of Burst
bool msg_EB::Execute( const xParameters& params )
{
if( !strcmp( params[ 0 ], theServer->getUplinkCharYY().c_str() ) )
{
// elog << "msg_EB> sendEA: "
// << theServer->getSendEA()
// << endl ;
// It's my uplink
if( theServer->getSendEA() && theServer->getSendEB() )
{
theServer->setBurstEnd( ::time( 0 ) ) ;
// Our uplink is done bursting
// This is done here instead of down below the if/else
// structure because some of the methods called here
// may depend or use the Uplink's isBursting() method
theServer->getUplink()->stopBursting() ;
}
// Signal that all Write()'s should write to the
// normal output buffer
theServer->setUseHoldBuffer( false ) ;
// Burst our clients
theServer->BurstClients() ;
// Burst our channels
theServer->BurstChannels() ;
// Only need EB to be sent to turn off bursting, since after
// EB no bursts can be sent
if( theServer->getSendEB() )
{
// We are no longer bursting
theServer->setBursting( false ) ;
}
// Called PostEvent() here to notify all attached clients
// that we are no longer bursting. This will ensure
// that all end of burst items are written to the
// burstOutputBuffer before the burst if officially
// completed (as seen by the network)
theServer->PostEvent( EVT_BURST_CMPLT,
static_cast< void* >( theServer->getUplink() ) ) ;
if( theServer->isVerbose() )
{
clog << "*** Completed net burst"
<< endl ;
}
elog << "*** Completed net burst"
<< endl ;
if( theServer->getSendEB() )
{
// Send our EB
theServer->Write( "%s EB\n", theServer->getCharYY().c_str() ) ;
}
if( theServer->getSendEA() )
{
// Acknowledge their end of burst
theServer->Write( "%s EA\n", theServer->getCharYY().c_str() ) ;
}
// Is the burstOutputBuffer empty?
theServer->WriteBurstBuffer() ;
theServer->PostEvent( EVT_EA_SENT,
static_cast< void* >( theServer->getUplink() ) ) ;
}
else
{
/* Its another server that has just completed its net.burst. */
iServer* targetServer = Network->findServer( params[ 0 ] ) ;
if( NULL == targetServer )
{
elog << "msg_EB> Unable to find server: "
<< params[ 0 ]
<< endl ;
return -1 ;
}
targetServer->stopBursting() ;
theServer->PostEvent( EVT_BURST_CMPLT,
static_cast< void* >( targetServer ) ) ;
}
return true ;
}
} // namespace gnuworld