summaryrefslogtreecommitdiff
path: root/comm
diff options
context:
space:
mode:
authorchatty1994-05-10 11:36:23 +0000
committerchatty1994-05-10 11:36:23 +0000
commitb0fff9b9e5becf35cdd051a81d0574a3a6c3be2a (patch)
treef6e866161bb17587d344d0fbdf30cef57b435444 /comm
parent6f03fc87b2858caf3424639cbba2d38f8f8f3029 (diff)
downloadivy-league-b0fff9b9e5becf35cdd051a81d0574a3a6c3be2a.zip
ivy-league-b0fff9b9e5becf35cdd051a81d0574a3a6c3be2a.tar.gz
ivy-league-b0fff9b9e5becf35cdd051a81d0574a3a6c3be2a.tar.bz2
ivy-league-b0fff9b9e5becf35cdd051a81d0574a3a6c3be2a.tar.xz
replaced TRUE/FALSE by true/false
Diffstat (limited to 'comm')
-rw-r--r--comm/OLD/Agent.cc32
-rw-r--r--comm/OLD/Agent.h12
-rw-r--r--comm/OLD/TextServer.cc32
-rw-r--r--comm/OLD/TextStream.cc564
-rw-r--r--comm/OLD/TextStream.h137
-rw-r--r--comm/OLD/dgram.cc123
-rw-r--r--comm/OLD/dgram.h12
-rw-r--r--comm/OLD/portserv.cc95
-rw-r--r--comm/XtMultiplexer.cc6
-rw-r--r--comm/XtMultiplexer.h2
-rw-r--r--comm/error.h2
11 files changed, 574 insertions, 443 deletions
diff --git a/comm/OLD/Agent.cc b/comm/OLD/Agent.cc
index ec4c28d..dadfd3c 100644
--- a/comm/OLD/Agent.cc
+++ b/comm/OLD/Agent.cc
@@ -104,7 +104,7 @@ whenever a client connects to the server, an instance of \typ{UchRemoteAgent} is
Whenever data is readable from a client, it is read in an input buffer and processed as soon
as a full message is received.
Whenever a client closes the connection, it is removed from the channel set of the server.
-This function returns TRUE if all went well, else it calls \fun{SysError} and returns FALSE.
+This function returns true if all went well, else it calls \fun{SysError} and returns false.
You may want to pass your own channel set if you are already multiplexing
i/o on that channel set. For instance, you may have several \typ{UchAgent} objects
in your application.
@@ -116,7 +116,7 @@ UchAgent :: Setup (UchBaseMultiplexer* cs)
{
if (Listen () < 0) {
SysError (ErrWarn, "UchAgent::Setup");
- return FALSE;
+ return false;
}
SetMode (IORead);
if (!cs)
@@ -124,7 +124,7 @@ UchAgent :: Setup (UchBaseMultiplexer* cs)
Mpx = cs;
Mpx->Add (this);
- return TRUE;
+ return true;
}
/*?
@@ -148,18 +148,12 @@ UchAgent :: Unlisten ()
void
UchAgent :: HandleRead ()
{
-// cannot redefine Accept to return UchRemoteAgent*, so this does not work :
-// UchRemoteAgent* cl = Accept ();
-// need to delete the channel created by Accept, so this does not work either :
-// UchRemoteAgent* cl = new UchRemoteAgent (Accept ());
-// so we do this (less elegant ...) :
- UchChannel* ch = Accept ();
- if (! ch) {
+ int fd = Accept ();
+ if (fd < 0) {
SysError (ErrWarn, "UchAgent::HandleRead: Accept");
return;
}
- UchRemoteAgent* ra = HandleNew (ch);
- delete ch;
+ UchRemoteAgent* ra = CreateRemote (fd);
ra->SetMode (IOReadSelect);
RemoteAgents.Append (ra);
@@ -171,9 +165,9 @@ UchAgent :: HandleRead ()
This virtual function is called whenever a new agent connects to this one.
?*/
UchRemoteAgent*
-UchAgent :: HandleNew (UchChannel* ch)
+UchAgent :: CreateRemote (int fd)
{
- return new UchRemoteAgent (this, ch);
+ return new UchRemoteAgent (this, fd);
}
/*?
@@ -234,7 +228,7 @@ UchAgent :: Run ()
/*?
Send a message to all the agents currently connected to this one.
-If \var{flush} is TRUE, the output buffer of each remote agent is flushed.
+If \var{flush} is true, the output buffer of each remote agent is flushed.
?*/
void
UchAgent :: Broadcast (UchMessage& msg, bool flush)
@@ -252,7 +246,7 @@ UchAgent :: Broadcast (UchMessage& msg, bool flush)
/*?
Send a message to all the agents currently connected to this one, except \var{exclude}.
-If \var{flush} is TRUE, the output buffer of each client is flushed.
+If \var{flush} is true, the output buffer of each client is flushed.
?*/
void
UchAgent :: Broadcast (UchMessage& msg, UchRemoteAgent* excl, bool flush)
@@ -352,11 +346,11 @@ UchRemoteAgent :: UchRemoteAgent (const UchRemoteAgent& cl)
/*?
Construct a new agent connected to this one on channel \var{ch}.
?*/
-UchRemoteAgent :: UchRemoteAgent (UchAgent* a, UchChannel* ch)
+UchRemoteAgent :: UchRemoteAgent (UchAgent* a, int fd)
: UchMsgStream (),
MyLocalAgent (a)
{
- UchChannel::Open (ch->FilDes ());
+ UchChannel::Open (fd);
}
UchRemoteAgent :: UchRemoteAgent (UchAgent* a, UchAddress* addr)
@@ -365,7 +359,7 @@ UchRemoteAgent :: UchRemoteAgent (UchAgent* a, UchAddress* addr)
{
if (!Setup ())
SysError (ErrWarn, "Connect");
- SetSyncMode (TRUE);
+ SetSyncMode (true);
}
diff --git a/comm/OLD/Agent.h b/comm/OLD/Agent.h
index 2db4b18..9b270af 100644
--- a/comm/OLD/Agent.h
+++ b/comm/OLD/Agent.h
@@ -51,12 +51,12 @@ inline UchBaseMultiplexer* GetMultiplexer () { return Mpx; }
MPX_RES Run ();
void Unlisten ();
- void Broadcast (UchMessage&, bool = FALSE);
- void Broadcast (UchMessage&, UchRemoteAgent*, bool = FALSE);
- void Broadcast (UchMsgBuffer&, bool = FALSE);
- void Broadcast (UchMsgBuffer&, UchRemoteAgent*, bool = FALSE);
+ void Broadcast (UchMessage&, bool = false);
+ void Broadcast (UchMessage&, UchRemoteAgent*, bool = false);
+ void Broadcast (UchMsgBuffer&, bool = false);
+ void Broadcast (UchMsgBuffer&, UchRemoteAgent*, bool = false);
-virtual UchRemoteAgent* HandleNew (UchChannel*);
+virtual UchRemoteAgent* CreateRemote (int);
virtual void HandleRemove (UchRemoteAgent*);
virtual bool SysError (errtype, const char*, int = 0, int = 0);
virtual void Error (errtype, const char*, const char*);
@@ -73,7 +73,7 @@ public:
UchRemoteAgent (UchAgent*);
UchRemoteAgent (const UchRemoteAgent& cl);
UchRemoteAgent (UchAgent*, UchAddress*);
- UchRemoteAgent (UchAgent*, UchChannel* ch);
+ UchRemoteAgent (UchAgent*, int);
~UchRemoteAgent ();
UchChannel* Copy () const;
diff --git a/comm/OLD/TextServer.cc b/comm/OLD/TextServer.cc
index 4b9ac14..5808fba 100644
--- a/comm/OLD/TextServer.cc
+++ b/comm/OLD/TextServer.cc
@@ -19,6 +19,12 @@
#include "PortServer.h"
#include <stdio.h>
+#ifdef __osf__
+extern "C" {
+ int accept (int, struct sockaddr*, int*);
+}
+#endif
+
/* every REG_TIME milliseconds, the server registers to the port server
we want this time to be shorter than the REG_TIME of the port server.
half the value of the port server's REG_TIME seems reasonable */
@@ -64,9 +70,9 @@ if \typ{MY_CLIENT} is the derived class of \var{UchTextClient} defined
by the application and \var{s} is this server.
?*/
UchTextServer :: UchTextServer (const char* serv, fNEW_CLIENT newcl)
-: UchStream (new UchInetAddress (ANYADDR), 0),
+: UchStream (new UchInetAddress (ANYADDR, 0), 0),
Timer (0),
- ok (FALSE),
+ ok (false),
Clients ()
{
service = serv;
@@ -93,15 +99,15 @@ UchTextServer :: Init (UchBaseMultiplexer& mpx)
{
if (Listen () < 0) { // calls Setup
SysError (ErrWarn, "UchTextServer::Setup");
- return FALSE;
+ return false;
}
mpx.Add (*this);
- ok = TRUE;
+ ok = true;
char buf [128];
sprintf (buf, "listening on port #%d", (void*) ((UchInetAddress*) BoundTo ())->Port ());
- Error (ErrLog, "UchTextServer::Init", buf);
+ ::Error (ErrLog, "UchTextServer::Init", buf);
Timer = new UchTextServerTimer (this);
- return TRUE;
+ return true;
}
/*?
@@ -117,7 +123,7 @@ UchTextServer :: Quit ()
{
if (! ok)
return;
- ok = FALSE;
+ ok = false;
// a bit tricky because of the smart pointers:
// each tstream probably is referenced only through the multiplexer
// removing it from the multiplexer hence deletes it.
@@ -156,7 +162,7 @@ UchTextServer :: Remove (UchTextClient* s)
int found = Clients.Remove (s);
if (!found)
- Error (ErrWarn, "UchTextServer::Remove", "stream not in client list");
+ ::Error (ErrWarn, "UchTextServer::Remove", "stream not in client list");
if (Mpx)
Mpx->Remove (*s);
@@ -220,7 +226,7 @@ UchTextClient :: UchTextClient (UchTextServer* s)
: UchTextStream (),
MyServer (s)
{
- sendToOut = FALSE;
+ sendToOut = false;
out = 0;
}
@@ -247,8 +253,8 @@ UchTextClient :: Starting ()
/*?
This protected virtual function is called by \fun{HandleRead} when
-an end-of-file is read (the argument is then TRUE) or when an error occured
-while reading (the argument is then FALSE).
+an end-of-file is read (the argument is then true) or when an error occured
+while reading (the argument is then false).
It calls the server's \fun{Remove} function for this client,
which should result in the destruction of the client.
This virtual function can be redefined in derived classes, but the
@@ -321,7 +327,7 @@ If \var{ch} is 0, output is simply discarded.
void
UchTextClient :: SetOutput (UchChannel* ch)
{
- sendToOut = TRUE;
+ sendToOut = true;
out = ch;
}
@@ -332,6 +338,6 @@ void
UchTextClient :: ResetOutput ()
{
out = 0;
- sendToOut = FALSE;
+ sendToOut = false;
}
diff --git a/comm/OLD/TextStream.cc b/comm/OLD/TextStream.cc
index 65f461c..445add6 100644
--- a/comm/OLD/TextStream.cc
+++ b/comm/OLD/TextStream.cc
@@ -22,6 +22,308 @@
#include <stdio.h>
#include <ctype.h>
+extern int windex (const char* list, const char* word);
+
+#ifdef __osf__
+extern "C" {
+ int socket (int, int, int);
+}
+#endif
+
+/*?
+Construct a \typ{UchTextStream}.
+?*/
+UchTextStream :: UchTextStream ()
+: UchBufStream ()
+{
+}
+
+/*?
+Protected destructor.
+\fun{Close} must be used instead to properly close down a \typ{UchTextStream}
+?*/
+UchTextStream :: ~UchTextStream ()
+{
+}
+
+/*?
+This virtual function is called by \fun{HandleRead} when an end of file
+is read (the argument is then \var{true}), or when an error occured while
+reading (the argument is then \var{false}).
+The default action is to call \fun{Close}.
+?*/
+void
+UchTextStream :: Closing (bool)
+{
+ Close ();
+}
+
+/*?
+Read and decode input. When a complete line (terminated either by
+a newline or cr-newline) is in the input buffer, it is parsed.
+If parsing is successful, \fun{Execute} is called with the line as argument.
+If \fun{Execute} returns \var{isCmdUnknown}, \fun{TryPredefined} is called
+to decode the predefined commands.
+Finally, \fun{ProcessCmdResult} is called and the line is flushed from
+the input buffer.
+Note that since the parsed line passed to \fun{Execute} contains pointers
+to the input buffer, \fun{Execute} {\em must not} keep copies of these
+pointers, but copy the contents instead.
+?*/
+void
+UchTextStream :: HandleRead ()
+{
+ if (ReadInput () <= 0)
+ return;
+
+ Process (InBuffer);
+}
+
+void
+UchTextStream :: Process (UchMsgBuffer& buf)
+{
+ // scan buffer for complete commands
+ char* start = (char*) buf.Buffer ();
+ char* stop = start + buf.BufLength ();
+ for (char* p = start; p < stop; p++) {
+ if (*p == '\n') {
+ *p = '\0';
+ // check cr-nl sequence
+ if (p > start && *(p-1) == '\r')
+ *(p-1) = '\0';
+ // parse line, lookup command
+ UchTextLine line;
+ cmd_res res = isCmdUnknown;
+ if (line.Parse (start)) {
+ if (line.NumWords () == 0)
+ res = isCmdOk;
+ else
+ res = Execute (line);
+ if (res == isCmdUnknown)
+ res = TryPredefined (line);
+ } else
+ res = isCmdSyntax;
+ ProcessCmdResult (res, line);
+ // reset for scanning rest of buffer
+ start = p+1;
+ buf.Flush ((byte*) start);
+ }
+ }
+}
+
+/*?
+Process the result \var{res} of the execution of the line \var{line}.
+If \var{res} is one of \var{isCmdSyntax}, \var{isCmdUnknown}, \var{isCmdError},
+a warning message is issued.
+If \var{res} is \var{isCmdClose} (resp. \var{isCmdQuit}), the virtual function
+\fun{Close} (resp. \fun{Quit}) is called.
+If \var{res} is \var{isCmdTerminate} (resp. \var{isCmdAbort}),
+the global function \fun{MpxTerminate} (resp. \fun{MpxAbort}) is called.
+If \var{res} is \var{isCmdExit}, \fun{exit(1)} is called.
+Finally, if \var{res} is \var{isCmdOk}, nothing happens.
+?*/
+void
+UchTextStream :: ProcessCmdResult (cmd_res res, const UchTextLine& line)
+{
+ const char* msg = 0;
+ switch (res) {
+ case isCmdSyntax:
+ msg = "syntax error in <%s>";
+ break;
+ case isCmdUnknown:
+ msg = "unknown command: <%s>";
+ break;
+ case isCmdOk:
+ return;
+ case isCmdError:
+ msg = "error while executing command <%s>";
+ break;
+ case isCmdClose:
+ // like eof (but smarter for the session)
+ Close ();
+ return;
+ case isCmdQuit:
+ //quit application
+ Quit ();
+ return;
+ case isCmdTerminate:
+ // terminate the multiplexer
+ if (Mpx)
+ Mpx->Close ();
+ return;
+ case isCmdAbort:
+ // abort the multiplexer
+ if (Mpx)
+ Mpx->Abort ();
+ return;
+ case isCmdExit:
+ exit (1);
+ }
+ if (msg) {
+ char buf [64];
+ line.Unparse (buf, sizeof (buf));
+ fprintf (stderr, "UchTextStream::ProcessCmdResult\n", msg, buf);
+ }
+}
+
+/*?
+If \var{line} is one of the words
+\com{Close}, \com{Quit}, \com{Terminate}, \com{Abort}, \com{Exit},
+the corresponding code is returned (\var{isCmdClose}, etc.),
+otherwise, \var{isCmdUnknown} is returned.
+?*/
+UchTextStream::cmd_res
+UchTextStream :: TryPredefined (const UchTextLine& line)
+{
+ const char* cname = line [0];
+
+ if (line.NumWords () != 1)
+ return isCmdUnknown;
+ switch (windex (":Close:Quit:Terminate:Abort:Exit:", cname)) {
+ case 1: return isCmdClose;
+ case 2: return isCmdQuit;
+ case 3: return isCmdTerminate;
+ case 4: return isCmdAbort;
+ case 5: return isCmdExit;
+ }
+ return isCmdUnknown;
+}
+
+void
+UchTextStream :: Send (const char* l, bool flush)
+{
+ OutBuffer.Append (l, false);
+ if (flush || Sync || OutBuffer.BufLength () >= OutSize)
+ Flush ();
+}
+
+void
+UchTextStream :: Send (const UchTextLine& l, bool flush)
+{
+ l.Unparse (&OutBuffer);
+ OutBuffer.WriteChar ('\n');
+ if (flush || Sync || OutBuffer.BufLength () >= OutSize)
+ Flush ();
+}
+
+/*?
+By default, it writes the output buffer on the stream.
+?*/
+void
+UchTextStream :: Flush ()
+{
+ Write (OutBuffer);
+}
+
+/*?
+This virtual function is called by \fun{ProcessCmdResult} when a \com{close}
+command has been received.
+It can be called directly by the application to close down the connection
+(remember that the destructor is private and cannot be called directly).
+By default it calls \fun{MpxRemoveChannel} to unregister this stream from the
+multiplexer.
+This will trigger deletion of the stream is the multiplexer holds the last
+smart pointer to it.
+Derived classes can redefine this function, but the redefinition
+should call the default implementation.
+?*/
+void
+UchTextStream :: Close ()
+{
+ Mpx->Remove (*this);
+}
+
+/*?
+This virtual function is called by \fun{ProcessCmdResult} when a \com{quit}
+command has been received.
+By default is calls \fun{MpxTerminate}.
+Derived classes can redefine this function if they want to terminate more
+gracefully.
+?*/
+void
+UchTextStream :: Quit ()
+{
+ Mpx->Close ();
+}
+
+
+void
+UchTextStream :: Emit (lword l)
+{
+
+ char c [1];
+ sprintf (c, "%d", l);
+ OutBuffer << c;
+}
+
+void
+UchTextStream :: Emit (sword s)
+{
+ char c [1];
+ sprintf (c, "%d", s);
+ OutBuffer << c;
+}
+
+void
+UchTextStream :: Emit (byte b)
+{
+ char c [1];
+ sprintf (c, "%d", b);
+ OutBuffer << c;
+}
+
+void
+UchTextStream :: Emit (char c)
+{
+ OutBuffer << c;
+}
+
+void
+UchTextStream :: Emit (const char* s)
+{
+ OutBuffer << s;
+}
+
+
+
+void
+UchTextStream :: Receive (lword& l)
+{
+ InBuffer >> l;
+}
+
+void
+UchTextStream :: Receive (sword& s)
+{
+ InBuffer >> s;
+}
+
+void
+UchTextStream :: Receive (byte& b)
+{
+ InBuffer >> b;
+}
+
+void
+UchTextStream :: Receive (char& c)
+{
+ InBuffer >> c;
+}
+
+void
+UchTextStream :: Receive (char* s)
+{
+ InBuffer >> s;
+}
+
+void
+UchTextStream :: Receive (CcuString& s)
+{
+ InBuffer >> s;
+}
+
+
+
// list is a set of words
// the separator must be the first and last char of the string:
// e.g. :yes:no: /foo/bar/toto/
@@ -243,8 +545,8 @@ UchTextLine :: Parse (char* line)
if (where != IN_SPACE)
AddWord (word);
if (where == IN_QUOTE)
- return FALSE;
- return TRUE;
+ return false;
+ return true;
}
// decompile line into buffer
@@ -329,13 +631,13 @@ UchTextLine :: Unparse (UchMsgBuffer* buf) const
}
}
if (*quotes)
- buf->Append (quotes [0]);
- buf->Append (sa, FALSE /*no newline*/);
+ buf->WriteChar (quotes [0]);
+ buf->Append (sa, false /*no newline*/);
if (*quotes)
- buf->Append (quotes [1]);
+ buf->WriteChar (quotes [1]);
// separator with next one
if (i < Num -1)
- buf->Append (' ');
+ buf->WriteChar (' ');
}
return start;
}
@@ -344,10 +646,10 @@ bool
UchTextLine :: Match (const char* cmdname, const char* profile) const
{
if (Num <= 0)
- return FALSE; // no word on line
+ return false; // no word on line
const char* myname = Words [0];
if (! myname || cmpname (myname, cmdname) != 0)
- return FALSE; // wrong command name
+ return false; // wrong command name
// check the profile, if it is non null.
// each letter in the profile corresponds to one argument:
@@ -361,17 +663,17 @@ UchTextLine :: Match (const char* cmdname, const char* profile) const
// *** we'll probably add features for repeated arguments,
// *** enums (mapping strings to ints), etc.
if (! profile)
- return TRUE;
+ return true;
const char* p = profile;
for (int i = 1; i < Num; i++) {
switch (*p) {
case 'i':
if (! Words [i].IsInt ())
- return FALSE;
+ return false;
break;
case 's':
if (! Words [i].IsString ())
- return FALSE;
+ return false;
break;
case 'b':
{
@@ -385,25 +687,25 @@ UchTextLine :: Match (const char* cmdname, const char* profile) const
Words[i].SetVal (0);
break;
}
- return FALSE;
+ return false;
}
case '+':
if (*(p+1)) // not at end of profile
fprintf (stderr, "UchTextLine::Match, invalid command profile: <%s>\n", profile);
- return TRUE;
+ return true;
case '\0':
// profile shorter than arg list
- return FALSE;
+ return false;
default:
fprintf (stderr, "UchTextLine::Match, invalid command profile: <%s>\n", profile);
- return FALSE;
+ return false;
}
p++;
}
if (*p)
- return FALSE; // arg list shorter than profile
- return TRUE;
+ return false; // arg list shorter than profile
+ return true;
}
// return -1 if word is not in the line, otherwise return its index
@@ -427,7 +729,7 @@ UchTextLine :: Index (int value) const
int i = 0;
for (; i < Num; i++, w++)
- if (w->IsInt () && *w == value)
+ if (w->IsInt () && value == int (*w))
return i;
return -1;
}
@@ -447,208 +749,6 @@ UchTextLine :: Index (int value) const
#define RETRY_TIME 2
#define MAX_RETRIES 5
-/*?
-Construct a \typ{UchTextStream}.
-?*/
-UchTextStream :: UchTextStream ()
-: UchStream (),
- InBuffer (256),
- OutBuffer (256)
-{
-}
-
-/*?
-Protected destructor.
-\fun{Close} must be used instead to properly close down a \typ{UchTextStream}
-?*/
-UchTextStream :: ~UchTextStream ()
-{
- // nothing
-}
-
-/*?
-This virtual function is called by \fun{HandleRead} when an end of file
-is read (the argument is then \var{TRUE}), or when an error occured while
-reading (the argument is then \var{FALSE}).
-The default action is to call \fun{Close}.
-?*/
-void
-UchTextStream :: Closing (bool)
-{
- Close ();
-}
-
-/*?
-Read and decode input. When a complete line (terminated either by
-a newline or cr-newline) is in the input buffer, it is parsed.
-If parsing is successful, \fun{Execute} is called with the line as argument.
-If \fun{Execute} returns \var{isCmdUnknown}, \fun{TryPredefined} is called
-to decode the predefined commands.
-Finally, \fun{ProcessCmdResult} is called and the line is flushed from
-the input buffer.
-Note that since the parsed line passed to \fun{Execute} contains pointers
-to the input buffer, \fun{Execute} {\em must not} keep copies of these
-pointers, but copy the contents instead.
-?*/
-void
-UchTextStream :: HandleRead ()
-{
- InBuffer.NeedSize (128);
- int n = Read (InBuffer);
- if (n <= 0) {
- Closing (n < 0 ? FALSE : TRUE);
- return;
- }
-
- // scan buffer for complete commands
- char* start = (char*) InBuffer.Buffer ();
- char* stop = start + InBuffer.BufLength ();
- for (char* p = start; p < stop; p++) {
- if (*p == '\n') {
- *p = '\0';
- // check cr-nl sequence
- if (p > start && *(p-1) == '\r')
- *(p-1) = '\0';
- // parse line, lookup command
- UchTextLine line;
- cmd_res res = isCmdUnknown;
- if (line.Parse (start)) {
- if (line.NumWords () == 0)
- res = isCmdOk;
- else
- res = Execute (line);
- if (res == isCmdUnknown)
- res = TryPredefined (line);
- } else
- res = isCmdSyntax;
- ProcessCmdResult (res, line);
- // reset for scanning rest of buffer
- start = p+1;
- InBuffer.Flush ((byte*) start);
- }
- }
-}
-
-/*?
-Process the result \var{res} of the execution of the line \var{line}.
-If \var{res} is one of \var{isCmdSyntax}, \var{isCmdUnknown}, \var{isCmdError},
-a warning message is issued.
-If \var{res} is \var{isCmdClose} (resp. \var{isCmdQuit}), the virtual function
-\fun{Close} (resp. \fun{Quit}) is called.
-If \var{res} is \var{isCmdTerminate} (resp. \var{isCmdAbort}),
-the global function \fun{MpxTerminate} (resp. \fun{MpxAbort}) is called.
-If \var{res} is \var{isCmdExit}, \fun{exit(1)} is called.
-Finally, if \var{res} is \var{isCmdOk}, nothing happens.
-?*/
-void
-UchTextStream :: ProcessCmdResult (cmd_res res, const UchTextLine& line)
-{
- const char* msg = 0;
- switch (res) {
- case isCmdSyntax:
- msg = "syntax error in <%s>";
- break;
- case isCmdUnknown:
- msg = "unknown command: <%s>";
- break;
- case isCmdOk:
- return;
- case isCmdError:
- msg = "error while executing command <%s>";
- break;
- case isCmdClose:
- // like eof (but smarter for the session)
- Close ();
- return;
- case isCmdQuit:
- //quit application
- Quit ();
- return;
- case isCmdTerminate:
- // terminate the multiplexer
- if (Mpx)
- Mpx->Close ();
- return;
- case isCmdAbort:
- // abort the multiplexer
- if (Mpx)
- Mpx->Abort ();
- return;
- case isCmdExit:
- exit (1);
- }
- if (msg) {
- char buf [64];
- line.Unparse (buf, sizeof (buf));
- fprintf (stderr, "UchTextStream::ProcessCmdResult\n", msg, buf);
- }
-}
-
-/*?
-If \var{line} is one of the words
-\com{Close}, \com{Quit}, \com{Terminate}, \com{Abort}, \com{Exit},
-the corresponding code is returned (\var{isCmdClose}, etc.),
-otherwise, \var{isCmdUnknown} is returned.
-?*/
-UchTextStream::cmd_res
-UchTextStream :: TryPredefined (const UchTextLine& line)
-{
- const char* cname = line [0];
-
- if (line.NumWords () != 1)
- return isCmdUnknown;
- switch (windex (":Close:Quit:Terminate:Abort:Exit:", cname)) {
- case 1: return isCmdClose;
- case 2: return isCmdQuit;
- case 3: return isCmdTerminate;
- case 4: return isCmdAbort;
- case 5: return isCmdExit;
- }
- return isCmdUnknown;
-}
-
-/*?
-This virtual function is called by the members that send commands on the stream.
-By defaults, it writes the output buffer on the stream.
-Derived classes can redefine this function.
-?*/
-void
-UchTextStream :: DoSend ()
-{
- Write (OutBuffer);
-}
-
-/*?
-This virtual function is called by \fun{ProcessCmdResult} when a \com{close}
-command has been received.
-It can be called directly by the application to close down the connection
-(remember that the destructor is private and cannot be called directly).
-By default it calls \fun{MpxRemoveChannel} to unregister this stream from the
-multiplexer.
-This will trigger deletion of the stream is the multiplexer holds the last
-smart pointer to it.
-Derived classes can redefine this function, but the redefinition
-should call the default implementation.
-?*/
-void
-UchTextStream :: Close ()
-{
- Mpx->Remove (*this);
-}
-
-/*?
-This virtual function is called by \fun{ProcessCmdResult} when a \com{quit}
-command has been received.
-By default is calls \fun{MpxTerminate}.
-Derived classes can redefine this function if they want to terminate more
-gracefully.
-?*/
-void
-UchTextStream :: Quit ()
-{
- Mpx->Close ();
-}
-
//---------------- ServiceStarter
class UchServiceStarter : public UchBaseTimeOut {
@@ -718,7 +818,7 @@ UchTextService :: UchTextService ()
: UchTextStream (),
StatusFlag (isLost),
Starter (0),
- Closed (FALSE),
+ Closed (false),
User (),
Service (),
Host ()
@@ -733,7 +833,7 @@ UchTextService :: UchTextService (UchBaseMultiplexer& mpx, const char* s, const
: UchTextStream (),
StatusFlag (isLost),
Starter (0),
- Closed (FALSE),
+ Closed (false),
User (),
Service (),
Host ()
@@ -803,7 +903,7 @@ UchTextService :: Restart ()
ConnectTo (addr);
bool wasopened = Fd.Opened ();
- bool setup = TRUE;
+ bool setup = true;
if (wasopened) {
// we are in trouble because a stream socket can be connected
// only once and a channel is immutable...
@@ -814,7 +914,7 @@ UchTextService :: Restart ()
int nfd = socket (ConnectedTo () ->Family (), SockType (), 0);
// fprintf (stderr, "UchTextService::Restart, reopening socket: %d -> %d\n", (void*) ofd, (void*) nfd);
if (nfd < 0) {
- setup = FALSE;
+ setup = false;
} else if (nfd != ofd) {
dup2 (nfd, ofd);
close (nfd);
@@ -905,8 +1005,8 @@ void
UchTextService :: GotServer ()
{
Mpx->SetMode (*this, IORead);
- if (OutBuffer.BufLength ())
- DoSend ();
+ if (OutBuffer.BufLength () != 0)
+ Flush ();
}
/*?
@@ -937,7 +1037,7 @@ UchTextService :: Execute (const UchTextLine&)
}
/*?
-This implementation of the protected virtual function \fun{UchTextStream::DoSend}
+This implementation of the protected virtual function \fun{UchBufStream::Flush}
writes the output buffer only if the state of the connection is
\var{isRunning}.
Otherwise, the outgoing requests accumulate in the ouput buffer until the
@@ -946,7 +1046,7 @@ This function also closes down the connection by calling \var{MpxRemoveChannel}
if \fun{Close} has been called before the connection ws actually established.
?*/
void
-UchTextService :: DoSend ()
+UchTextService :: Flush ()
{
if (StatusFlag == isRunning) {
Write (OutBuffer);
@@ -977,9 +1077,9 @@ UchTextService :: Init (UchBaseMultiplexer& mpx, const char* s, const char* h)
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");
+ ::Error (ErrLog, "TSERVICE::Init", "trying to run agentman");
if (execlp ("agentman", "agentman", 0) != 0)
- Error (ErrWarn, "TSERVICE::Init", "could not run agentman");
+ ::Error (ErrWarn, "TSERVICE::Init", "could not run agentman");
}
}
// delay retry
@@ -1017,7 +1117,7 @@ and then the connection will be closed.
void
UchTextService :: Close ()
{
- Closed = TRUE;
+ Closed = true;
if (StatusFlag == isRunning || OutBuffer.BufLength () == 0)
Mpx->Remove (*this);
}
@@ -1044,6 +1144,6 @@ TellServer (const char* sname, const char* host, const char* req)
serv->Init (sname, host);
serv->Send (req);
serv->Close ();
- return TRUE;
+ return true;
}
#endif
diff --git a/comm/OLD/TextStream.h b/comm/OLD/TextStream.h
index d7527ad..3c919f7 100644
--- a/comm/OLD/TextStream.h
+++ b/comm/OLD/TextStream.h
@@ -18,56 +18,12 @@
#include "cplus_bugs.h"
#include "Stream.h"
#include "MsgBuffer.h"
+#include "MsgStream.h"
#include "ccu/String.h"
-class UchTextWord {
-protected:
- const char* Sval;
- int Ival;
-public:
-inline UchTextWord () : Sval (0), Ival (0) {}
-inline UchTextWord (const char* s) { SetVal (s); }
-inline UchTextWord (int i) { SetVal (i); }
- void SetVal (const char*);
-inline void SetVal (int i) { Sval = 0; Ival = i; }
-inline bool IsInt () const { return (Sval == 0) ? TRUE : FALSE; }
-inline bool IsString () const { return (Sval != 0) ? TRUE : FALSE; }
- const char* GetQuotes () const;
-inline operator int () const { return Ival; }
-inline operator const char* () const { return Sval; }
-};
-
-
-class UchTextLine {
-protected:
- int Num;
- int Max;
- UchTextWord* Words;
-void NewWord (const char* s, int i);
+class UchTextLine;
-public:
- UchTextLine ();
- ~UchTextLine ();
-inline UchTextWord& operator [] (int i) const { return Words [i]; }
-inline int NumWords () const { return Num; }
-inline void AddWord (const char* s) { NewWord (s, 0); }
-inline void AddWord (int i) { NewWord (0, i); }
- void AddTrailer (const UchTextLine&, int);
-inline UchTextLine& operator << (int i) { AddWord (i); return *this; }
-inline UchTextLine& operator << (const char* s) { AddWord (s); return *this; }
-inline UchTextLine& operator << (const UchTextLine& l) { AddTrailer (l, 0); return *this; }
- bool Parse (char*);
- char* Unparse (char* dest, int len) const;
- char* Unparse (UchMsgBuffer*) const;
- bool Match (const char*, const char* = 0) const;
- int Index (const char*) const;
- int Index (int) const;
-inline bool Contains (const char* w) const { return (Index (w) == -1) ? FALSE : TRUE; }
-inline bool Contains (int i) const { return (Index (i) == -1) ? FALSE : TRUE; }
-inline void Reset () { Num = 0; }
-};
-
-class UchTextStream : public UchStream {
+class UchTextStream : public UchBufStream {
public:
enum cmd_res {
isCmdSyntax, // syntax error when parsing command
@@ -80,31 +36,40 @@ enum cmd_res {
isCmdAbort, // abort multiplexer
isCmdExit // call exit
};
-protected:
- UchMsgBuffer InBuffer;
- UchMsgBuffer OutBuffer;
-virtual void Closing (bool);
+protected:
+ void Closing (bool);
void HandleRead ();
+ void Process (UchMsgBuffer&);
+ void Flush ();
+
void ProcessCmdResult (cmd_res, const UchTextLine&);
cmd_res TryPredefined (const UchTextLine&);
virtual cmd_res Execute (const UchTextLine&) = 0;
-virtual void DoSend ();
+
+ void Emit (lword);
+ void Emit (sword);
+ void Emit (byte);
+ void Emit (char);
+ void Emit (const char*);
+
+ void Receive (lword&);
+ void Receive (sword&);
+ void Receive (byte&);
+ void Receive (char&);
+ void Receive (char*);
+ void Receive (CcuString&);
+
public:
UchTextStream ();
~UchTextStream ();
- UchTextStream (const UchTextStream&);
+// UchTextStream (const UchTextStream&);
// UchChannel* Copy () const;
virtual void Close (); // 'close' request
virtual void Quit (); // 'quit' request
-inline void Append (const char* l) { OutBuffer.Append (l, FALSE); }
-inline void Append (const UchTextLine& l) { l.Unparse (&OutBuffer); OutBuffer.Append ('\n');}
-inline UchTextStream& operator << (const char* l) { Append (l); return *this; }
-inline UchTextStream& operator << (const UchTextLine& l) { Append (l); return *this; }
-inline void Send () { DoSend (); }
-inline void Send (const char* l) { Append (l); DoSend (); }
-inline void Send (const UchTextLine& l) { Append (l); DoSend (); }
+ void Send (const char*, bool = false);
+ void Send (const UchTextLine&, bool = false);
};
class UchTextService : public UchTextStream {
@@ -115,7 +80,7 @@ enum status {
isUnavailable, // address not found in port server
isError, // could not init connection
isRunning, // connection established
- isLost, // no connection (auto-starting)
+ isLost // no connection (auto-starting)
};
protected:
@@ -127,13 +92,13 @@ protected:
CcuString Host;
void Closing (bool);
+ void Flush ();
status Restart ();
void AutoStart (int = -1, int = -1);
virtual void LostServer ();
virtual void GotServer ();
virtual void AbandonRestart ();
cmd_res Execute (const UchTextLine&);
- void DoSend ();
public:
UchTextService (UchBaseMultiplexer&, const char*, const char* = 0);
@@ -151,4 +116,52 @@ public:
// the simplest interface to a server.
extern bool TellServer (const char*, const char*, const char*);
+class UchTextWord {
+protected:
+ const char* Sval;
+ int Ival;
+public:
+inline UchTextWord () : Sval (0), Ival (0) {}
+inline UchTextWord (const char* s) { SetVal (s); }
+inline UchTextWord (int i) { SetVal (i); }
+ void SetVal (const char*);
+inline void SetVal (int i) { Sval = 0; Ival = i; }
+inline bool IsInt () const { return (Sval == 0) ? true : false; }
+inline bool IsString () const { return (Sval != 0) ? true : false; }
+ const char* GetQuotes () const;
+inline operator int () const { return Ival; }
+inline operator const char* () const { return Sval; }
+};
+
+
+class UchTextLine {
+protected:
+ int Num;
+ int Max;
+ UchTextWord* Words;
+void NewWord (const char* s, int i);
+
+public:
+ UchTextLine ();
+ ~UchTextLine ();
+inline UchTextWord& operator [] (int i) const { return Words [i]; }
+inline int NumWords () const { return Num; }
+inline void AddWord (const char* s) { NewWord (s, 0); }
+inline void AddWord (int i) { NewWord (0, i); }
+ void AddTrailer (const UchTextLine&, int);
+inline UchTextLine& operator << (int i) { AddWord (i); return *this; }
+inline UchTextLine& operator << (const char* s) { AddWord (s); return *this; }
+inline UchTextLine& operator << (const UchTextLine& l) { AddTrailer (l, 0); return *this; }
+ bool Parse (char*);
+ char* Unparse (char* dest, int len) const;
+ char* Unparse (UchMsgBuffer*) const;
+ bool Match (const char*, const char* = 0) const;
+ int Index (const char*) const;
+ int Index (int) const;
+inline bool Contains (const char* w) const { return (Index (w) == -1) ? false : true; }
+inline bool Contains (int i) const { return (Index (i) == -1) ? false : true; }
+inline void Reset () { Num = 0; }
+};
+
+
#endif /* TextStream_H_ */
diff --git a/comm/OLD/dgram.cc b/comm/OLD/dgram.cc
index 28e50d1..712c1be 100644
--- a/comm/OLD/dgram.cc
+++ b/comm/OLD/dgram.cc
@@ -15,6 +15,7 @@
#include "MsgBuffer.h"
#include "dgram.h"
#include "error.h"
+#include "Message.h"
#include <sys/ioctl.h>
#include <errno.h>
@@ -24,7 +25,13 @@
// needed only if DEBUG is active
#include <stdio.h>
#define DEBUG //**//
-bool DGTrace = FALSE;
+bool DGTrace = false;
+
+#ifdef __osf__
+extern "C" {
+ int ioctl (int, unsigned long, char*);
+}
+#endif
/*?class UchDGRAM
The class \typ{UchDGRAM} is derived from \typ{UchDatagram}.
@@ -76,10 +83,10 @@ UchDGRAM :: Init ()
ninput = 0;
fromAddr = 0;
retry = 5;
- resend = FALSE;
+ resend = false;
locked = 0;
timeout = 1000;
- sync = FALSE;
+ sync = false;
}
/*?nextdoc?*/
@@ -151,9 +158,9 @@ DEBUG SysError (ErrWarn, "UchDGRAM::GetInput")
DEBUG if (DGTrace) printf ("UchDGRAM :: GetInput : received %d bytes\n", buf->BufLength ());
lword id;
- buf->Get (id);
+ buf->ReadLong (id);
byte s;
- buf->Get (s);
+ buf->ReadByte (s);
DEBUG if (DGTrace) printf ("UchDGRAM :: GetInput : id %x byte %d\n", id, s);
if (s == DGRAM_ACK) {
@@ -178,14 +185,14 @@ UchDGRAM :: CheckInput ()
for (;;) {
lword np;
if (ioctl (FilDes (), FIONREAD, (char*) &np) < 0)
- return FALSE;
+ return false;
DEBUG if (DGTrace) if (np) printf ("UchDGRAM :: CheckInput : FIONREAD says %d\n", np);
if (np == 0)
break;
if (GetInput (int (np)) == DGRAM_ERR)
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/*?hidden?*/
@@ -194,17 +201,17 @@ UchDGRAM :: WaitInput ()
{
// check the input queue
if (ninput)
- return TRUE;
+ return true;
// check pending input
if (! CheckInput ())
- return FALSE;
+ return false;
// block until something
while (! ninput)
if (GetInput (2048) == DGRAM_ERR) // *** arbitrary max size
- return FALSE;
- return TRUE;
+ return false;
+ return true;
}
/*?hidden?*/
@@ -212,8 +219,8 @@ bool
UchDGRAM :: Wait (lword id)
{
DEBUG if (DGTrace) printf ("UchDGRAM::Wait %x\n", id);
- bool ret = FALSE;
- bool loop = TRUE;
+ bool ret = false;
+ bool loop = true;
Lock ();
PENDING* pend;
@@ -224,7 +231,7 @@ DEBUG if (DGTrace) printf ("UchDGRAM::Wait %x\n", id);
// did we receive the ack ?
pend = pending.Get (id);
if (! pend) {
- ret = TRUE;
+ ret = true;
break;
}
@@ -239,10 +246,10 @@ DEBUG if (DGTrace) printf ("UchDGRAM::Wait : resending\n");
if (n < 0)
break;
--pend->retries;
- resend = FALSE;
+ resend = false;
} else
DEBUG if (DGTrace) printf ("UchDGRAM::Wait : waiting\n"),
- timer.Wait (); // sets resend to TRUE
+ timer.Wait (); // sets resend to true
}
Unlock ();
DEBUG if (DGTrace) printf ("UchDGRAM::Wait : %s\n", ret ? "done" : "failed");
@@ -260,8 +267,8 @@ void
UchDGRAM :: SendAck (lword id, UchAddress& addr)
{
UchMsgBuffer buf;
- buf.Append (id);
- buf.Append (DGRAM_ACK);
+ buf.WriteLong (id);
+ buf.WriteByte (DGRAM_ACK);
SendBuffer (buf, addr);
fromAddr = & addr;
DEBUG if (DGTrace) printf ("UchDGRAM :: SendAck : acknowledging %x\n", id);
@@ -272,7 +279,7 @@ void
UchDGRAM :: Expired ()
{
if (locked)
- resend = TRUE;
+ resend = true;
else
Resend ();
}
@@ -292,8 +299,8 @@ UchAddress* toCopy = new UchInetAddress (ia->Host (), ia->Port ());
outId = pending.Store (out);
DEBUG if (DGTrace) printf ("UchDGRAM :: PrepareToSend : id %x\n", outId);
- obuf->Append (outId);
- obuf->Append (DGRAM_SEND);
+ obuf->WriteLong (outId);
+ obuf->WriteByte (DGRAM_SEND);
if (! npending) {
timer.ChangePeriod (timeout);
@@ -309,7 +316,7 @@ int
UchDGRAM :: SendBuffer (UchMsgBuffer& buf, UchAddress& addr)
{
int n;
- while ((n = UchDatagram :: Send (buf, addr, TRUE)) == -1 && errno == EINTR)
+ while ((n = UchDatagram :: Send (buf, addr, true)) == -1 && errno == EINTR)
DEBUG SysError (ErrWarn, "UchDGRAM::SendBuffer")
;
return n;
@@ -321,7 +328,7 @@ UchDGRAM :: RemovePending (lword id)
{
PENDING* pend = pending.Get (id);
if (! pend) {
- Error (ErrWarn, "Receive", "unrecognized ACK");
+ ::Error (ErrWarn, "Receive", "unrecognized ACK");
return;
}
pending.Remove (id);
@@ -340,7 +347,7 @@ UchDGRAM :: Send (byte* buf, int len, UchAddress& to, bool ack, int retries)
DEBUG if (DGTrace) printf ("UchDGRAM :: Send\n");
Lock ();
UchMsgBuffer* obuf = PrepareToSend (to, retries);
- obuf->Append (buf, len);
+ obuf->WriteBuf (buf, len);
int n = SendBuffer (*obuf, to);
CheckInput ();
int ret = (ack || sync) ? (Wait (outId) ? n : -1) : n;
@@ -383,7 +390,7 @@ UchDGRAM :: Send (UchMsgBuffer& buf, UchAddress& to, bool peek, bool ack, int re
DEBUG if (DGTrace) printf ("UchDGRAM :: Send\n");
Lock ();
UchMsgBuffer* obuf = PrepareToSend (to, retries);
- obuf->Append (buf.Buffer (), buf.BufLength ());
+ obuf->WriteBuf (buf.Buffer (), buf.BufLength ());
if (! peek)
buf.Flush ();
int n = SendBuffer (*obuf, to);
@@ -403,7 +410,7 @@ DEBUG if (DGTrace) printf ("UchDGRAM :: Receive\n");
PENDING* p = input.RemoveFirst ();
ninput--;
int n = p->outBuf->BufLength ();
- buf.Append (p->outBuf->Buffer (), n);
+ buf.WriteBuf (p->outBuf->Buffer (), n);
SendAck (p->id, *p->toAddr);
delete p;
DEBUG if (DGTrace) printf ("UchDGRAM :: Receive : received buffer %d bytes\n", n);
@@ -417,7 +424,7 @@ except that they manage messages acknowledgement.
is received.
\fun{Receive} acknowledges the received message.
\fun{Reply} sends the message to the sender of the last received message.
-If \var{ack} is TRUE, the acknowledge of the message is waited for.
+If \var{ack} is true, the acknowledge of the message is waited for.
In that case, \fun{Send} returns -1 if the acknowledge is not received.
If \var{retries} is non zero, it specifies a number of retries for this message
different from the default retry number of this dgram.
@@ -437,7 +444,7 @@ UchDGRAM :: Send (UchMessage& msg, UchAddress& to, bool ack, int retries)
DEBUG if (DGTrace) printf ("UchDGRAM :: Send message\n");
Lock ();
UchMsgBuffer* obuf = PrepareToSend (to, retries);
- obuf->Append (msg);
+ obuf->WriteMsg (msg);
// int l;
// printf ("outBuffer is %d bytes long\n", l = obuf->BufLength ());
// for (int i = 0; i < l; i++) printf ("%02x ", obuf->Buffer () [i]);
@@ -446,7 +453,7 @@ DEBUG if (DGTrace) printf ("UchDGRAM :: Send message\n");
CheckInput ();
bool ret;
if (ack || sync)
- ret = Wait (outId) ? TRUE : FALSE;
+ ret = Wait (outId) ? true : false;
else
ret = bool (n != obuf->BufLength ());
Unlock ();
@@ -459,27 +466,27 @@ UchDGRAM :: Receive (UchMessage* msg)
{
DEBUG if (DGTrace) printf ("UchDGRAM :: Receive message\n");
if (! WaitInput ())
- return FALSE;
+ return false;
PENDING* p = input.RemoveFirst ();
ninput--;
// int n;
// printf ("inBuffer is %d bytes long\n", n = p->outBuf->BufLength ());
// for (int i = 0; i < n; i++) printf ("%02x ", p->outBuf->Buffer () [i]);
// printf ("\n");
- if (! p->outBuf->Get (*msg))
- return FALSE;
+ if (! p->outBuf->ReadMsg (*msg))
+ return false;
SendAck (p->id, *p->toAddr);
delete p;
DEBUG if (DGTrace) printf ("UchDGRAM :: Receive : received message\n");
- return TRUE;
+ return true;
}
/*?
These functions are similar to the previous functions except that they take
a \typ{UchMessage} as argument.
\fun{Send} converts the message in the output buffer.
-If \var{ack} is TRUE, the acknowledge of the message is waited for.
-In that case, \fun{Send} returns FALSE if the acknowledge is not received.
+If \var{ack} is true, the acknowledge of the message is waited for.
+In that case, \fun{Send} returns false if the acknowledge is not received.
If \var{retries} is non zero, it specifies a number of retries for this message
different from the default retry number of this dgram.
\fun{Receive} converts the incoming data into the message passed as argument.
@@ -490,7 +497,7 @@ bool
UchDGRAM :: Reply (UchMessage& msg, bool ack, int retries)
{
if (! fromAddr)
- return FALSE;
+ return false;
return Send (msg, *fromAddr, ack, retries);
}
@@ -502,10 +509,10 @@ UchDGRAM :: Ask (UchMessage& msg, UchAddress& to)
DEBUG if (DGTrace) printf ("UchDGRAM :: Ask\n");
Lock ();
UchMsgBuffer* obuf = PrepareToSend (to, DGRAM_ASK *******);
- obuf->Append (msg);
+ obuf->WriteMsg (msg);
int n = SendBuffer (*obuf, to);
CheckInput ();
- bool ret = Wait (outId) ? TRUE : FALSE;
+ bool ret = Wait (outId) ? true : false;
if (ret) {
// wait answer
for (;;) {
@@ -535,7 +542,7 @@ if (DGTrace) printf ("UchDGRAM::Resend\n");
if (npending)
CheckInput ();
if (! npending) {
- resend = FALSE;
+ resend = false;
Unlock ();
return;
}
@@ -550,8 +557,8 @@ if (DGTrace) printf ("UchDGRAM::Resend\n");
UchMsgBuffer fake (*pend->outBuf);
lword id;
byte typ;
- fake.Get (id);
- fake.Get (typ);
+ fake.ReadLong (id);
+ fake.ReadByte (typ);
if (! DiscardNotify (fake, *pend->toAddr)) {
pend->retries = retry; // *** should be controllable ?
continue;
@@ -571,7 +578,7 @@ DEBUG printf ("UchDGRAM::Resend : resending %x\n", iter.CurId ());
DEBUG else printf ("UchDGRAM::Resend : skipping %x\n", iter.CurId ());
}
- resend = FALSE;
+ resend = false;
Unlock ();
}
@@ -579,14 +586,14 @@ DEBUG else printf ("UchDGRAM::Resend : skipping %x\n", iter.CurId ());
This virtual function is called whenever a pending message is about
to be discarded because no acknowledge has been received after
the the default number of retries.
-If it returns FALSE, the message is not discarded and its retry count is reset to zero.
-Returning FALSE is not very social.
-The default action is to return TRUE, thus discarding the pending message.
+If it returns false, the message is not discarded and its retry count is reset to zero.
+Returning false is not very social.
+The default action is to return true, thus discarding the pending message.
?*/
bool
UchDGRAM :: DiscardNotify (UchMsgBuffer&, UchAddress&)
{
- return TRUE;
+ return true;
}
/*?
@@ -621,23 +628,23 @@ This virtual function is called by \fun{HandleRead}.
It must be redefined in a derived class if \fun{HandleRead} is to be used
(for instance if this \typ{UchDGRAM} is put in a channel set).
This function should convert the contents of the buffer into a message, and handle it.
-It should return TRUE if the message was correctly handled, else FALSE.
-Note that if it returns FALSE, the message will not be acknowledged, and thus it will
+It should return true if the message was correctly handled, else false.
+Note that if it returns false, the message will not be acknowledged, and thus it will
be resent later.
The default behaviour of this virtual function is to issue an error message and
-to return TRUE.
+to return true.
?*/
bool
UchDGRAM :: NewMessage (UchMsgBuffer&)
{
- Error (ErrWarn, "UchDGRAM :: NewMessage", "should be defined in derived class");
- return TRUE;
+ ::Error (ErrWarn, "UchDGRAM :: NewMessage", "should be defined in derived class");
+ return true;
}
/*?
This is an instance of the virtual function \fun{HandleRead} of class \typ{UchChannel}.
It calls the virtual function \fun{NewMessage} when a message is received.
-If \fun{NewMessage} returns TRUE, an acknowledge is sent back.
+If \fun{NewMessage} returns true, an acknowledge is sent back.
This functions also handles incoming acknowledges.
?*/
void
@@ -659,21 +666,21 @@ DEBUG if (DGTrace) printf ("<<UchDGRAM :: HandleRead\n");
/*?
This is an instance of the virtual function \fun{HandleSelect} of class \typ{UchChannel}.
It calls the virtual function \fun{NewMessage} when a message is in the input buffer.
-If \fun{NewMessage} returns TRUE, an acknowledge is sent back.
+If \fun{NewMessage} returns true, an acknowledge is sent back.
This functions also handles incoming acknowledges.
?*/
bool
UchDGRAM :: HandleSelect ()
{
if (! ninput)
- return FALSE;
+ return false;
DEBUG if (DGTrace) printf (">>UchDGRAM :: HandleSelect\n");
PENDING* p = input.RemoveFirst ();
ninput--;
if (NewMessage (* p->outBuf))
SendAck (p->id, *p->toAddr);
DEBUG if (DGTrace) printf ("<<UchDGRAM :: HandleSelect\n");
- return TRUE;
+ return true;
}
#ifdef DOC
@@ -703,8 +710,8 @@ UchDGRAM :: SetRetry (short r)
/*?
Set the synchronous mode of this \typ{UchDGRAM}.
-If \var{s} is TRUE, the \fun{Send} functions always wait for the acknowledge of the messages.
-The default value is FALSE.
+If \var{s} is true, the \fun{Send} functions always wait for the acknowledge of the messages.
+The default value is false.
?*/
void
UchDGRAM :: SetSync (bool s)
diff --git a/comm/OLD/dgram.h b/comm/OLD/dgram.h
index 43dff17..b2f9f77 100644
--- a/comm/OLD/dgram.h
+++ b/comm/OLD/dgram.h
@@ -70,17 +70,17 @@ public:
UchDGRAM (UchAddress*, UchAddress*);
~UchDGRAM ();
- int Send (byte*, int, UchAddress&, bool = FALSE, int retries = 0);
+ int Send (byte*, int, UchAddress&, bool = false, int retries = 0);
int Receive (byte*, int);
- int Reply (byte*, int, bool = FALSE, int retries = 0);
+ int Reply (byte*, int, bool = false, int retries = 0);
- int Send (UchMsgBuffer&, UchAddress&, bool = FALSE, bool = FALSE, int retries = 0);
+ int Send (UchMsgBuffer&, UchAddress&, bool = false, bool = false, int retries = 0);
int Receive (UchMsgBuffer&);
- int Reply (UchMsgBuffer&, bool = FALSE, bool = FALSE, int retries = 0);
+ int Reply (UchMsgBuffer&, bool = false, bool = false, int retries = 0);
- bool Send (UchMessage&, UchAddress&, bool = FALSE, int retries = 0);
+ bool Send (UchMessage&, UchAddress&, bool = false, int retries = 0);
bool Receive (UchMessage* msg);
- bool Reply (UchMessage&, bool = FALSE, int retries = 0);
+ bool Reply (UchMessage&, bool = false, int retries = 0);
virtual bool DiscardNotify (UchMsgBuffer&, UchAddress&);
diff --git a/comm/OLD/portserv.cc b/comm/OLD/portserv.cc
index 7719be5..3b66348 100644
--- a/comm/OLD/portserv.cc
+++ b/comm/OLD/portserv.cc
@@ -17,7 +17,7 @@
#include "error.h"
#include "Multiplexer.h"
#include "Datagram.h"
-#include "Signal.h"
+#include "SignalHandler.h"
#include "ccu/List.h"
#include "ccu/RegExp.h"
#include "ccu/String.h"
@@ -29,7 +29,18 @@
#include <errno.h>
#include <signal.h>
#include <stdio.h>
+#ifdef __osf__
+extern "C" {
+#endif
#include <netdb.h>
+#ifdef __osf__
+}
+#endif
+#ifdef __osf__
+extern "C" {
+ int setsockopt (int, int, int, char*, int);
+}
+#endif
//---------------- globals
// if SaveTime > 0, the state is saved to SaveFile
@@ -42,7 +53,7 @@ int SaveFileIsFd = -1;
int SaveTime = 0;
int Mod = 0;
int NbEntries = 0;
-bool Trace = FALSE;
+bool Trace = false;
UchMultiplexer* Mpx = 0;
const char* LoadFile;
@@ -220,7 +231,7 @@ LoadConfigFile ()
strcpy (nline, line);
char** words = ParseConfigLine (nline);
if (! words) {
- Error (ErrWarn, "LoadConfigFile", "incorrect line ignored in file");
+ ::Error (ErrWarn, "LoadConfigFile", "incorrect line ignored in file");
delete nline;
continue;
}
@@ -231,8 +242,8 @@ LoadConfigFile ()
s->Host = 0;
s->Port = 0;
s->Ident = 0;
- s->AutoLaunch = TRUE;
- s->Running = FALSE;
+ s->AutoLaunch = true;
+ s->Running = false;
s->LastRun= 0;
s->LastRegistered = 0;
s->CmdLine = nline;
@@ -282,7 +293,7 @@ RegisterService (const char* key, lword host, sword port, int id)
if (! s) {
s = new Service;
s->Key = key;
- s->AutoLaunch = FALSE;
+ s->AutoLaunch = false;
s->LastRun = 0;
s->CmdLine = 0;
s->RunCmd = 0;
@@ -293,7 +304,7 @@ RegisterService (const char* key, lword host, sword port, int id)
s->Ident = id;
CcuTimeStamp now;
s->LastRegistered = now;
- s->Running = TRUE;
+ s->Running = true;
return s;
}
@@ -316,7 +327,7 @@ RemoveService (const char* key, lword host, sword port, int id)
#endif
if (host == s->Host && port == s->Port && id == s->Ident && strcmp (key, s->Key) == 0) {
if (s->AutoLaunch) {
- s->Running = FALSE;
+ s->Running = false;
s->LastRun = 0;
s->LastRegistered = 0;
s->Host = 0;
@@ -327,12 +338,12 @@ RemoveService (const char* key, lword host, sword port, int id)
delete s;
ServList.RemoveAfter (trailing_iter);
}
- return TRUE;
+ return true;
}
++trailing_iter;
}
- Error (ErrWarn, key, "not found for remove");
- return FALSE;
+ ::Error (ErrWarn, key, "not found for remove");
+ return false;
}
Service*
@@ -372,7 +383,7 @@ InquireService (const char* key)
AutoLaunch (s);
return s;
}
- Error (ErrWarn, key, "not found");
+ ::Error (ErrWarn, key, "not found");
return 0;
}
@@ -482,8 +493,8 @@ RegistrationChannel :: HandleRead ()
return;
}
- if (! buf.Get (req)) {
- Error (ErrWarn, "Receive", "could not read message");
+ if (! buf.ReadMsg (req)) {
+ ::Error (ErrWarn, "Receive", "could not read message");
return;
}
@@ -516,7 +527,7 @@ RegistrationChannel :: HandleRead ()
ans.Port = 0;
}
buf.Flush ();
- buf.Append (ans);
+ buf.WriteMsg (ans);
if (Reply (buf) < 0)
SysError (ErrWarn, "reply");
}
@@ -536,13 +547,13 @@ RegistrationChannel :: HandleRead ()
if (Trace) printf ("quit\n");
if (SaveTime)
DumpToFile ();
- KillProcesses (TRUE);
+ KillProcesses (true);
Mpx->Close ();
break;
default:
if (Trace) printf ("unknown\n");
- Error (ErrWarn, "Receive", "unknown request");
+ ::Error (ErrWarn, "Receive", "unknown request");
}
}
@@ -571,7 +582,7 @@ if (Trace) printf ("Match: %s\n", (const char*) s->Key);
ans.Host = s->Host;
ans.Port = s->Port;
ans.SetKey (s->Key);
- buf.Append (ans);
+ buf.WriteMsg (ans);
Reply (buf);
nb++;
}
@@ -581,7 +592,7 @@ if (Trace) printf ("Match: %s\n", (const char*) s->Key);
ans.Type = PortServEndMatch;
ans.Ident = nb;
ans.SetKey (0);
- buf.Append (ans);
+ buf.WriteMsg (ans);
Reply (buf);
}
@@ -602,8 +613,8 @@ public:
BroadcastChannel (sword, UchInetAddress*);
bool SetUp ();
void HandleRead ();
- void RegisterMe () { printf ("RegisterMe: %d\n", Send (registerBuf, *bcast, TRUE /*peek*/)); }
- void RemoveMe () { Send (removeBuf, *bcast, TRUE /*peek*/); printf ("sending remove\n"); }
+ void RegisterMe () { printf ("RegisterMe: %d\n", Send (registerBuf, *bcast, true /*peek*/)); }
+ void RemoveMe () { Send (removeBuf, *bcast, true /*peek*/); printf ("sending remove\n"); }
};
lword
@@ -628,7 +639,7 @@ BroadcastChannel :: BroadcastChannel (sword port, UchInetAddress* reg_addr)
if (! l)
l = cuserid (0);
if (! l)
- Error (ErrFatal, "BroadcastChannel", "getlogin failed");
+ ::Error (ErrFatal, "BroadcastChannel", "getlogin failed");
/* prepare answerBuf for future requests */
char key [32];
@@ -637,11 +648,11 @@ BroadcastChannel :: BroadcastChannel (sword port, UchInetAddress* reg_addr)
sword reg_port = reg_addr->Port ();
int pid = getpid ();
UchPortServerReq reg (PortServRegister, reg_host, reg_port, pid, key);
- registerBuf.Append (reg);
+ registerBuf.WriteMsg (reg);
UchPortServerReq rem (PortServRemove, reg_host, reg_port, pid, key);
- removeBuf.Append (rem);
+ removeBuf.WriteMsg (rem);
UchPortServerReq ans (PortServAnswer, reg_host, reg_port, pid, key);
- answerBuf.Append (ans);
+ answerBuf.WriteMsg (ans);
}
bool
@@ -649,16 +660,16 @@ BroadcastChannel :: SetUp ()
{
int on = 1;
if (! UchDatagram::Setup ())
- return FALSE;
- if (setsockopt (FilDes (), SOL_SOCKET, SO_BROADCAST, (const char*) &on, sizeof (on)) < 0)
- return FALSE;
- return TRUE;
+ return false;
+ if (setsockopt (FilDes (), SOL_SOCKET, SO_BROADCAST, (char*) &on, sizeof (on)) < 0)
+ return false;
+ return true;
}
void
BroadcastChannel :: Answer ()
{
- int res = Send (answerBuf, *bcast, TRUE /*peek*/);
+ int res = Send (answerBuf, *bcast, true /*peek*/);
printf ("AnswerMe: %d\n", res);
}
@@ -676,8 +687,8 @@ BroadcastChannel :: HandleRead ()
SysError (ErrFatal, "BroadcastChannel", EINTR);
return;
}
- if (! buf.Get (req)) {
- Error (ErrWarn, "BroadcastChannel", "could not read message");
+ if (! buf.ReadMsg (req)) {
+ ::Error (ErrWarn, "BroadcastChannel", "could not read message");
return;
}
@@ -686,7 +697,7 @@ BroadcastChannel :: HandleRead ()
case PortServRegister:
RegisterService (req.Key, req.Host, req.Port, int (req.Ident));
Modified ();
- printf ("received registration %s 0x%x %d %d\n", req.Key, req.Host, req.Port, req.Ident);
+ printf ("received registration %s 0x%x %d %d\n", (const char*) req.Key, req.Host, req.Port, req.Ident);
// when somebody else registers, we send our address
Answer ();
break;
@@ -699,7 +710,7 @@ BroadcastChannel :: HandleRead ()
case PortServAnswer:
RegisterService (req.Key, req.Host, req.Port, int (req.Ident));
Modified ();
- printf ("received answer %s 0x%x %d %d\n", req.Key, req.Host, req.Port, req.Ident);
+ printf ("received answer %s 0x%x %d %d\n", (const char*) req.Key, req.Host, req.Port, req.Ident);
break;
case PortServRemove:
@@ -708,7 +719,7 @@ BroadcastChannel :: HandleRead ()
break;
default:
- Error (ErrWarn, "main", "unknown request");
+ ::Error (ErrWarn, "main", "unknown request");
}
}
@@ -737,24 +748,24 @@ GetPortNumber (const char* servname, int dflt)
void
Usage ()
{
- Error (ErrUsage, "portserv", "[-t] [-s service] [-quit] [-save file [time]] [-load file]");
+ ::Error (ErrUsage, "portserv", "[-t] [-s service] [-quit] [-save file [time]] [-load file]");
}
main (int argc, const char** argv)
{
const char* servname = "portserv";
int running = 1;
- bool qflag = FALSE;
+ bool qflag = false;
ProgramName (argv [0]);
LoadFile = getenv ("AGENTMGRCF");
while (--argc) {
++argv;
if (strcmp (*argv, "-quit") == 0) {
- qflag = TRUE;
+ qflag = true;
} else
if (strcmp (*argv, "-t") == 0) {
- Trace = TRUE;
+ Trace = true;
} else
if (strcmp (*argv, "-s") == 0) {
if (--argc < 1)
@@ -788,7 +799,7 @@ main (int argc, const char** argv)
// the portserver that is running
if (qflag) {
if (SaveFile || LoadFile)
- Error (ErrFatal, "-quit", "incompatible with -save or -load");
+ ::Error (ErrFatal, "-quit", "incompatible with -save or -load");
UchPortServer ps (servname, 0);
ps.Quit ();
exit (0);
@@ -824,7 +835,7 @@ main (int argc, const char** argv)
//
sword reg_port = GetPortNumber (servname, 3003);
if (! reg_port)
- Error (ErrFatal, servname, "service not available");
+ ::Error (ErrFatal, servname, "service not available");
// open dgram socket
//
@@ -846,7 +857,7 @@ main (int argc, const char** argv)
delete bc_chan;
bc_chan = 0;
} else {
- Error (ErrLog, "main", "created broadcast channel");
+ ::Error (ErrLog, "main", "created broadcast channel");
bc_chan->SetMode (IORead);
bc_chan->RegisterMe ();
mpx.Add (bc_chan);
diff --git a/comm/XtMultiplexer.cc b/comm/XtMultiplexer.cc
index edd2409..fbd49b5 100644
--- a/comm/XtMultiplexer.cc
+++ b/comm/XtMultiplexer.cc
@@ -116,7 +116,7 @@ MPX_RES
UchXtMultiplexer :: Loop ()
{
XEvent event;
- bool waiting = TRUE;
+ bool waiting = true;
while (Looping && (waiting || ReadCount || WriteCount)) {
// *** problem with other loop: work proc are not called!
@@ -125,10 +125,10 @@ UchXtMultiplexer :: Loop ()
XtNextEvent (&event);
XtDispatchEvent (&event);
if (ReadCount || WriteCount)
- waiting = FALSE;
+ waiting = false;
}
if (Looping) {
- Looping = FALSE;
+ Looping = false;
return isMpxEmpty;
}
return isMpxTerminated;
diff --git a/comm/XtMultiplexer.h b/comm/XtMultiplexer.h
index 164a296..6ce1301 100644
--- a/comm/XtMultiplexer.h
+++ b/comm/XtMultiplexer.h
@@ -18,7 +18,7 @@
#include "Multiplexer.h"
-/*** Intrinsic.h redefines TRUE and FALSE if FALSE is undefined... */
+/*** Intrinsic.h redefines true and false if false is undefined... */
#define FALSE 0
#include <X11/Intrinsic.h>
#undef FALSE
diff --git a/comm/error.h b/comm/error.h
index a0d11ef..340d3a0 100644
--- a/comm/error.h
+++ b/comm/error.h
@@ -43,7 +43,7 @@ typedef errtype (*ErrorHandler) (errtype, const char* who, const char* what, con
typedef void (*CleanUpProc) ();
extern void ProgramName (const char*);
-extern void LogfileName (const char*, bool = FALSE);
+extern void LogfileName (const char*, bool = false);
extern void CleanUp (CleanUpProc);
extern ErrorHandler SetErrorHandler (ErrorHandler);