Ludzie pragną czasami się rozstawać, żeby móc tęsknić, czekać i cieszyć się z powrotem.
This is likely to be
noticeable only if the application immediately tries to open
a new socket (if no sockets are available), or to connect()
to the same peer.
Cancelling an accept() or a select() call does not adversely
impact the sockets passed to these calls. Only the
particular call fails; any operation that was legal before
the cancel is legal after the cancel, and the state of the
socket is not affected in any way.
Cancelling any operation other than accept() and select()
can leave the socket in an indeterminate state. If an
application cancels a blocking operation on a socket, the
only operation that the application can depend on being able
to perform on the socket is a call to closesocket(),
although other operations may work on some Windows Sockets
implementations. If an application desires maximum
portability, it must be careful not to depend on performing
operations after a cancel. An application may reset the
connection by setting the timeout on SO_LINGER to 0.
If a cancel operation compromised the integrity of a
SOCK_STREAM's data stream in any way, the Windows Sockets
implementation must reset the connection and fail all future
operations other than closesocket() with WSAECONNABORTED.
WSACancelBlockingCall 113
Return Value The value returned by WSACancelBlockingCall() is 0 if
the operation was successfully canceled. Otherwise the
value SOCKET_ERROR is returned, and a specific error number
may be retrieved by calling WSAGetLastError().
Comments Note that it is possible that the network operation
completes before the WSACancelBlockingCall() is processed,
for example if data is received into the user buffer at
interrupt time while the application is in a blocking hook.
In this case, the blocking operation will return
successfully as if WSACancelBlockingCall() had never been
called. Note that the WSACancelBlockingCall() still
succeeds in this case; the only way to know with certainty
that an operation was actually canceled is to check for a
return code of WSAEINTR from the blocking call.
Error Codes WSANOTINITIALISED A successful
WSAStartup() must occur before using
this API.
WSAENETDOWN The Windows Sockets implementation has
detected that the network subsystem has
failed.
WSAEINVAL Indicates that there is no outstanding
blocking call.
114 WSACleanup
4.3.10 WSACleanup()
Description Terminate use of the Windows Sockets DLL.
#include
int PASCAL FAR WSACleanup ( void );
Remarks An application or DLL is required to perform a (successful)
WSAStartup() call before it can use Windows Sockets
services. When it has completed the use of Windows Sockets,
the application or DLL must call WSACleanup() to deregister
itself from a Windows Sockets implementation and allow the
implementation to free any resources allocated on behalf of
the application or DLL. Any open SOCK_STREAM sockets that
are connected when WSACleanup() is called are reset; sockets
which have been closed with closesocket() but which still
have pending data to be sent are not affected--the pending
data is still sent.
There must be a call to WSACleanup() for every call to
WSAStartup() made by a task. Only the final WSACleanup()
for that task does the actual cleanup; the preceding calls
simply decrement an internal reference count in the Windows
Sockets DLL. A naive application may ensure that
WSACleanup() was called enough times by calling WSACleanup()
in a loop until it returns WSANOTINITIALISED.
Return Value The return value is 0 if the operation was successful.
Otherwise the value SOCKET_ERROR is returned, and a specific
error number may be retrieved by calling WSAGetLastError().
Comments Attempting to call WSACleanup() from within a blocking hook
and then failing to check the return code is a common
Windows Sockets programming error. If an application needs
to quit while a blocking call is outstanding, the
application must first cancel the blocking call with
WSACancelBlockingCall() then issue the WSACleanup() call
once control has been returned to the application.
Notes For
Windows Sockets
Suppliers Well-behaved Windows Sockets applications will make a
WSACleanup() call to indicate deregistration from a Windows
Sockets implementation. This function can thus, for
example, be utilized to free up resources allocated to the
specific application.
A Windows Sockets implementation must be prepared to deal
with an application which terminates without invoking
WSACleanup() - for example, as a result of an error.
In a multithreaded environment, WSACleanup() terminates
Windows Sockets operations for all threads.
A Windows Sockets implementation must ensure that
WSACleanup() leaves things in a state in which the
WSACleanup 115
application can invoke WSAStartup() to re-establish Windows
Sockets usage.
Error Codes WSANOTINITIALISED A successful
WSAStartup() must occur before using
this API.
WSAENETDOWN The Windows Sockets implementation has
detected that the network subsystem has
failed.
WSAEINPROGRESS A blocking Windows Sockets operation is
in progress.
See Also WSAStartup()
116 WSAGetLastError
4.3.11 WSAGetLastError()
Description Get the error status for the last operation which
failed.