Share via


accept (Windows Sockets) (Windows CE 5.0)

Send Feedback

This function permits an incoming connection attempt on a socket.

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

Parameters

  • s
    [in] Descriptor identifying 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 this function.
  • 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.
  • addrlen
    [out] Optional pointer to an integer that contains the length of addr.

Return Values

If no error occurs, this function returns a value of type SOCKET that is a descriptor for the new socket. This returned value is a handle for the socket on which the actual connection is made.

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

If an error occurs, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError. The following table shows the possible error code return values.

Error code Description
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAEFAULT The addrlen parameter is too small or addr is not a valid part of the user address space.
WSAEINTR. The socket was closed.
WSAEINPROGRESS A blocking Winsock call is in progress, or the service provider is still processing a callback function.
WSAEINVAL The listen function was not invoked prior to this function.
WSAEMFILE The queue is nonempty on entry to this function, and there are no descriptors available.
WSAENOBUFS No buffer space is available.
WSAENOTSOCK The descriptor is not a socket.
WSAEOPNOTSUPP The referenced socket is not a type that supports connection-oriented service.
WSAEWOULDBLOCK The socket is marked as nonblocking and no connections are present to be accepted.

Remarks

This 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, including the asynchronous events registered with the WSAEventSelect function.

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 as nonblocking and no pending connections are present on the queue, this function returns an error as described in the following table. After the successful completion of accept returns a new socket handle, the accepted socket cannot be used to accept more connections. The original socket remains open and listens for new connection requests.

The addr parameter is a result parameter that is completed 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 parameter 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.

Note   Asynchronous transfer mode (ATM) is not supported in Microsoft® Windows® CE.

Notes for Bluetooth

The accept function works the same for RFCOMM as for any standard sockets implementation.

Requirements

OS Versions: Windows CE 1.0 and later.
Header: Winsock2.h.
Link Library: Ws2.lib.

See Also

bind (Windows Sockets) | connect (Windows Sockets) | listen | select | socket (Windows Sockets) | WSAAccept | WSAEventSelect | WSAGetLastError | WSAStartup

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.