[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Incoming data loss due to TCPStream::sync(void) gettting called if the a
From: |
Georg Soffel |
Subject: |
Incoming data loss due to TCPStream::sync(void) gettting called if the a tcpstream is flushed! |
Date: |
Thu, 8 May 2003 10:54:04 +0200 |
Hello all,
I am using the tcpstream class in binary mode:
mystream.setf(ios::binary);
mystream.unsetf(ios::skipws);
I wrote stream operators for a message class
which are used to send and receive messages via the stream socket, like :
mystream >> msg;
for receiving a message from the stream and:
mystream << msg << flush;
for sending a message to the stream.
Now I noticed an incoming message loss. Further investigations showed that
the reason was due to the fact that the call to flush led to a call of the
sync function
in the TCPStream class. This was not what I expected! I wanted only to get
the
message send immediately by the flush and not clear my incoming buffer.
I am not an expert with steam and stream buffer classes in the Standard C++
Library but I think this is not the desired behaviour.
I solved the problem by writing my own "Flush" function:
class mytcpstream : public tcpstream {
public:
void Flush(void) { // flush without clearing the incoming buffer
overflow(EOF);
}
Error setNoDelay(bool enable) { // disable nagle for better
performance
return Socket::setNoDelay(enable);
}
};
Now
mystream << msg; mystream.Flush();
works fine without any message loss even under high load.
Please give me some feedback/comments. This problem probably also
occurs if the stream is not used in binary mode and "endl" is used!
Regards
Georg Soffel
Marconi Communications GmbH Phone: +49 (7191) 13 2155
Postfach: 1920 Fax: +49 (7191)
13 6 2155
D-71509 Backnang
mailto:address@hidden
Germany
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Incoming data loss due to TCPStream::sync(void) gettting called if the a tcpstream is flushed!,
Georg Soffel <=