CUT_ERR::GetSocketError
static LPCSTR GetSocketError(SOCKET * s, int * result=NULL)
Parameters
s |
A pointer to the socket to be queried. |
result |
An optional integer that will receive the actual winsock error code. |
Return Value
A string containing a readable description of the last error to occur on the socket (if available).
Remarks
In most cases, the predefined return codes are sufficient to indicate what went wrong with a call to a method of one of the Ultimate TCPIP classes.
Occasionally you will find that you need to deal with a return value of SOCKET_ERROR from a call to a winsock API function, particularly when extending a class.
This ususally involves a call to WSAGetLastError, and a switch statement to determine which error constant was returned. Often you will need the switch to determine a course of action to take, but if all you are concerned with is knowing what the error was, GetSocketError can be a time and space saver.
WSAGetLastError will return the last error that occurred on any socket in the current thread. The code in GetSocketError takes a pointer to the socket in order to query the socket. This is done by using the GetSockOpt call, rather than WSAGetLastError.
If the socket is invalid the return string will be "GetSockOpt error: WSAENOTSOCK", indicating that the call to GetSockOpt failed. Other errors may be returned as GetSockOpt errors.
If you want the actual error code pass a pointer to the result parameter.
For some TCPIP methods you should call WSAGetLastError to determine the socket error if a particular call returns UTE_ERROR or -1. This is indicated where appropriate.
If the socket is still valid (i.e. the method was not involved with creating or destroying the socket) you may find it more convenient to call GetSocketError instead of WSAGetLastError.
GetSocketError is intended more as a development aid than a library export.
See also: GetErrorString
Example
// if an error occurs connecting then in the OnError callback
// we are just examining the error and then returning an errorcode.
if(connect(m_socket, (LPSOCKADDR)&m_sockAddr, sizeof(m_sockAddr)) ==SOCKET_ERROR)
{
// you can place a break point here to examine the string
LPCSTR str = CUT_ERR::GetSocketError(&m_socket);
return OnError(UTE_SOCK_CONNECT_FAILED);
}