Adding logical Process Control to C + + programs

Source: Internet
Author: User

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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.