summaryrefslogtreecommitdiff
path: root/comm/MsgBuffer.cc
diff options
context:
space:
mode:
authorsc2000-11-28 17:07:47 +0000
committersc2000-11-28 17:07:47 +0000
commitee937667fd0ecd82faab4c88d756b906fb625f1a (patch)
tree19e679318b5cb87e8be1a05a7bbc9ba5568d0814 /comm/MsgBuffer.cc
parent1326b11d65f7020f5f6c691305d2c090b064bd04 (diff)
downloadivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.zip
ivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.tar.gz
ivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.tar.bz2
ivy-league-ee937667fd0ecd82faab4c88d756b906fb625f1a.tar.xz
Integration into IvyLeague
Uvh -> Ivl Multiplexer.* is renamed into Scheduler.* A few name conflicts in the merger with ex-DNN have been solved Imakefile is replaced by Makefile Created InetAddress.* and UnixAddress.* from Address.* Created IrdaAddress.* OLD/TextStream has been updated
Diffstat (limited to 'comm/MsgBuffer.cc')
-rw-r--r--comm/MsgBuffer.cc139
1 files changed, 65 insertions, 74 deletions
diff --git a/comm/MsgBuffer.cc b/comm/MsgBuffer.cc
index 225c764..55cec65 100644
--- a/comm/MsgBuffer.cc
+++ b/comm/MsgBuffer.cc
@@ -14,7 +14,7 @@
#include "MsgBuffer.h"
#include "Message.h"
-#include "ccu/String.h"
+#include "ivl/String.h"
#include <stdlib.h>
#include <string.h>
@@ -23,15 +23,15 @@
// management of buffers
// The buffer is said to be allocated if Begin is non zero.
// There is a special constructor that builds an allocated buffer with Begin = 0 :
-// UchMsgBuffer (UchMsgBuffer&, int len)
+// IvlMsgBuffer (IvlMsgBuffer&, int len)
// This buffer can only be read from and flushed
// This is useful for creating a fake buffer that is actually a pointer to
// a subpart of the original one. Thus, the new buffer can be safely read from
// without eating too far away
//
-/*?class UchMsgBuffer
-A \typ{UchMsgBuffer} is an array of bytes of a given size that can be partially filled.
+/*?class IvlMsgBuffer
+A \typ{IvlMsgBuffer} is an array of bytes of a given size that can be partially filled.
The buffer may grow whenever bytes are appended to it.
The initial size, the increments and the maximum sizes can be defined.
If the buffer exceeds its maximal size, it will be deleted when it becomes empty
@@ -54,8 +54,8 @@ Construct an empty buffer.
The buffer will be allocated with a default size whenever data is appended to it.
This default size is currently 128 bytes.
?*/
-UchMsgBuffer :: UchMsgBuffer ()
-: UchIOS ()
+IvlMsgBuffer :: IvlMsgBuffer ()
+: IvlIOS ()
{
Begin = Start = Stop = End = 0;
GetErr = false;
@@ -66,8 +66,8 @@ UchMsgBuffer :: UchMsgBuffer ()
/*?
Construct a buffer with \var{sz} bytes.
?*/
-UchMsgBuffer :: UchMsgBuffer (int sz)
-: UchIOS ()
+IvlMsgBuffer :: IvlMsgBuffer (int sz)
+: IvlIOS ()
{
MinSize = GrowSize = sz = pad (sz);
Begin = Start = Stop = new byte [sz];
@@ -80,8 +80,8 @@ UchMsgBuffer :: UchMsgBuffer (int sz)
Construct a buffer with minimum \var{sz} bytes, growing by \var{grow} bytes,
until a maximum size of \var{max} bytes.
?*/
-UchMsgBuffer :: UchMsgBuffer (int sz, int grow, int max)
-: UchIOS ()
+IvlMsgBuffer :: IvlMsgBuffer (int sz, int grow, int max)
+: IvlIOS ()
{
MinSize = sz = pad (sz);
Begin = Start = Stop = new byte [sz];
@@ -102,8 +102,8 @@ Note that the contents of the fake buffer can be overwritten if you read and the
the original buffer.
The rule of thumb is to avoid modifying the original buffer while there is a fake buffer on it.
?*/
-UchMsgBuffer :: UchMsgBuffer (const UchMsgBuffer& b, int l)
-: UchIOS (b)
+IvlMsgBuffer :: IvlMsgBuffer (const IvlMsgBuffer& b, int l)
+: IvlIOS (b)
{
Begin = 0;
Start = b.Start;
@@ -118,7 +118,7 @@ UchMsgBuffer :: UchMsgBuffer (const UchMsgBuffer& b, int l)
}
/*?nodoc?*/
-UchMsgBuffer :: ~UchMsgBuffer ()
+IvlMsgBuffer :: ~IvlMsgBuffer ()
{
Clear ();
}
@@ -129,7 +129,7 @@ The buffer can still be used after this function has been called (it will reallo
The destructor calls this function.
?*/
void
-UchMsgBuffer :: Clear ()
+IvlMsgBuffer :: Clear ()
{
if (Begin)
delete Begin;
@@ -137,11 +137,11 @@ UchMsgBuffer :: Clear ()
}
/*?
-Insure that a UchMsgBuffer.has at least \var{sz} free bytes.
+Insure that a IvlMsgBuffer.has at least \var{sz} free bytes.
The buffer may be reallocated with a new size to provide the necessary space.
?*/
void
-UchMsgBuffer :: NeedSize (int sz)
+IvlMsgBuffer :: NeedSize (int sz)
{
// brand new buffer
if (! Begin) {
@@ -183,9 +183,9 @@ Discard the \var{n} first bytes of a buffer, or the whole buffer if \var{n} is n
If the buffer becomes empty and had exceeded its maximum size, it is reset.
?*/
void
-UchMsgBuffer :: Flush (int n)
+IvlMsgBuffer :: Flush (int n)
{
-//printf ("UchMsgBuffer %x : Flush (%d)\n", this, n);
+//printf ("IvlMsgBuffer %x : Flush (%d)\n", this, n);
if (! Begin)
if (! End) // ! Begin && End => fake buffer
return;
@@ -205,7 +205,7 @@ This can be used when the buffer has been accessed through \fun{Buffer ()}
and you want to flush until a given position in the buffer.
?*/
void
-UchMsgBuffer :: Flush (byte* p)
+IvlMsgBuffer :: Flush (byte* p)
{
if (p >= Start && p <= Stop)
Flush (p - Start);
@@ -222,7 +222,7 @@ Note that the buffer can always grow as big as necessary to hold the appended da
the maximum size is only used to reallocate the buffer whenever it becomes empty.
?*/
void
-UchMsgBuffer :: SetSizes (int min, int grow, int max)
+IvlMsgBuffer :: SetSizes (int min, int grow, int max)
{
if (min >= 0)
MinSize = pad (min);
@@ -244,7 +244,7 @@ Append the \var{n} first bytes of \var{buf} to the buffer.
All append functions call \fun{NeedSize} so that appending always succeeds.
?*/
void
-UchMsgBuffer :: WriteBuf (const byte* buf, int n)
+IvlMsgBuffer :: WriteBuf (const byte* buf, int n)
{
GetErr = false;
if (! Begin || End - Stop < n)
@@ -255,7 +255,7 @@ UchMsgBuffer :: WriteBuf (const byte* buf, int n)
/*?nextdoc?*/
void
-UchMsgBuffer :: WriteByte (byte b)
+IvlMsgBuffer :: WriteByte (byte b)
{
GetErr = false;
if (! Begin || End - Stop < 1)
@@ -263,17 +263,16 @@ UchMsgBuffer :: WriteByte (byte b)
*Stop++ = b;
}
-
/*?nextdoc?*/
void
-UchMsgBuffer :: WriteChar (char c)
+IvlMsgBuffer :: WriteChar (char c)
{
WriteByte ((byte) c);
}
/*?nextdoc?*/
void
-UchMsgBuffer :: WriteLong (lword l)
+IvlMsgBuffer :: WriteLong (lword l)
{
WriteBuf ((const byte*)&l, lwsize);
}
@@ -283,14 +282,13 @@ Append a short word, a long word, a byte or a character to a buffer.
The buffer is extended as necessary.
?*/
void
-UchMsgBuffer :: WriteShort (sword s)
+IvlMsgBuffer :: WriteShort (sword s)
{
WriteBuf ((const byte*)&s, swsize);
}
-
void
-UchMsgBuffer :: WriteString (const char* s)
+IvlMsgBuffer :: WriteString (const char* s)
{
Append (s);
}
@@ -301,7 +299,7 @@ If the second argument is \var{true}, the terminating null byte is appended, els
If the string is the null pointer, nothing is appended to the buffer.
?*/
void
-UchMsgBuffer :: Append (const char* s, bool nullbyte)
+IvlMsgBuffer :: Append (const char* s, bool nullbyte)
{
if (! s)
return;
@@ -319,7 +317,7 @@ The virtual function \fun{WriteTo} of the buffer is called.
The length of the message is automatically computed and prepended to the message itself.
?*/
void
-UchMsgBuffer :: WriteMsg (UchMessage& msg)
+IvlMsgBuffer :: WriteMsg (IvlMessage& msg)
{
GetErr = false;
@@ -343,12 +341,11 @@ UchMsgBuffer :: WriteMsg (UchMessage& msg)
memcpy (p, &len, lwsize);
}
-
//----- get operations
//
bool
-UchMsgBuffer :: GetBuf (byte* b, int n, bool peek, int offset)
+IvlMsgBuffer :: GetBuf (byte* b, int n, bool peek, int offset)
{
if (GetErr)
return false;
@@ -364,10 +361,8 @@ UchMsgBuffer :: GetBuf (byte* b, int n, bool peek, int offset)
return true;
}
-
-
int
-UchMsgBuffer :: GetString (char* str, int n, const char* delim, bool peek, int offset)
+IvlMsgBuffer :: GetString (char* str, int n, const char* delim, bool peek, int offset)
{
if (GetErr)
return 0;
@@ -400,24 +395,23 @@ UchMsgBuffer :: GetString (char* str, int n, const char* delim, bool peek, int o
return i;
}
-
/*?nextdoc?*/
bool
-UchMsgBuffer :: ReadLong (lword& l)
+IvlMsgBuffer :: ReadLong (lword& l)
{
return GetBuf ((byte*) &l, lwsize, false);
}
/*?nextdoc?*/
bool
-UchMsgBuffer :: ReadShort (sword& s)
+IvlMsgBuffer :: ReadShort (sword& s)
{
return GetBuf ((byte*) &s, swsize, false);
}
/*?nextdoc?*/
bool
-UchMsgBuffer :: ReadByte (byte& b)
+IvlMsgBuffer :: ReadByte (byte& b)
{
return GetBuf (&b, 1, false);
}
@@ -428,17 +422,17 @@ Return true if the data was actually extracted, else return false and mark the b
If \var{peek} is true, the buffer is not flushed after extracting the data.
?*/
bool
-UchMsgBuffer :: ReadChar (char& c)
+IvlMsgBuffer :: ReadChar (char& c)
{
return GetBuf ((byte*) &c, 1, false);
}
/*?
-Extract a string from a buffer and copy it to a \typ{CcuString}.
+Extract a string from a buffer and copy it to a \typ{IvlString}.
This assumes that the string in the buffer is null-terminated.
?*/
int
-UchMsgBuffer :: ReadString (CcuString& s)
+IvlMsgBuffer :: ReadString (IvlString& s)
{
if (GetErr)
return 0;
@@ -463,14 +457,14 @@ If \var{peek} is true, the buffer is not flushed after extracting the data
?*/
bool
-UchMsgBuffer :: ReadBuf (byte* b, int n)
+IvlMsgBuffer :: ReadBuf (byte* b, int n)
{
return GetBuf (b, n, false);
}
/*?nextdoc?*/
int
-UchMsgBuffer :: ReadString (char* str, char delim, int n)
+IvlMsgBuffer :: ReadString (char* str, char delim, int n)
{
char ds [2];
ds [0] = delim;
@@ -480,7 +474,7 @@ UchMsgBuffer :: ReadString (char* str, char delim, int n)
/*?nextdoc?*/
int
-UchMsgBuffer :: ReadString (char* str, int n)
+IvlMsgBuffer :: ReadString (char* str, int n)
{
return GetString (str, n, 0, false);
}
@@ -493,21 +487,21 @@ The number of characters actually transferred is returned.
\var{str} is always terminated by a null character.
?*/
int
-UchMsgBuffer :: ReadString (char* str, const char* ds, int n)
+IvlMsgBuffer :: ReadString (char* str, const char* ds, int n)
{
return GetString (str, n, ds, false);
}
/*?
Get a message from the buffer.
-The message must be prefixed by its length, as done by \fun{Append(UchMessage*)}.
+The message must be prefixed by its length, as done by \fun{Append(IvlMessage*)}.
The virtual function \fun{ReadFrom} of the message is called to convert the buffer into a message.
If there is not enough data in the buffer, false is returned.
If \fun{ReadFrom} reads past the end of the message,
false is returned and the get error flag is set.
?*/
bool
-UchMsgBuffer :: ReadMsg (UchMessage& msg)
+IvlMsgBuffer :: ReadMsg (IvlMessage& msg)
{
if (GetErr || (Stop - Start < lwsize))
return false;
@@ -539,27 +533,25 @@ UchMsgBuffer :: ReadMsg (UchMessage& msg)
}
}
-
-
//------ peek operations
/*?nextdoc?*/
bool
-UchMsgBuffer :: PeekByte (byte& b, int offset)
+IvlMsgBuffer :: PeekByte (byte& b, int offset)
{
return GetBuf (&b, 1, true, offset);
}
/*?nextdoc?*/
bool
-UchMsgBuffer :: PeekShort (sword& sw, int offset)
+IvlMsgBuffer :: PeekShort (sword& sw, int offset)
{
return GetBuf ((byte*) &sw, swsize, true, offset);
}
/*?nextdoc?*/
bool
-UchMsgBuffer :: PeekLong (lword& lw, int offset)
+IvlMsgBuffer :: PeekLong (lword& lw, int offset)
{
return GetBuf ((byte*) &lw, lwsize, true, offset);
}
@@ -570,13 +562,13 @@ at \var{offset} bytes from the start of the buffer.
They return false if the data to peek falls outside the buffer, else true.
?*/
bool
-UchMsgBuffer :: PeekBuf (byte* b, int n, int offset)
+IvlMsgBuffer :: PeekBuf (byte* b, int n, int offset)
{
return GetBuf (b, n, true, offset);
}
int
-UchMsgBuffer :: PeekString (CcuString& s, int offset)
+IvlMsgBuffer :: PeekString (IvlString& s, int offset)
{
if (GetErr)
return 0;
@@ -594,7 +586,7 @@ UchMsgBuffer :: PeekString (CcuString& s, int offset)
/*?nextdoc?*/
int
-UchMsgBuffer :: PeekString (char* str, int n, char delim, int offset)
+IvlMsgBuffer :: PeekString (char* str, int n, char delim, int offset)
{
char ds [2];
ds [0] = delim;
@@ -610,12 +602,11 @@ The number of characters actually transferred is returned.
\var{str} is always terminated by a null character.
?*/
int
-UchMsgBuffer :: PeekString (char* str, int n, const char* delim, int offset)
+IvlMsgBuffer :: PeekString (char* str, int n, const char* delim, int offset)
{
return GetString (str, n, delim, true, offset);
}
-
//----- miscellaneous
//
@@ -633,7 +624,7 @@ if (nb > 0)
\end{ccode}
?*/
void
-UchMsgBuffer :: More (int n)
+IvlMsgBuffer :: More (int n)
{
GetErr = false;
if (End) // Begin == 0 for fake buffers
@@ -646,7 +637,7 @@ This is useful to remove erroneous data that has just been appended to the buffe
This is in some sense the reverse operation of \fun{More}.
?*/
void
-UchMsgBuffer :: Discard (int n)
+IvlMsgBuffer :: Discard (int n)
{
if (! Begin)
if (! End) // ! Begin && End => fake buffer
@@ -666,7 +657,7 @@ UchMsgBuffer :: Discard (int n)
/*?nextdoc?*/
byte*
-UchMsgBuffer :: Buffer ()
+IvlMsgBuffer :: Buffer ()
{ }
/*?
@@ -681,12 +672,12 @@ if (n > 0)
\end{ccode}
?*/
int
-UchMsgBuffer :: BufLength ()
+IvlMsgBuffer :: BufLength ()
{ }
/*?nextdoc?*/
byte*
-UchMsgBuffer :: Free ()
+IvlMsgBuffer :: Free ()
{ }
/*?
@@ -695,7 +686,7 @@ This may be used in conjunction with \fun{NeedSize} and \fun{More}
to append data to the buffer.
?*/
int
-UchMsgBuffer :: FreeLength ()
+IvlMsgBuffer :: FreeLength ()
{ }
/*?
@@ -703,7 +694,7 @@ Grow the buffer if its free size is less than its grow size.
This function can be called when a buffer is full.
?*/
void
-UchMsgBuffer :: Grow ()
+IvlMsgBuffer :: Grow ()
{ }
/*?
@@ -712,13 +703,13 @@ The type of the data can be a long word, a short word, a byte, a character, or a
for strings, the null character is included.
The operator returns the buffer so that several items can be added.
?*/
-UchMsgBuffer&
-UchMsgBuffer :: operator << (type data)
+IvlMsgBuffer&
+IvlMsgBuffer :: operator << (type data)
{ }
/*?nextdoc?*/
-UchMsgBuffer&
-UchMsgBuffer :: operator >> (type* data)
+IvlMsgBuffer&
+IvlMsgBuffer :: operator >> (type* data)
{ }
/*?
@@ -727,13 +718,13 @@ The type of the data can be a long word, a short word, a byte, or a character.
The operator returns the buffer so that several items can be read.
Errors can be tested by the functions \fun{Error} and \fun{Ok}.
?*/
-UchMsgBuffer&
-UchMsgBuffer :: operator >> (type& data)
+IvlMsgBuffer&
+IvlMsgBuffer :: operator >> (type& data)
{ }
/*?nextdoc?*/
bool
-UchMsgBuffer :: Error ()
+IvlMsgBuffer :: Error ()
{ }
/*?
@@ -742,7 +733,7 @@ Test the state of the buffer, as set by the get functions.
\fun{Ok} is the negation of \fun{Error}.
?*/
bool
-UchMsgBuffer :: Ok ()
+IvlMsgBuffer :: Ok ()
{ }
/*?
@@ -751,7 +742,7 @@ The error flag is automatically reset by the functions \fun{Append} and \fun{Mor
and by \fun{operator $<<$}.
?*/
void
-UchMsgBuffer :: ResetError ()
+IvlMsgBuffer :: ResetError ()
{ }
#endif /* DOC */