diff options
Diffstat (limited to 'comm/OLD')
-rw-r--r-- | comm/OLD/Agent.cc | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/comm/OLD/Agent.cc b/comm/OLD/Agent.cc index 3e4bf8a..6c06f01 100644 --- a/comm/OLD/Agent.cc +++ b/comm/OLD/Agent.cc @@ -39,7 +39,7 @@ Construct an empty server port. UchAgent :: UchAgent () : UchStream (), RemoteAgents (), - ChanSet (0) + Mpx (0) { } @@ -47,7 +47,7 @@ UchAgent :: UchAgent () UchAgent :: UchAgent (const UchAgent& sp) : UchStream (sp), RemoteAgents (), - ChanSet (0) + Mpx (0) { } @@ -60,7 +60,7 @@ This can be done with the instruction \com{new UchInetAddress(ANYADDR)}. UchAgent :: UchAgent (UchAddress* a) : UchStream (a, 0), RemoteAgents (), - ChanSet (0) + Mpx (0) { } @@ -71,7 +71,7 @@ UchAgent :: ~UchAgent () while (cl = RemoteAgents.First ()) cl->Delete (); - ChanSet = 0; // will delete it if necessary + Mpx = 0; // will delete it if necessary } /*?nodoc?*/ @@ -112,7 +112,7 @@ A smart pointer to the channel set is actually kept in the server, so that it ca securely. ?*/ bool -UchAgent :: Setup (UchMultiplexer* cs) +UchAgent :: Setup (UchBaseMultiplexer* cs) { if (Listen () < 0) { SysError (ErrWarn, "UchAgent::Setup"); @@ -121,8 +121,8 @@ UchAgent :: Setup (UchMultiplexer* cs) SetMode (IORead); if (!cs) cs = new UchMultiplexer; - ChanSet = cs; - ChanSet->Add (this); + Mpx = cs; + Mpx->Add (this); return TRUE; } @@ -139,8 +139,8 @@ This is the only way to exit properly from \fun{Run}. void UchAgent :: Unlisten () { - if (ChanSet) - ChanSet->Remove (*this); + if (Mpx) + Mpx->Remove (*this); } @@ -163,8 +163,8 @@ UchAgent :: HandleRead () ra->SetMode (IOReadSelect); RemoteAgents.Append (ra); - if (ChanSet) - ChanSet->Add (ra); + if (Mpx) + Mpx->Add (ra); } /*? @@ -213,20 +213,22 @@ UchAgent :: Error (errtype how, const char* who, const char* what) /*? Setup the server if necessary, then scan and process its channel set -by calling \fun{LoopScan} for it. +by calling \fun{Run} for it. To have a server active, you need at least to initialize it (and thus know its address), and then run it. If you have added your own channels to the channel set of the server, their \fun{HandleRead} and \fun{HandleWrite} functions will be called normally by \fun{Run}. ?*/ -void +MPX_RES UchAgent :: Run () { - if (! ChanSet) + if (! Mpx) if (! Setup ()) Error (ErrFatal, "UchAgent::Run", "could not setup"); - if (ChanSet) - ChanSet->LoopScan (); + if (Mpx) + return Mpx->Run (); + else + return isMpxError; } /*? @@ -236,9 +238,15 @@ If \var{flush} is TRUE, the output buffer of each remote agent is flushed. void UchAgent :: Broadcast (UchMessage& msg, bool flush) { +#ifndef CPLUS_BUG19 CcuListIterOf <UchRemoteAgent> li (RemoteAgents); while (++li) (*li)->Send (msg, flush); +#else + CcuListIter li (RemoteAgents); + while (++li) + ((UchRemoteAgent*)(*li))->Send (msg, flush); +#endif } /*? @@ -248,19 +256,34 @@ If \var{flush} is TRUE, the output buffer of each client is flushed. void UchAgent :: Broadcast (UchMessage& msg, UchRemoteAgent* excl, bool flush) { +#ifndef CPLUS_BUG19 CcuListIterOf <UchRemoteAgent> li (RemoteAgents); while (++li) if (*li != excl) (*li)->Send (msg, flush); +#else + CcuListIter li (RemoteAgents); + while (++li) { + UchRemoteAgent* a = (UchRemoteAgent*)(*li); + if (a != excl) + a->Send (msg, flush); + } +#endif } /*?nextdoc?*/ void UchAgent :: Broadcast (UchMsgBuffer& buf, bool flush) { +#ifndef CPLUS_BUG19 CcuListIterOf <UchRemoteAgent> li (RemoteAgents); while (++li) (*li)->Send (buf, flush); +#else + CcuListIter li (RemoteAgents); + while (++li) + ((UchRemoteAgent*)(*li))->Send (buf, flush); +#endif } /*? @@ -272,10 +295,19 @@ message conversion overhead. void UchAgent :: Broadcast (UchMsgBuffer& buf, UchRemoteAgent* excl, bool flush) { +#ifndef CPLUS_BUG19 CcuListIterOf <UchRemoteAgent> li (RemoteAgents); while (++li) if (*li != excl) (*li)->Send (buf, flush); +#else + CcuListIter li (RemoteAgents); + while (++li) { + UchRemoteAgent* a = (UchRemoteAgent*)(*li); + if (a != excl) + a->Send (buf, flush); + } +#endif } #ifdef DOC @@ -285,8 +317,8 @@ UchAgent :: Broadcast (UchMsgBuffer& buf, UchRemoteAgent* excl, bool flush) Return the channel set used by the server. This is useful if you want to add your own channels to the channel set. ?*/ -UchMultiplexer* -UchAgent :: GetChanSet () +UchBaseMultiplexer* +UchAgent :: GetMultiplexer () { } #endif @@ -298,7 +330,7 @@ UchAgent :: Contact (UchAddress* a) return 0; UchRemoteAgent* ra = new UchRemoteAgent (this, a); if (ra) - ChanSet->Add (ra); + Mpx->Add (ra); return ra; } @@ -340,8 +372,8 @@ UchRemoteAgent :: ~UchRemoteAgent () UchAgent* s = MyLocalAgent; s->Error (ErrWarn, "~UchRemoteAgent", "remote agent still connected; deleting anyway ...\n"); s->RemoveRemoteAgent (this); - if (s->ChanSet) - s->ChanSet->Remove (*this); // calls the destructor if no more refs + if (s->Mpx) + s->Mpx->Remove (*this); // calls the destructor if no more refs } } @@ -364,8 +396,8 @@ UchRemoteAgent :: Delete () if (MyLocalAgent) { UchAgent* s = MyLocalAgent; s->RemoveRemoteAgent (this); - if (s->ChanSet) - s->ChanSet->Remove (*this); // calls the destructor if no more refs + if (s->Mpx) + s->Mpx->Remove (*this); // calls the destructor if no more refs } } |