aa4be1e2030074f3f4468d62f33852c0b0424d9e
Corrected two critical issues with socket mock precision: **1. Windows Socket Error Handling:** - Socket functions on Windows use WSAGetLastError/WSASetLastError, NOT errno - Added SET_SOCKET_ERROR macro that calls: - WSASetLastError() on Windows - errno assignment on Linux - Mapped all POSIX error codes to WSA equivalents: - EWOULDBLOCK → WSAEWOULDBLOCK - EAFNOSUPPORT → WSAEAFNOSUPPORT - EMFILE → WSAEMFILE - EBADF → WSAEBADF - ENOTSOCK → WSAENOTSOCK - EINVAL → WSAEINVAL - EADDRINUSE → WSAEADDRINUSE - EDESTADDRREQ → WSAEDESTADDRREQ - ECONNABORTED → WSAECONNABORTED - EISCONN → WSAEISCONN - EINPROGRESS → WSAEINPROGRESS - EOPNOTSUPP → WSAEOPNOTSUPP - ENOTCONN → WSAENOTCONN - ECONNRESET → WSAECONNRESET - ENOPROTOOPT → WSAENOPROTOOPT - EPIPE → WSAESHUTDOWN (Windows equivalent) **2. Fixed mock_recv() Return Value:** - Now returns 0 when peer closes connection (orderly shutdown) - Previously returned -1 with ECONNRESET - This matches standard POSIX/Winsock behavior: - 0 = peer closed connection gracefully - -1 = error occurred (check errno/WSAGetLastError) - >0 = bytes received **Updated Functions:** - mock_socket, mock_bind, mock_listen, mock_accept - mock_connect, mock_recv, mock_send - mock_getsockopt, mock_setsockopt All socket functions now use correct error reporting mechanism for their platform, improving simulation accuracy.
Languages
C
98.4%
Shell
1%
Zig
0.4%
Batchfile
0.2%