summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty2000-11-28 17:07:44 +0000
committerchatty2000-11-28 17:07:44 +0000
commit30f1d67e8b836760abd265f2fc0afeaba810d004 (patch)
tree9aa54f51f052082f021f76580dc1d327876bd820
parent421a701c93c6bd8afda7285b670ba3f264b10128 (diff)
downloadivy-league-30f1d67e8b836760abd265f2fc0afeaba810d004.zip
ivy-league-30f1d67e8b836760abd265f2fc0afeaba810d004.tar.gz
ivy-league-30f1d67e8b836760abd265f2fc0afeaba810d004.tar.bz2
ivy-league-30f1d67e8b836760abd265f2fc0afeaba810d004.tar.xz
Moved parts to BufStream
-rw-r--r--comm/MsgStream.cc190
-rw-r--r--comm/MsgStream.h53
2 files changed, 5 insertions, 238 deletions
diff --git a/comm/MsgStream.cc b/comm/MsgStream.cc
index 47a2a74..3a84eba 100644
--- a/comm/MsgStream.cc
+++ b/comm/MsgStream.cc
@@ -17,196 +17,6 @@
#include "error.h"
-/*?
-These constructors are similar to those of class \typ{UchSocket}.
-?*/
-UchBufStream :: UchBufStream (UchAddress* bindTo, UchAddress* connectTo)
-: UchStream (bindTo, connectTo),
- InBuffer (),
- OutBuffer (),
- OutSize (128),
- Sync (false)
-{
-}
-
-// *** this copy constructor might be automatically generated
-/*?nodoc?*/
-UchBufStream :: UchBufStream (const UchBufStream& ms)
-: UchStream (ms),
- InBuffer (),
- OutBuffer (),
- OutSize (ms.OutSize),
- Sync (ms.Sync)
-{
-}
-
-/*?nodoc?*/
-UchBufStream :: ~UchBufStream ()
-{
- Flush ();
- InBuffer.Clear ();
- OutBuffer.Clear ();
-}
-
-/*?nextdoc?*/
-void
-UchBufStream :: InputBuffer (int min, int grow, int max)
-{
- InBuffer.SetSizes (min, grow, max);
-}
-
-/*?
-Set the input and output buffer sizes.
-Default sizes are used if these functions are not called.
-?*/
-void
-UchBufStream :: OutputBuffer (int min, int grow, int max)
-{
- OutBuffer.SetSizes (min, grow, max);
- OutSize = max;
-}
-
-/*?
-Flush the output buffer.
-This function is called automatically when the buffer exceeds its flush size,
-or after each message when this stream is in synchronous mode.
-It is also called from \fun{Ask} to wait for the answer.
-?*/
-void
-UchBufStream :: Flush ()
-{
- if (OutBuffer.BufLength () == 0)
- return;
- int n = Write (OutBuffer);
- OutBuffer.Flush (n);
-}
-
-/*?nodoc?*/
-void
-UchBufStream :: HandleWrite ()
-{
- Flush ();
-}
-
-
-// read stream into input buffer
-// delete the stream when an eof is received
-// return the number of bytes read
-//
-/*?hidden?*/
-int
-UchBufStream :: ReadInput ()
-{
- if (InBuffer.BufLength () == 0)
- InBuffer.NeedSize (128);
- int n = Read (InBuffer);
- if (n <= 0) {
- if (n == -2) {
- InBuffer.Grow ();
- n = Read (InBuffer);
- }
- if (n < 0)
- SysError (ErrWarn, "UchBufStream::ReadInput");
- if (n <= 0)
- Closing (n < 0 ? false : true);
- }
- return n;
-}
-
-/*?
-This virtual function is called when an end of file is read,
-meaning that the communication is terminated.
-It is also called if an error occurs while reading.
-You can check the value of the global variable \var{errno}:
-if it is non zero, \fun{Closing} was called because of an error. % wrong
-By default this function does nothing.
-?*/
-void
-UchBufStream :: Closing (bool)
-{
-}
-
-
-void
-UchBufStream :: WriteLong (lword l)
-{
- OutBuffer << l;
-}
-
-void
-UchBufStream :: WriteShort (sword s)
-{
- OutBuffer << s;
-}
-
-void
-UchBufStream :: WriteByte (byte b)
-{
- OutBuffer << b;
-}
-
-void
-UchBufStream :: WriteChar (char c)
-{
- OutBuffer << c;
-}
-
-void
-UchBufStream :: WriteString (const char* s)
-{
- OutBuffer << s;
-}
-
-void
-UchBufStream :: WriteBuf (const byte* b, int n)
-{
- OutBuffer.WriteBuf (b, n);
-}
-
-bool
-UchBufStream :: ReadLong (lword& l)
-{
- return InBuffer.ReadLong (l);
-}
-
-bool
-UchBufStream :: ReadShort (sword& s)
-{
- return InBuffer.ReadShort (s);
-}
-
-bool
-UchBufStream :: ReadByte (byte& b)
-{
- return InBuffer.ReadByte (b);
-}
-
-bool
-UchBufStream :: ReadChar (char& c)
-{
- return InBuffer.ReadChar (c);
-}
-
-int
-UchBufStream :: ReadString (char* s, int n)
-{
- return InBuffer.ReadString (s, n);
-}
-
-int
-UchBufStream :: ReadString (CcuString& s)
-{
- return InBuffer.ReadString (s);
-}
-
-bool
-UchBufStream :: ReadBuf (byte* b, int n)
-{
- return InBuffer.ReadBuf (b, n);
-}
-
-
-
/*?class UchMsgStream
An object of class \typ{UchMsgStream} is a stream that sends and receives messages:
we call it a message stream.
diff --git a/comm/MsgStream.h b/comm/MsgStream.h
index 0ed867f..7660ae8 100644
--- a/comm/MsgStream.h
+++ b/comm/MsgStream.h
@@ -15,59 +15,16 @@
#ifndef MsgStream_H_
#define MsgStream_H_
-#include "Stream.h"
-#include "ccu/SmartPointer.h"
-#include "MsgBuffer.h"
+#include "BufStream.h"
class UchMessage;
-class UchBufStream : public UchStream {
-protected:
- UchMsgBuffer InBuffer;
- UchMsgBuffer OutBuffer;
- int OutSize;
- bool Sync;
-
- UchBufStream (const UchBufStream&);
- int ReadInput ();
- void HandleWrite ();
-
- void WriteLong (lword);
- void WriteShort (sword);
- void WriteByte (byte);
- void WriteChar (char);
- void WriteString (const char*);
- void WriteBuf (const byte*, int);
-
-
- bool ReadLong (lword&);
- bool ReadShort (sword&);
- bool ReadByte (byte&);
- bool ReadChar (char&);
- int ReadString (char*, int);
- int ReadString (CcuString&);
- bool ReadBuf (byte*, int);
-
-public:
- UchBufStream (UchAddress* = 0, UchAddress* = 0);
- ~UchBufStream ();
-
- void InputBuffer (int min, int grow, int max);
- void OutputBuffer (int min, int grow, int max);
-inline bool GetSyncMode () { return Sync; }
-inline void SetSyncMode (bool s) { Sync = s; Flush (); }
-inline void FlushSize (int n) { OutSize = n; }
-virtual void Flush ();
-
-virtual void Closing (bool);
-};
-
class UchMsgStream : public UchBufStream {
protected:
enum STATE { WAITING, GOT_TYPE, GOT_LENGTH, DONE};
enum TYPE { MSG = 1, ASK, ANS, SYNC, ASYNC, OK };
STATE State;
bool BufferedMessages;
- UchMsgBuffer Buffered;
+ UchMsgBuffer Buffered;
bool WaitingReply;
int InLength;
byte InType;
@@ -82,10 +39,10 @@ public:
~UchMsgStream ();
void HandleRead ();
-virtual UchMessage* DecodeMessage (UchMsgBuffer&);
-virtual UchMessage* DecodeAnswer (UchMsgBuffer&);
+virtual UchMessage* DecodeMessage (UchMsgBuffer&);
+virtual UchMessage* DecodeAnswer (UchMsgBuffer&);
void Send (UchMessage&, bool = false);
- UchMessage* Ask (UchMessage&);
+ UchMessage* Ask (UchMessage&);
void Reply (UchMessage&);
void Send (UchMsgBuffer&, bool = false);
};