if ioctlsocket(nSocket, FIONREAD , &InBuffer) = SOCKET_ERROR then
begin
case WSAGetLastError of
WSANOTINITIALISED: ErrorString := 'A successful WSAStartup call must occur before using this function.';
WSAENETDOWN: ErrorString := 'The network subsystem has failed.';
WSAEINPROGRESS: ErrorString := 'A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.';
WSAENOTSOCK: ErrorString := 'The descriptor s is not a socket.';
WSAEFAULT: ErrorString := 'The argp parameter is not a valid part of the user address space.';
end;
Break;
end;
if InBuffer > 65536 then InBuffer := 65536; rxLen := recv(nSocket, RxBuffer, InBuffer, 0);
if (rxLen = SOCKET_ERROR) or (rxLen = 0) then
begin
case WSAGetLastError of
WSANOTINITIALISED: ErrorString := 'A successful WSAStartup call must occur before using this function.';
WSAENETDOWN: ErrorString := 'The network subsystem has failed.';
WSAEFAULT: ErrorString := 'The buf parameter is not completely contained in a valid part of the user address space.';
WSAENOTCONN: ErrorString := 'The socket is not connected.';
WSAEINTR: ErrorString := 'The (blocking) call was canceled through WSACancelBlockingCall.';
WSAEINPROGRESS: ErrorString := 'A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.';
WSAENETRESET: ErrorString := 'The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.';
WSAENOTSOCK: ErrorString := 'The descriptor is not a socket.';
WSAEOPNOTSUPP: ErrorString := 'MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations.';
WSAESHUTDOWN: ErrorString := 'The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.';
WSAEWOULDBLOCK: ErrorString := 'The socket is marked as nonblocking and the receive operation would block.';
WSAEMSGSIZE: ErrorString := 'The message was too large to fit into the specified buffer and was truncated.';
WSAEINVAL: ErrorString := 'The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative.';
WSAECONNABORTED: ErrorString := 'The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.';
WSAETIMEDOUT: ErrorString := 'The connection has been dropped because of a network failure or because the peer system failed to respond.';
WSAECONNRESET: ErrorString := 'The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable.'; else
ErrorString := 'Error Desconocido';
if RxLen = 0 then
ErrorString := 'Desconectado';
end;
Break;
end
else
begin
if RxLen > 0 then
begin
ErrorString := '';
Synchronize(recibido);
end;
end;