X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fipdbg-la%2Fprotocol.c;h=ac36b060839ab61c477506bff5e3fa5668060f82;hb=c54ca323400bd03400e489cd5661bc28d81410c2;hp=4c97d0b9389e7d88547c4c07048a71a1230c3154;hpb=24fbd9f8140e5d6821a89d3e1d00136ffa56401e;p=libsigrok.git diff --git a/src/hardware/ipdbg-la/protocol.c b/src/hardware/ipdbg-la/protocol.c index 4c97d0b9..ac36b060 100644 --- a/src/hardware/ipdbg-la/protocol.c +++ b/src/hardware/ipdbg-la/protocol.c @@ -23,19 +23,15 @@ #define _WIN32_WINNT 0x0501 #include #include -#endif - -#include -#include - -#ifndef _WIN32 +#else #include #include #include #include #include #endif - +#include +#include #include #include "protocol.h" @@ -69,18 +65,17 @@ static gboolean data_available(struct ipdbg_la_tcp *tcp) { -#ifdef __WIN32__ - ioctlsocket(tcp->socket, FIONREAD, &bytes_available); +#ifdef _WIN32 + u_long bytes_available; + if(ioctlsocket(tcp->socket, FIONREAD, &bytes_available) != 0){ #else - int status; - - if (ioctl(tcp->socket, FIONREAD, &status) < 0) { // TIOCMGET + int bytes_available; + if (ioctl(tcp->socket, FIONREAD, &bytes_available) < 0){ // TIOCMGET +#endif sr_err("FIONREAD failed: %s\n", g_strerror(errno)); return FALSE; } - - return (status < 1) ? FALSE : TRUE; -#endif // __WIN32__ + return (bytes_available > 0); } SR_PRIV struct ipdbg_la_tcp *ipdbg_la_tcp_new(void) @@ -147,6 +142,15 @@ SR_PRIV int ipdbg_la_tcp_close(struct ipdbg_la_tcp *tcp) { int ret = SR_OK; +#ifdef _WIN32 + if (shutdown(tcp->socket, SD_SEND) != SOCKET_ERROR) + { + char recvbuf[16]; + int recvbuflen = 16; + // Receive until the peer closes the connection + while(recv(tcp->socket, recvbuf, recvbuflen, 0) > 0); + } +#endif if (close(tcp->socket) < 0) ret = SR_ERR; @@ -158,7 +162,7 @@ SR_PRIV int ipdbg_la_tcp_close(struct ipdbg_la_tcp *tcp) static int tcp_send(struct ipdbg_la_tcp *tcp, const uint8_t *buf, size_t len) { int out; - out = send(tcp->socket, buf, len, 0); + out = send(tcp->socket, (const char *)buf, len, 0); if (out < 0) { sr_err("Send error: %s", g_strerror(errno)); @@ -198,7 +202,7 @@ SR_PRIV int ipdbg_la_tcp_receive(struct ipdbg_la_tcp *tcp, if (data_available(tcp)) { while (received < 1) { - int len = recv(tcp->socket, buf, 1, 0); + int len = recv(tcp->socket, (char *)buf, 1, 0); if (len < 0) { sr_err("Receive error: %s", g_strerror(errno));