bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tcpstream bugreport (accurate, this time :)


From: Andrea Pippa
Subject: tcpstream bugreport (accurate, this time :)
Date: Sun, 08 Sep 2002 16:26:41 +0200

Hi! I've done some tests, and I've some code that shows a problem (or a
misunderstood feature !? :) in the tcpstream class:

/** Server part **/

#include <cc++/socket.h>

using namespace ost;
using namespace std;

#include <stdlib.h>
#include <stdio.h>

int main(int argc,char **argv) {
 InetAddress local = "127.0.0.1";
 TCPSocket *sok = new TCPSocket(local,6969);
 tcpstream *_ios; int i = 0;
 while (1) {
  printf("%d:Waiting..\n",++i);
  if (sok->isPendingConnection()){
   _ios = new tcpstream(*sok);
   break;
  } else {
   sleep(1);
  }
 };
 while (1) {
  char buf[256];
  if (!_ios->eof()) {
   _ios->getline(buf,256);
   char rbuf[256]; i++;
   printf("%d:In:%s\n",i,buf);
   snprintf(rbuf,256,"Reply:%d",i);
   *_ios << rbuf << endl; // By removing this reply, everything works
well
  }
 };
}

/** Client part **/

#include <cc++/socket.h>

using namespace ost;
using namespace std;

#include <stdlib.h>
#include <stdio.h>

int main(int argc,char **argv) {
 tcpstream str; int i=0;
 str.open("127.0.0.1:6969");
 str << "line1\nline2\nline3\nline4\n";
 str.flush();
}

The problem is that the server does not receive all the 4 lines that the
client sends.
It just receive the first, then replies, and then does not receive
anything more.
The problem disappears if I remove the reply, so all the 4 lines are
received.

Is this a problem, or I'm supposed to use stream in a different way ?
maybe reading all lines, and replying only when the input buffer is
empty ? maybe flush flushes both the buffers (input/output), so replying
empties also the input buffer ?

I'm using gcc2.96 to compile, on a redhat 7.3, and commonc++2 v1.0.1
(also v1.0.0 anyway has this problem, so it's not a new bug).

Well, thanks for your help, bye ! :)

Pyper.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]