Well, it's *supposed* to work as you say. But honestly, this code has not been tested with blocking streams, since that's not how we use it in Google. It's possible that there is a bug. But the code appears to be correct AFAICT. When CodedInputStream needs more data, it calls Refresh(), which looks like this:
bool CodedInputStream::Refresh() { DCHECK_EQ(buffer_size_, 0); if (buffer_size_after_limit_ > 0 || overflow_bytes_ > 0 || total_bytes_read_ == current_limit_) { // ... return false; } // ... } In your case, total_bytes_read_ should be equal to current_limit_ -- both should be 17. Therefore, it *should* be returning false, not trying to read more. What are you seeing? If you can't figure it out, can you write a small demo program? Just make the demo program abort if CodedInputStream tries to read too much. Then I can debug it. On Tue, Jun 30, 2009 at 10:57 AM, Matthews <heav...@gmail.com> wrote: > > I am writing a Java server and C++ client and trying to use Protocol > Buffers for encoding the socket communication. I have written the Java > server and tested it with a Java based client and all is well. > However, I am having some difficulty with the C++ portion. > > I've wrapped the socket code in my own CopyingInputStream and > CopyingOutputStream sub-classes and am using those with the > CopyingInputStreamAdaptor and CopyingOutputStreamAdapdtor classes. > These classes are further wrapped in CodedInputStream and > CodedOutputStream instances for reading/writing the serialized data. > > When I send messages I encode the message type and size as varints > then the message itself. When reading the server response in the C++ > code I read the message type and size then pass the size to > CodedInputStream.PushLimit(). My server response is very small, 17 > bytes so the initial read gets all the data (I verified that by > stepping through the code in the debugger). > > In this case the type and size are each encoded as 1 byte so that > leaves 15 bytes for the message. What I am finding is that even after > the call to PushLimit() with the value 15 the CodedInputStream is > trying to read more bytes. Again, stepping through the code in the > debugger I can see that the 15 bytes are already buffered. I've poured > through the C++ docs and the description of limits states that > PushLimit will prevent CodedInputStream from reading any additional > bytes. > > This is a problem as the socket is doing a blocking read so it is > waiting for bytes that will not be sent. > > Am I mis-understanding the behavior of PushLimit? > > Thanks, > Michael > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~----------~----~----~----~------~----~------~--~---