Partager via


WSAJoinLeaf

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function joins a leaf node into a multipoint session, and exchanges connect data.

Note

WSAJoinLeaf is not supported by the default TCP/UDP and Winsock provider in Windows Embedded CE. However, third parties can implement their own provider and have support for this function if they choose.

Syntax

SOCKET WSAJoinLeaf(
  SOCKET s,
  const struct sockaddr FAR* name,
  int namelen,
  LPWSABUF lpCallerData,
  LPWSABUF lpCalleeData,
  LPQOS lpSQOS,
  LPQOS lpGQOS,
  DWORD dwFlags
);

Parameters

  • s
    [in] Descriptor identifying a multipoint socket.
  • name
    [in] Name of the peer to which the socket is to be joined.
  • namelen
    [in] Length of name.
  • lpCallerData
    [in] Pointer to the user data that is to be transferred to the peer during multipoint session establishment.
  • lpCalleeData
    [out] Pointer to the user data that is to be transferred back from the peer during multipoint session establishment.
  • lpSQOS
    [in] Pointer to the structures for socket s, one for each direction.
  • lpGQOS
    [in] Reserved.
  • dwFlags
    [in] Flags to indicate that the socket is acting as a sender, receiver, or both.

Return Value

If no error occurs, this function returns a value of type SOCKET that is a descriptor for the newly created multipoint socket. If an error occurs, a value of INVALID_SOCKET is returned. A specific error code can be retrieved by calling WSAGetLastError.

On a blocking socket, the return value indicates success or failure of the join operation.

With a nonblocking socket, successful initiation of a join operation is indicated by a return of a valid socket descriptor. Subsequently, an FD_CONNECT indication will be given on the original socket s when the join operation completes, either successfully or otherwise. The application must use WSAEventSelect with interest registered for the FD_CONNECT event in order to determine when the join operation has completed. It then checks the associated error code to determine the success or failure of the operation. The select function cannot be used to determine when the join operation completes. Also, until the multipoint session join attempt completes, all subsequent calls to WSAJoinLeaf on the same socket will fail with the error code WSAEALREADY. After the WSAJoinLeaf operation completes successfully, a subsequent attempt will usually fail with the error code WSAEISCONN. An exception to the WSAEISCONN rule occurs for a c_root socket that allows root-initiated joins. In such a case, another join may be initiated after a prior WSAJoinLeaf operation completes.

If the return error code indicates that the multipoint session join attempt failed with error codes WSAECONNREFUSED, WSAENETUNREACH, or WSAETIMEDOUT, the application can call WSAJoinLeaf again for the same socket.

The following table shows the possible error values.

Error Description

WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAEADDRINUSE

The socket's local address is already in use and the socket was not marked to allow address reuse with SO_REUSEADDR. This error usually occurs at the time of bind, but could be delayed until this function if the bind was to a partially wildcard address involving ADDR_ANY and if a specific address needs to be committed at the time of this function.

WSAEINPROGRESS

A blocking Winsock call is in progress, or the service provider is still processing a callback function.

WSAEALREADY

A nonblocking WSAJoinLeaf call is in progress on the specified socket.

WSAEADDRNOTAVAIL

The remote address is not a valid address (such as ADDR_ANY).

WSAEAFNOSUPPORT

Addresses in the specified family cannot be used with this socket.

WSAECONNREFUSED

The attempt to join was forcefully rejected.

WSAEFAULT

The name or the namelen parameter is not a valid part of the user address space, the namelen parameter is too small, the buffer length for lpCalleeData, lpSQOS, and lpGQOS are too small, or the buffer length for lpCallerData is too large.

WSAEISCONN

The socket is already a member of the multipoint session.

WSAENETUNREACH

The network cannot be reached from this host at this time.

WSAENOBUFS

No buffer space is available. The socket cannot be joined.

WSAENOTSOCK

The descriptor is not a socket.

WSAEOPNOTSUPP

The structures specified in lpSQOS and lpGQOS cannot be satisfied.

WSAEPROTONOSUPPORT

The lpCallerData augment is not supported by the service provider.

WSAETIMEDOUT

The attempt to join timed out without establishing a multipoint session.

Note

WSAJoinLeaf is not supported for the default TCP/UDP provider and will always return WSASYSCALLFAILURE.

Remarks

This function is used to join a leaf node to a multipoint session and to perform a number of other ancillary operations that occur at session join time as well. If the socket, s, is unbound, unique values are assigned to the local association by the system and the socket is marked as bound.

The WSAJoinLeaf function has the same parameters and semantics as WSAConnect except that it returns a socket descriptor (as in WSAAccept), and it has an additional dwFlags parameter. Only multipoint sockets created using WSASocket with the appropriate multipoint flags set can be used for input parameter s in this function. The returned socket descriptor will not be usable until after the join operation completes. For example, if the socket is in nonblocking mode after a corresponding FD_CONNECT indication has been received from WSAEventSelect on the original socket s, closesocket may be invoked on this new socket descriptor to cancel a pending join operation. A root application in a multipoint session may call WSAJoinLeaf one or more times in order to add a number of leaf nodes; however, at most one multipoint connection request may be outstanding at a time.

For nonblocking sockets, it is often not possible to complete the connection immediately. In such a case, this function returns an as-yet unusable socket descriptor and the operation proceeds. There is no error code such as WSAEWOULDBLOCK in this case because the function has effectively returned a successful start indication. When the final outcome success or failure becomes known, it may be reported through WSAEventSelect. In either case, the notification is announced with FD_CONNECT and the error code associated with the FD_CONNECT indicates either success or a specific reason for failure. The select function cannot be used to detect completion notification for WSAJoinLeaf.

The socket descriptor returned by WSAJoinLeaf is different depending on whether the input socket descriptor, s, is a c_root or a c_leaf. When used with a c_root socket, the name parameter designates a particular leaf node to be added and the returned socket descriptor is a c_leaf socket corresponding to the newly added leaf node. The newly created socket has the same properties as s, including asynchronous events registered with WSAEventSelect. It is not intended to be used for the exchange of multipoint data, but rather it is used to receive network event indications such as FD_CLOSE for the connection that exists to the particular c_leaf. Some multipoint implementations can also allow this socket to be used for side chats between the root and an individual leaf node. An FD_CLOSE indication will be received for this socket if the corresponding leaf node calls closesocket to drop out of the multipoint session. Symmetrically, invoking closesocket on the c_leaf socket returned from WSAJoinLeaf will cause the socket in the corresponding leaf node to get an FD_CLOSE notification.

When WSAJoinLeaf is invoked with a c_leaf socket, the name parameter contains the address of the root application for a rooted control scheme, or an existing multipoint session for a nonrooted control scheme, and the returned socket descriptor is the same as the input socket descriptor. In other words, a new socket descriptor is not allocated. In a rooted control scheme, the root application would put its c_root socket in listening mode by calling listen. The standard FD_ACCEPT notification will be delivered when the leaf node requests to join itself to the multipoint session. The root application uses the usual accept/WSAAccept functions to admit the new leaf node. The value returned from either accept or WSAAccept is also a c_leaf socket descriptor just like those returned from WSAJoinLeaf. To accommodate multipoint schemes that allow both root-initiated and leaf-initiated joins, it is acceptable for a c_root socket that is already in listening mode to be used as an input to WSAJoinLeaf.

The application is responsible for allocating any memory space pointed to directly or indirectly by any of the parameters it specifies.

The lpCallerData parameter is a value parameter that contains any user data that is to be sent along with the multipoint session join request. If lpCallerData is NULL, no user data will be passed to the peer. The lpCalleeData parameter is a result parameter that will contain any user data passed back from the peer as part of the multipoint session establishment. The lpCalleeData->len initially contains the length of the buffer allocated by the application and pointed to by lpCalleeData->buf. lpCalleeData->len will be set to 0 if no user data has been passed back. The lpCalleeData information will be valid when the multipoint join operation is complete.

For blocking sockets, this will be when the WSAJoinLeaf function returns. For nonblocking sockets, this will be after the join operation has completed. For example, this could occur after FD_CONNECT notification on the original socket s. If lpCalleeData is NULL, no user data will be passed back. The exact format of the user data is specific to the address family to which the socket belongs.

The dwFlags parameter is used to indicate whether the socket will be acting only as a sender with JL_SENDER_ONLY, only as a receiver with JL_RECEIVER_ONLY, or both as JL_BOTH.

When connected sockets break or become closed for whatever reason, they should be discarded and recreated. It is safest to assume that when things go awry for any reason on a connected socket, the application must discard and recreate the needed sockets in order to return to a stable point.

Requirements

Header winsock2.h
Library Ws2.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

accept (Windows Sockets)
bind (Windows Sockets)
select
WSAAccept
WSAEventSelect
WSASocket