summaryrefslogtreecommitdiff
path: root/comm/MsgStream.cc
diff options
context:
space:
mode:
authorchatty1993-11-29 15:45:14 +0000
committerchatty1993-11-29 15:45:14 +0000
commitf44633df7f1bea8920bcb5a2b39ee0c334e9da8d (patch)
tree7576b7daed74e1c4cbcdb8185f6df049a7802564 /comm/MsgStream.cc
parent2084a7c9423408d93ed917ba538bf6519c7c3b77 (diff)
downloadivy-league-f44633df7f1bea8920bcb5a2b39ee0c334e9da8d.zip
ivy-league-f44633df7f1bea8920bcb5a2b39ee0c334e9da8d.tar.gz
ivy-league-f44633df7f1bea8920bcb5a2b39ee0c334e9da8d.tar.bz2
ivy-league-f44633df7f1bea8920bcb5a2b39ee0c334e9da8d.tar.xz
Removed useless default constructor
Changed return type of Ask and ConvertAnswer
Diffstat (limited to 'comm/MsgStream.cc')
-rw-r--r--comm/MsgStream.cc171
1 files changed, 69 insertions, 102 deletions
diff --git a/comm/MsgStream.cc b/comm/MsgStream.cc
index 2f6f741..5f27e04 100644
--- a/comm/MsgStream.cc
+++ b/comm/MsgStream.cc
@@ -86,18 +86,6 @@ redefine the virtual functions \fun{NewMessage} and \fun{ConvertAnswer}.
// ---- no byte swapping ...
// ---- no locked sync mode ...
-/*?nextdoc?*/
-UchMsgStream :: UchMsgStream ()
-: UchStream (), InBuffer (), OutBuffer (), Buffered ()
-{
- OutSize = 128;
- State = WAITING;
- BufferedMessages = FALSE;
- WaitingForAnswer = FALSE;
- WaitingReply = FALSE;
- Sync = FALSE;
-}
-
/*?
These constructors are similar to those of class \typ{UchSocket}.
?*/
@@ -139,7 +127,7 @@ Default sizes are used if these functions are not called.
void
UchMsgStream :: OutputBuffer (int min, int grow, int max)
{
- InBuffer.SetSizes (min, grow, max);
+ OutBuffer.SetSizes (min, grow, max);
OutSize = max;
}
@@ -147,9 +135,9 @@ UchMsgStream :: OutputBuffer (int min, int grow, int max)
UchMsgStream :: ~UchMsgStream ()
{
Flush ();
- InBuffer.Delete ();
- OutBuffer.Delete ();
- Buffered.Delete ();
+ InBuffer.Clear ();
+ OutBuffer.Clear ();
+ Buffered.Clear ();
}
/*?nodoc?*/
@@ -217,89 +205,74 @@ UchMsgStream :: Delete ()
void
UchMsgStream :: ProcessInput (UchMsgBuffer& buf, bool waitAnswer)
{
-DBG (printf ("ProcessInput: ");)
for (;;) {
switch (State) {
- case WAITING:
-DBG (printf ("WAITING\n");)
- buf.Get (InType);
-DBG (if (buf.Error ()) printf (" buf empty\n");)
- if (buf.Error ())
+ case WAITING:
+ buf.Get (InType);
+ if (buf.Error ())
+ return;
+ WaitingReply = FALSE;
+ switch (InType) {
+ case ASK :
+ WaitingReply = TRUE;
+ State = GOT_TYPE;
+ break;
+ case ANS :
+ case MSG :
+ State = GOT_TYPE;
+ break;
+ case SYNC :
+ case ASYNC :
+ case OK :
+ default :
+ State = WAITING;
+ }
+ if (State != GOT_TYPE)
+ break;
+ // fallthrough
+
+ case GOT_TYPE:
+ if (! buf.Peek ((lword*) &InLength))
+ return;
+ buf.NeedSize ((int) InLength - buf.BufLength ());
+ State = GOT_LENGTH;
+ // fallthrough
+
+ case GOT_LENGTH:
+ if (buf.BufLength () < InLength)
+ return;
+ State = DONE;
+ // fallthrough
+
+ case DONE:
+ if (waitAnswer) {
+ if (InType == ANS) {
+ WaitingForAnswer = FALSE;
+ // answer still in the buffer
+ // the answer is converted and
+ // the buffer is flushed in Ask
return;
- WaitingReply = FALSE;
- switch (InType) {
- case ASK :
-DBG (printf (" waiting reply\n");)
- WaitingReply = TRUE;
- State = GOT_TYPE;
- break;
- case ANS :
-DBG (printf (" answer\n");)
- case MSG :
-DBG (if (InType != ANS) printf (" msg\n");)
-DBG (printf (" got type\n");)
- State = GOT_TYPE;
- break;
- case SYNC :
- case ASYNC :
- case OK :
- default :
-DBG (printf (" unknown !!\n");)
- State = WAITING;
+ } else {
+ // store incoming message in a separate buffer
+ BufferedMessages = TRUE;
+ Buffered.Append (InType);
+ Buffered.Append (buf.Buffer (), InLength);
}
- if (State != GOT_TYPE)
- break;
- // fallthrough
-
- case GOT_TYPE:
-DBG (printf ("GOT_TYPE\n");)
- if (! buf.Peek ((lword*) &InLength))
- return;
- buf.NeedSize ((int) InLength - buf.BufLength ());
- State = GOT_LENGTH;
- // fallthrough
-
- case GOT_LENGTH:
-DBG (printf ("GOT_LENGTH\n");)
- if (buf.BufLength () < InLength)
- return;
- State = DONE;
- // fallthrough
-
- case DONE:
-DBG (printf ("DONE\n");)
- if (waitAnswer) {
- if (InType == ANS) {
-DBG (printf ("got answer\n");)
- WaitingForAnswer = FALSE;
- // answer still in the buffer
- // the answer is converted and
- // the buffer is flushed in Ask
+ } else {
+ if (InType == MSG || InType == ASK) {
+ // pass a fake buffer to the handler
+ UchMsgBuffer fake (buf, InLength);
+ if (! NewMessage (fake, WaitingReply))
return;
- } else {
- // store incoming message in a separate buffer
- BufferedMessages = TRUE;
- Buffered.Append (InType);
- Buffered.Append (buf.Buffer (), InLength);
-DBG (printf ("buffering\n");)
- }
- } else {
- if (InType == MSG || InType == ASK) {
-DBG (printf ("new message\n");)
- // pass a fake buffer to the handler
- UchMsgBuffer fake (buf, InLength);
- if (! NewMessage (fake, WaitingReply))
- return;
- // *** this return breaks the assumption that
- // *** ProcessInput empties the buffer.
- // *** this is assumed in HandleRead/HandleSelect
- // *** because BufferedMessages is reset to FALSE;
- }
-DBG (else printf ("discarding\n");)
+ // *** this return breaks the assumption that
+ // *** ProcessInput empties the buffer.
+ // *** this is assumed in HandleRead/HandleSelect
+ // *** because BufferedMessages is reset to FALSE;
}
- buf.Flush (InLength);
- State = WAITING;
- // fallthrough
+ }
+ buf.Flush (InLength);
+ State = WAITING;
+ // fallthrough
}
}
}
@@ -381,7 +354,7 @@ Send a message and wait for an answer.
Incoming messages that are received while waiting for the answer are kept for later processing.
The answer message is returned by calling the virtual function \fun{ConvertAnswer}.
?*/
-void*
+UchMessage*
UchMsgStream :: Ask (UchMessage& msg)
{
if (WaitingReply) {
@@ -394,13 +367,7 @@ UchMsgStream :: Ask (UchMessage& msg)
WaitingForAnswer = TRUE;
do {
-#ifdef DEBUG
- printf ("waiting for answer\n");
-#endif
int n = ReadInput ();
-#ifdef DEBUG
- printf (" got %d bytes\n", n);
-#endif
if (n <= 0)
return 0;
ProcessInput (InBuffer, TRUE);
@@ -409,7 +376,7 @@ UchMsgStream :: Ask (UchMessage& msg)
// ProcessInput did not flush so that we can convert the answer
// *** If ProcessInput would return a void*, we could do all this stuff in it ...
UchMsgBuffer fake (InBuffer, InLength);
- void* res = ConvertAnswer (fake);
+ UchMessage* res = ConvertAnswer (fake);
InBuffer.Flush (InLength);
State = WAITING;
return res;
@@ -436,7 +403,7 @@ UchMsgStream :: Reply (UchMessage& msg)
This function is called by \fun{Ask} when the answer is in the buffer,
in order to convert it into an object usable by the application.
?*/
-void*
+UchMessage*
UchMsgStream :: ConvertAnswer (UchMsgBuffer&)
{
return 0;