Jump to main content

##

# accept Function

## C

    SOCKET accept(
        SOCKET s,
        struct sockaddr* addr,
        int* addrlen
    );

## Description

The accept function is used to accept connection request queued for a listening socket. If a connection request is pending, accept removes the request from the queue, and a new socket is created for the connection. The original listening socket remains open and continues to queue new connection requests. The socket must be a SOCK_STREAM type socket.

## Preconditions

The listen function should be called.

## Parameters

Parameters | Description
--- | ---
s | Socket descriptor returned from a previous call to socket. Must be bound to a local name and in listening mode.
addr | Optional pointer to a buffer that reveives the address of the connecting entity.
addrlen | Optional pointer to an integer that contains the length of the address addr.

## Returns

- non-negative integer - The function succeeds and the integer is a descriptor for the accepted socket.
- SOCKET_ERROR - Function failed. errno is set accordingly.

## Remarks

None.