From 2e3c0ecb10f9523058e4b59c77bd9494f1679511 Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 27 Jul 1993 13:52:54 +0000 Subject: Move MyMpx to UchChannel Integrated changes from mbl --- comm/OLD/TextStream.cc | 76 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 30 deletions(-) (limited to 'comm/OLD') diff --git a/comm/OLD/TextStream.cc b/comm/OLD/TextStream.cc index a6d12d3..a869b9e 100644 --- a/comm/OLD/TextStream.cc +++ b/comm/OLD/TextStream.cc @@ -16,6 +16,7 @@ #include "TimeOut.h" #include "PortServer.h" #include "Multiplexer.h" +#include "error.h" #include #include #include @@ -122,10 +123,14 @@ UchTextWord :: SetVal (const char* val) // if Sval is null, then it's an integer, whose value is in Ival // if Sval is non null, then it's a string, whose value is in Sval Ival = atoi (val); - if (Ival == 0 && strcmp (val, "0") != 0) + if (Ival == 0 && strcmp (val, "0") != 0) { Sval = val; // word is a string: atoi returned 0 and val is not "0" - else + } else if (strlen (val) < 10) { Sval = 0; // word is an integer + } else { + Sval = val; + Ival = 0; + } } const char* @@ -448,8 +453,7 @@ Construct a \typ{UchTextStream}. UchTextStream :: UchTextStream () : UchStream (), InBuffer (256), - OutBuffer (256), - MyMpx (0) + OutBuffer (256) { } @@ -474,19 +478,6 @@ UchTextStream :: Closing (bool) Close (); } -void -UchTextStream :: AddNotify (UchMultiplexer& m) -{ - MyMpx = &m; -} - -void -UchTextStream :: RemoveNotify (UchMultiplexer& m) -{ - if (MyMpx == &m) - MyMpx = 0; -} - /*? Read and decode input. When a complete line (terminated either by a newline or cr-newline) is in the input buffer, it is parsed. @@ -575,12 +566,13 @@ UchTextStream :: ProcessCmdResult (cmd_res res, const UchTextLine& line) return; case isCmdTerminate: // terminate the multiplexer - if (MyMpx) - MyMpx->LoopEnd (); + if (Mpx) + Mpx->Close (); return; case isCmdAbort: // abort the multiplexer -// MpxAbort (); + if (Mpx) + Mpx->Abort (); return; case isCmdExit: exit (1); @@ -641,7 +633,7 @@ should call the default implementation. void UchTextStream :: Close () { - MyMpx->Remove (*this); + Mpx->Remove (*this); } /*? @@ -654,7 +646,7 @@ gracefully. void UchTextStream :: Quit () { - MyMpx->LoopEnd (); + Mpx->Close (); } //---------------- ServiceStarter @@ -793,9 +785,22 @@ UchTextService :: Restart () { UchInetAddress* addr = PortServerInquire ("portserv", Service, Host); if (! addr) { +#if 0 + // *** horrible patch - see portcli.C. This info should be returned by PortServerInquire + extern bool PortServerInquireSysError; + if (PortServerInquireSysError) { + Log ("TSERVICE::Restart", "no agent manager"); + return StatusFlag = isError; + } +#endif fprintf (stderr, "UchTextService::Restart, no address in port server\n"); return StatusFlag = isUnavailable; } + if (addr->Host () == 0 && addr->Port () == 0) { +// Log ("TSERVICE::Restart", "agent being launched by agent manager"); + return StatusFlag = isLost; + } + ConnectTo (addr); bool wasopened = Fd.Opened (); @@ -808,7 +813,7 @@ UchTextService :: Restart () if (ofd >= 0) { close (ofd); int nfd = socket (ConnectedTo () ->Family (), SockType (), 0); - fprintf (stderr, "UchTextService::Restart, reopening socket: %d -> %d\n", (void*) ofd, (void*) nfd); +// fprintf (stderr, "UchTextService::Restart, reopening socket: %d -> %d\n", (void*) ofd, (void*) nfd); if (nfd < 0) { setup = FALSE; } else if (nfd != ofd) { @@ -821,7 +826,7 @@ UchTextService :: Restart () setup = Setup (); if (! wasopened) { SetMode (IONone); - MyMpx->Add (this); + Mpx->Add (this); } if (! setup) { fprintf (stderr, "UchTextService::Restart, could not setup connection\n"); @@ -865,7 +870,7 @@ UchTextService :: AutoStart (int retry_time, int maxr) Starter->ChangePeriod (retry_time); Starter->Retries = 0; Starter->Max = maxr; - } else if (MyMpx) { + } else if (Mpx) { Starter = new UchServiceStarter (this, retry_time, maxr); } else fprintf (stderr, "UchTextService::AutoStart, no multiplexer for time-out\n"); @@ -882,7 +887,7 @@ call the default implementation. void UchTextService :: LostServer () { - MyMpx->SetMode (*this, IONone); + Mpx->SetMode (*this, IONone); AutoStart (); } @@ -899,7 +904,7 @@ call the default implementation. void UchTextService :: GotServer () { - MyMpx->SetMode (*this, IORead); + Mpx->SetMode (*this, IORead); if (OutBuffer.BufLength ()) DoSend (); } @@ -946,7 +951,7 @@ UchTextService :: DoSend () if (StatusFlag == isRunning) { Write (OutBuffer); if (Closed) - MyMpx->Remove (*this); + Mpx->Remove (*this); } } @@ -966,6 +971,17 @@ UchTextService :: Init (const char* s, const char* h) Host = h; StatusFlag = Restart (); + if (StatusFlag == isError) { + // try to run the agent manager + if (fork () != 0) { + // we are the parent process, and we become the agent manager + // *** how to have the agent manager survive the client ??? + Error (ErrLog, "TSERVICE::Init", "trying to run agentman"); + if (execlp ("agentman", "agentman", 0) != 0) + Error (ErrWarn, "TSERVICE::Init", "could not run agentman"); + } + } + // delay retry if (StatusFlag != isRunning) AutoStart (); } @@ -1002,7 +1018,7 @@ UchTextService :: Close () { Closed = TRUE; if (StatusFlag == isRunning || OutBuffer.BufLength () == 0) - MyMpx->Remove (*this); + Mpx->Remove (*this); } /*? @@ -1012,7 +1028,7 @@ the state of the connection is. void UchTextService :: CloseNow () { - MyMpx->Remove (*this); + Mpx->Remove (*this); } /*? -- cgit v1.1