I have a master master slave application running on WinXp (i7, 2.1 Ghz), and the slave is the controller board. The master sends a request to the slave and the slave in response sends data to the master cyclically. This data is transmitted cyclically by a slave of 1000 bytes in 0.5 ms. When the wizards send a request to send data, an error is reported to the console.
"Select () function error code :: 10038".
This is the code for WSAENOTSOCK .
This application is a single-threaded application that receives data from a slave device. As from an error, it seems that the socket is closed before it is checked by the select function.
Can someone point me in a direction?
: Source::
int Receive() { int rc; socklen_t cli_alen; struct timeval to; fd_set read_fd, write_fd, excep_fd; FD_ZERO(&write_fd); FD_ZERO(&excep_fd); sock_again: if (!_isSocketOpen) { return 0; } FD_ZERO(&read_fd); FD_SET(_sock_fd, &read_fd); to.tv_sec = 0; to.tv_usec = 0; cli_alen = sizeof(SOCKADDR_IN); rc = select(_sock_fd+1, &read_fd, &write_fd, &excep_fd, &to); if (rc == 0 ) { // Timeout // printf("XCP Port %d : select() timded out \n", _port); acess = 1; goto sock_again; } else if (rc == SOCKET_ERROR) { // Error LogError("XCP: select() error %d", WSAGetLastError()); closesocket(_sock_fd); return -1; } else { // Data if (!FD_ISSET(_sock_fd, &read_fd)) { LogError("XCP: select() wrong socket descr"); return -1; } else { //read data rc = recvfrom(_sock_fd, (char *)_recvBuf, UDP_RECVBUFLEN, 0, (LPSOCKADDR)&_saddr, &cli_alen); } } }
:: Edited ::
int CloseUdpConnection() { if (closesocket(_sock_fd) == SOCKET_ERROR) { LogError("closesocket() error: %d", WSAGetLastError()); return -1; } _isSocketOpen = 0; LogError("successfully closed socket %s:%d", _address, _port); return 0; }
::: Trace debugging :::
xcpApplication.exe -i 192.168.1.100 -p 5555 c --> Connecting... <-- Connection established t --> Setting daq signal list... Sorting daq signal list... Sorting done <-- Daq signal list set d --> Configuring daq lists... <-- Configuration done r --> Starting measurement... <-- Measurement started **_sock_fd: -448997078** XCP: select() error 10038
::: Trace ::
--> Starting measurement... <-- Measurement started _sock_fd: -1963260928 _sock_fd: 0x8afb0400 XCP: select() error 10038
:: Trace ::
xcpApplication.exe -i 192.168.1.100 -p 5555 _sock_fd: 1936 _sock_fd: 0x790 successfully opened socket 192.168.1.100:5555 --> Connecting... <-- Connection established t --> Setting daq signal list... Sorting daq signal list... Sorting done <-- Daq signal list set d --> Configuring daq lists... <-- Configuration done c --> Connecting... <-- Connection established r --> Starting measurement... <-- Measurement started _sock_fd: 901186560 _sock_fd: 0x35b70400 XCP: select() error 10038