Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function permits an incoming connection attempt on a socket.
Syntax
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 listenfunction. 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 addrparameter 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 Value
If no error occurs, this function returns a value of type SOCKETthat 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 addrleninitially 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 WSAStartupcall must occur before using this function. |
WSAENETDOWN |
The network subsystem has failed. |
WSAEFAULT |
The addrlenparameter is too small or addris 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 listenfunction 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 WSAEventSelectfunction.
The acceptfunction 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 acceptreturns 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 addrparameter 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 addrparameter is determined by the address family in which the communication is occurring. The addrlenparameter 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 acceptfunction is used with connection-oriented socket types such as SOCK_STREAM.
Note: |
---|
Asynchronous transfer mode (ATM) is not supported in Windows Embedded CE. |
Notes for Bluetooth
The acceptfunction works the same for RFCOMM as for any standard sockets implementation.
Requirements
Header | winsock2.h |
Library | Ws2.lib |
Windows Embedded CE | Windows CE 1.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |