Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what the difference between accept4 and accept

I saw nginx source code that use accept4 when system support it.
And I've google it accept4 support after Linux 2.6.28.
What the difference between accept4 and accept?

like image 473
Magic Avatar asked May 30 '14 10:05

Magic


People also ask

What is the difference between ‘accept’ and ‘except’?

The word ‘accept’ simply means ‘give consent to someone or something’, or ‘to receive something’ and so it denotes an action. As against, ‘except’ in basic terms means ‘other than’ or ‘apart from’, representing a condition in a sentence. We use accept mainly as a verb, whereas except is commonly used as a preposition or conjunction.

What is the difference between receive and accept in English grammar?

As verbs the difference between receive and accept is that receive is to get, to be given something while the other party is the active partner (opposite: to obtain) while accept is to receive, especially with a consent, with favour, or with approval. As a noun receive is (telecommunications) an operation in which data is received.

What is the difference between “accept” and “approve”?

“Approve” involves a higher authority to agree to something, whereas it is absent in the case of “accept”. What is the fifference between "have received" and "had received"?

What does it mean to accept a present?

consent to receive or undertake (something offered). "he accepted a pen as a present". believe or come to recognize (a proposition) as valid or correct. What's the difference between still and till? indefinite sense and till is used to indicate definite in time. The workers are still working now. The workers are working till noon.


1 Answers

accept4 is a non-standard linux extension. The real difference is in the 4th argument (flags) which is not present in accept:

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
int accept4(int sockfd, struct sockaddr *addr,socklen_t *addrlen, int flags);

From: accept man page

If flags is 0, then accept4() is the same as accept(). The following values can be bitwise ORed in flags to obtain different behavior:

   SOCK_NONBLOCK   Set the O_NONBLOCK file status flag on the new open
                   file description.  Using this flag saves extra calls
                   to fcntl(2) to achieve the same result.

   SOCK_CLOEXEC    Set the close-on-exec (FD_CLOEXEC) flag on the new
                   file descriptor.  See the description of the
                   O_CLOEXEC flag in open(2) for reasons why this may be
                   useful.

And from: open man page

By default, the new file descriptor is set to remain open across an execve(2) (i.e., the FD_CLOEXEC file descriptor flag described in fcntl(2) is initially disabled); the O_CLOEXEC flag, described below, can be used to change this default.

And for eg, by using this flag (SOCK_CLOEXEC), one can avoid race conditions in multithreaded programs where it may lead to the file descriptor returned by open() being unintentionally leaked to the program executed by the child process created by fork(2).

like image 162
brokenfoot Avatar answered Oct 01 '22 20:10

brokenfoot