-
For non-overlapping (non-asynchronous) operations, the function returns a value greater than 0 to indicate that the operation was successful. If 0 is returned, the connection is interrupted and the socket resource needs to be released. Socket error(-1) is returned, indicating an error, and the reason for the error is obtained by using wsagetlasterror().
As far as non-overlapping operations are concerned, their semantics are the same as standard recv functions.
For asynchronous operations, the wsarecv() function returns 0 if no errors occur and the receive operation completes immediately, noting that in this case the completion indication (starting a specified completion routine or setting an event object) will already have occurred. Otherwise, a socket error error will be returned, which the application can obtain via wsagetlasterror(). Error**WSA IO Pending indicates that the overlap operation was successfully started and there will be an indication of completion thereafter.
Any other errors indicate that the overlapping operation did not start successfully and there will be no indication of completion in the future.
If the msg interrupt flag is set, the meaning of the returned value changes. Zero means success, and the specific meaning is the same as above. Otherwise, the return value directly contains the error like the following.
This is required because wsagetlasterror() cannot be called in an interrupt environment. Please note that it only applies to the Win16 environment, and only applies to protocols with the XP1 Interrupt bit set in the Protocol Info structure.
-
#include
int pascal far wsagetlasterror ( void );
Note: This function returns the last network error that occurred. When a particular Windows Sockets API function indicates that an error has occurred, it should be called to obtain the corresponding error**.
A note on Windows sockets providers:
This makes you use the wsagetlasterror() function to get the last error**, instead of relying on global error variables, which is to provide compatibility with the multi-threaded environment in the future.
Note that in a non-preemptive Windows environment, wsagetlasterror() is only used to get Windows Sockets API errors. In a preemptive environment, wsagetlasterror() will call getlasterror() to get the error state of all win32 api functions on a per-thread basis. To improve portability, applications should use wsagetlasterror() immediately after a failed call
See: wsasetlasterror().
-
Try adding 500ms delay to non-stop connect.
-
The reason why the compilation fails is that the destructor is only declared but not defined as mentioned above Program 1 can compile and pass, and the reason why program 2 cannot pass is that the myaccept() function definition in program 1 is placed inside the class, and in C++ this definition will be defaulted to an inline function, for inline functions, C++ is only processed after the class definition is completed, so in the compilation m....
-
If no error occurs, wsasocket() returns the descriptor of the new set of interfaces. Otherwise, an invalid socket is returned, and the application can call wsagetlasterror() to get the corresponding error.