summaryrefslogtreecommitdiff
path: root/comm/OLD/dgram.cc
diff options
context:
space:
mode:
authorchatty1994-05-10 11:36:23 +0000
committerchatty1994-05-10 11:36:23 +0000
commitb0fff9b9e5becf35cdd051a81d0574a3a6c3be2a (patch)
treef6e866161bb17587d344d0fbdf30cef57b435444 /comm/OLD/dgram.cc
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/OLD/dgram.cc')
-rw-r--r--comm/OLD/dgram.cc123
1 files changed, 65 insertions, 58 deletions
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)