Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

accept (Windows Sockets)

Windows Mobile 6.5
A version of this page is also available for
4/8/2010

This function permits an incoming connection attempt on a socket.


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

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.

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.

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.

Aa920080.note(en-us,MSDN.10).gifNote:
Asynchronous transfer mode (ATM) is not supported in Windows Embedded CE.

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

Headerwinsock2.h
LibraryWs2.lib
Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

Show:
© 2015 Microsoft