Windows* Sockets 2 Application Programming Interface An Interface for Transparent Network Programming Under Microsoft Windowstm revision 2 August 7, 1997



Download 1.64 Mb.
Page23/49
Date31.07.2017
Size1.64 Mb.
#24975
1   ...   19   20   21   22   23   24   25   26   ...   49

89 shutdown()


Description Disable sends and/or receives on a socket.
#include
int WSAAPI
shutdown (
IN SOCKET
s,
IN int
how
);

s A descriptor identifying a socket.
how A flag that describes what types of operation will no longer be allowed.
Remarks shutdown() is used on all types of sockets to disable reception, transmission, or both.
If how is SD_RECEIVE, subsequent receives on the socket will be disallowed. This has no effect on the lower protocol layers. For TCP sockets, if there is still data queued on the socket waiting to be received, or data arrives subsequently, the connection is reset, since the data cannot be delivered to the user. For UDP sockets, incoming datagrams are accepted and queued. In no case will an ICMP error packet be generated.
If how is SD_SEND, subsequent sends are disallowed. For TCP sockets, a FIN will be sent after all data is sent and acknowledged by the receiver..
Setting how to SD_BOTH disables both sends and receives as described above.
Note that shutdown() does not close the socket, and resources attached to the socket will not be freed until closesocket() is invoked.
To assure that all data is sent and received on a connected socket before it is closed, an application should use shutdown() to close connection before calling closesocket(). For example, to initiate a graceful disconnect, an application could:



  • call WSAAsyncSelect() to register for FD_CLOSE notification

  • call shutdown() with how=SD_SEND

  • when FD_CLOSE received, call recv() until 0 returned, or SOCKET_ERROR

  • call closesocket()



Comments shutdown() does not block regardless of the SO_LINGER setting on the socket.
An application should not rely on being able to re-use a socket after it has been shut down. In particular, a WinSock provider is not required to support the use of connect() on such a socket.
Return Value If no error occurs, shutdown() returns 0. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code may be retrieved by calling WSAGetLastError().
Error Codes WSANOTINITIALISED A successful WSAStartup() must occur before using this API.
WSAENETDOWN The network subsystem has failed.
WSAEINVAL how is not valid, or is not consistent with the socket type, e.g., SD_SEND is used with a UNI_RECV socket type.
WSAEINPROGRESS A blocking WinSock 1.1 call is in progress, or the service provider is still processing a callback function.
WSAENOTCONN The socket is not connected (connection-oriented sockets only).
WSAENOTSOCK The descriptor is not a socket.
See Also connect(), socket().

90 socket()


Description Create a socket which is bound to a specific service provider.
#include
SOCKET WSAAPI
socket (
IN int
af,
IN int
type,
IN int
protocol
);

af An address family specification.
type A type specification for the new socket.
protocol A particular protocol to be used with the socket which is specific to the indicated address family.
Remarks socket() causes a socket descriptor and any related resources to be allocated and bound to a specific transport service provider. WinSock will utilize the first available service provider that supports the requested combination of address family, socket type and protocol parameters. The socket created will have the overlapped attribute by default. Note that on Microsoft operating systems there is a Microsoft-specific socket option, SO_OPENTYPE, defined in “mswsock.h” that can affect this default. See Microsoft-specific documentation for a detailed description of SO_OPENTYPE. Sockets without the overlapped attribute can be created by using WSASocket(). All functions that allow overlapped operation (WSASend(), WSARecv(),WSASendTo(), WSARecvFrom(), WSAIoctl()) also support non-overlapped usage on an overlapped socket if the values for parameters related to overlapped operation are NULL.
When selecting a protocol and its supporting service provider this procedure will only choose a base protocol or a protocol chain, not a protocol layer by itself. Unchained protocol layers are not considered to have "partial matches" on type or af either. That is, they do not lead to an error code of WSAEAFNOSUPPORT or WSAEPROTONOSUPPORT if no suitable protocol is found.
Note: the manifest constant AF_UNSPEC continues to be defined in the header file but its use is strongly discouraged, as this may cause ambiguity in interpreting the value of the protocol parameter.

The following are the only two type specifications supported for WinSock 1.1:


Type Explanation

SOCK_STREAM Provides sequenced, reliable, two-way, connection-based byte streams with an out-of-band data transmission mechanism. Uses TCP for the Internet address family.


SOCK_DGRAM Supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. Uses UDP for the Internet address family.
In WinSock 2 many new socket types will be introduced. However, since an application can dynamically discover the attributes of each available transport protocol via the WSAEnumProtocols() function, the various socket types need not be called out in the API specification. Socket type definitions will appear in Winsock2.h which will be periodically updated as new socket types, address families and protocols are defined.
Connection-oriented sockets such as SOCK_STREAM provide full-duplex connections, and must be in a connected state before any data may be sent or received on it. A connection to another socket is created with a connect() call. Once connected, data may be transferred using send() and recv() calls. When a session has been completed, a closesocket() must be performed.
The communications protocols used to implement a reliable, connection-oriented socket ensure that data is not lost or duplicated. If data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, the connection is considered broken and subsequent calls will fail with the error code set to WSAETIMEDOUT.
Connectionless, message-oriented sockets allow sending and receiving of datagrams to and from arbitrary peers using sendto() and recvfrom(). If such a socket is connect()ed to a specific peer, datagrams may be sent to that peer using send() and may be received from (only) this peer using recv().
Support for sockets with type RAW is not required but service providers are encouraged to support raw sockets whenever it makes sense to do so.

Return Value If no error occurs, socket() returns a descriptor referencing the new socket. Otherwise, a value of INVALID_SOCKET is returned, and a specific error code may be retrieved by calling WSAGetLastError().
Error Codes WSANOTINITIALISED A successful WSAStartup() must occur before using this API.
WSAENETDOWN The network subsystem or the associated service provider has failed.
WSAEAFNOSUPPORT The specified address family is not supported.
WSAEINPROGRESS A blocking WinSock 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEMFILE No more socket descriptors are available.
WSAENOBUFS No buffer space is available. The socket cannot be created.
WSAEPROTONOSUPPORT The specified protocol is not supported.
WSAEPROTOTYPE The specified protocol is the wrong type for this socket.
WSAESOCKTNOSUPPORT The specified socket type is not supported in this address family.
See Also accept(), bind(), connect(), getsockname(), getsockopt(), setsockopt(), listen(), recv(), recvfrom(), select(), send(), sendto(), shutdown(), ioctlsocket(), WSASocket().


Download 1.64 Mb.

Share with your friends:
1   ...   19   20   21   22   23   24   25   26   ...   49




The database is protected by copyright ©ininet.org 2024
send message

    Main page