accept

This function accepts a connection on a socket.

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

Parameters

  • s
    [in] Descriptor that identifies a socket that has been placed in a listening state with the listen function. The connection is actually made with the socket that is returned by accept.
  • addr
    [out] Optional pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family established when the socket was created. Set to NULL for IrSocket implementation.
  • addrlen
    [out] Optional pointer to an integer that contains the length of the address addr. Set to NULL for IrSocket implementation.

Return Values

The return value is a handle for the socket on which the actual connection is made. INVALID_SOCKET indicates failure. To get a specific error value, call WSAGetLastError. The following table shows common error values.

Windows CE does not support the WSACancelBlockingCall function; however, Windows CE returns the WSAEINTR error value if closesocket is called in the middle of executing a sockets call.

The integer referred to by addrlen initially contains the amount of space pointed to by addr. On return it contains the actual length in bytes of the address returned.

Remarks

For Infrared Sockets (IrSock), set the addr and addrlen parameters to NULL.

The accept function extracts the first connection on the queue of pending connections on socket s. It then creates a new socket and returns a handle to the new socket. The newly created socket is the socket that will handle the actual connection and has the same properties as socket s. The newly created socket s does not have the listening socket's group identifier, if any was applied.

The accept function can block the caller until a connection is present if no pending connections are present on the queue, and the socket is marked as blocking. If the socket is marked nonblocking and no pending connections are present on the queue, accept returns the WSAEWOULDBLOCK error value. The socket handle returned from a successful accept call cannot be used to accept further connections. The original socket remains open to listen for new connection requests.

The parameter addr is a result parameter that is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family in which the communication is occurring. The addrlen is a value-result parameter; it should initially contain the amount of space pointed to by addr; on return it will contain the actual length (in bytes) of the address returned.

The accept function is used with connection-oriented socket types such as SOCK_STREAM.

If addr and/or addrlen are equal to NULL, then no information about the remote address of the accepted socket is returned.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and later Winsock.h    

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

bind, connect, listen, select, socket

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.