The problem arises
In a computer program, in addition to the common execution Process control, there are logical process controls; Sometimes the execution process is a logical process, but in most cases it is different, for example, assuming that a Web server uses a synchronous socket to read HTTP requests, the following code is written:
void Read (http_request& http_request)
{
Read (http_request.header);
Read (Http_request.body, Http_request.header);
}
Void Read (http_request_header& HEADER)
{
String line = Read_line ();
Parse_request_link (line, H Eader.method, Header.uri,
Header.version);
while (TRUE)
{
line = Read_line ();
if (Line.empty ())
break;
Parse_header_field (line, header);
}
void Read (byte[]& body, http_request_header& HEADER)
{
String transfer_encoding = Header.fie lds[' transfer-encoding '];
if (transfer_encoding!= b.chunkedb.)
BODY = read_bytes (header.fields[' content-length '));
Else
{
while (TRUE)
{
String chunk_header = Read_line ();
DWORD chunk_size = atoi (Chunk_header);
if (chunk_size = 0)
break;
byte[] Chunk_body = read_bytes (chunk_size);
Body + = Chunk_body;
}
}
}
String Read_line ()
{
while (TRUE)
{
int n = strpos (Read_buffer, B.\nb., read_buffer.size ());
if (n > 0)
break;
Read_buffer + = Socket.read ();
}
return Read_buffer.extract (n);
}
byte[] read_bytes (int sz)
{
while (TRUE)
{
if (sz <= read_buffer.size ())
break;
Read _buffer + + socket.read ();
}
Return Read_buffer.extract (SZ);
}