Value-Result parameter

Source: Internet
Author: User

When passing a socket address structure to a socket function, the structure is always passed as a reference, that is, a pointer to the struct is passed.

The length of the structure is also passed as a parameter, but the way it is passed depends on the direction of the structure: process--Kernel kernel--process

1) process-to-kernel pass socket address structure functions are 3: Bind, Connect, sendto

One parameter to these functions is a pointer to a socket address structure, and the other parameter is the integer size of the structure

2) The kernel-to-process pass socket address structure has 4 functions: Accept, Recvfrom, GetSockName, Getpeername

The 2 parameters of these 4 functions are pointers to a socket address structure and pointers to integer variables that represent the size of the structure

Change the size of the socket address structure from an integer to a pointer to an integer variable for the reason:

When a function is called, the size of the structure is a value (value), which tells the kernel the size of the structure so that the kernel does not cross over when writing the structure;

When the function returns, the size of the structure is another result, which tells the process kernel exactly how much information is stored in the struct.

This type of parameter is called: value-result parameter

Value-Result parameter

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.