ByteVector ReadReply()
{
ByteVector reply = new ByteVector();
byte[] buf = new byte[512];
while(true)
{
int num = Receive(buf);
if(0 == num)
break;
reply.Add(buf, 0, num);
//handle the end of reply
int afterEndPos = FindReplyEnd(reply.Data, reply.Size);
if(afterEndPos > 0)
{
if(afterEndPos < num) //read after reply finished?
{
//put data back into the buffer for further
//processing in receive functions
PutBufferData(buf, afterEndPos, num - afterEndPos);
reply.CutTail(num - afterEndPos);
}
break;
}
if(reply.Size > _maxReplySize)
throw new ProtocolViolationException("Web proxy reply exceed maximum length.");
}
return reply;
}