mirror of
https://github.com/QuantumLeaps/qpc.git
synced 2025-01-28 07:03:10 +08:00
6.5.1
This commit is contained in:
parent
708e19a2d3
commit
3e5d7dd041
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief QUTEST port to POSIX
|
||||
* @brief QS/C QUTest port to POSIX
|
||||
* @ingroup ports
|
||||
* @cond
|
||||
******************************************************************************
|
||||
* Last updated for version 6.5.1
|
||||
* Last updated on 2019-05-31
|
||||
* Last Updated for Version: 6.5.1
|
||||
* Date of the Last Update: 2019-06-18
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ------------------------
|
||||
@ -41,7 +41,7 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#ifndef Q_SPY
|
||||
#error "Q_SPY must be defined for QTEST application"
|
||||
#error "Q_SPY must be defined to compile qutest_port.c"
|
||||
#endif /* Q_SPY */
|
||||
|
||||
#define QP_IMPL /* this is QP implementation */
|
||||
@ -68,7 +68,7 @@
|
||||
#define QS_TX_SIZE (8*1024)
|
||||
#define QS_RX_SIZE (2*1024)
|
||||
#define QS_TX_CHUNK QS_TX_SIZE
|
||||
#define QS_IMEOUT_MS 10
|
||||
#define QS_TIMEOUT_MS 10
|
||||
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
@ -111,7 +111,7 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
}
|
||||
*dst = '\0'; /* zero-terminate hostName */
|
||||
|
||||
/* extract port_remote from 'arg' (hostName:port_remote)... */
|
||||
/* extract serviceName from 'arg' (hostName:serviceName)... */
|
||||
if (*src == ':') {
|
||||
serviceName = src + 1;
|
||||
}
|
||||
@ -207,7 +207,7 @@ void QS_onReset(void) {
|
||||
void QS_onFlush(void) {
|
||||
uint16_t nBytes;
|
||||
uint8_t const *data;
|
||||
static struct timespec const c_10ms = { 0, 10000000L };
|
||||
static struct timespec const c_timeout = { 0, QS_TIMEOUT_MS*1000000L };
|
||||
|
||||
if (l_sock == INVALID_SOCKET) { /* socket NOT initialized? */
|
||||
fprintf(stderr, "<TARGET> ERROR invalid TCP socket\n");
|
||||
@ -220,10 +220,10 @@ void QS_onFlush(void) {
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
nanosleep(&c_10ms, NULL);
|
||||
nanosleep(&c_timeout, NULL);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -232,7 +232,7 @@ void QS_onFlush(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
nanosleep(&c_10ms, NULL); /* sleep for 10ms */
|
||||
nanosleep(&c_timeout, NULL); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -253,14 +253,14 @@ void QS_onTestLoop() {
|
||||
QS_rxPriv_.inTestLoop = true;
|
||||
while (QS_rxPriv_.inTestLoop) {
|
||||
struct timeval timeout = {
|
||||
(long)0, (long)(QS_IMEOUT_MS * 1000)
|
||||
(long)0, (long)(QS_TIMEOUT_MS * 1000)
|
||||
};
|
||||
int nrec;
|
||||
|
||||
FD_SET(l_sock, &readSet);
|
||||
|
||||
/* selective, timed blocking on the TCP/IP socket... */
|
||||
timeout.tv_usec = (long)(QS_IMEOUT_MS * 1000);
|
||||
timeout.tv_usec = (long)(QS_TIMEOUT_MS * 1000);
|
||||
nrec = select(l_sock + 1, &readSet,
|
||||
(fd_set *)0, (fd_set *)0, &timeout);
|
||||
if (nrec < 0) {
|
||||
|
@ -4,8 +4,8 @@
|
||||
* @ingroup ports
|
||||
* @cond
|
||||
******************************************************************************
|
||||
* Last updated for version 6.4.0
|
||||
* Last updated on 2019-02-10
|
||||
* Last Updated for Version: 6.5.1
|
||||
* Date of the Last Update: 2019-06-18
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ------------------------
|
||||
@ -66,13 +66,14 @@
|
||||
#define QS_TX_SIZE (8*1024)
|
||||
#define QS_RX_SIZE (2*1024)
|
||||
#define QS_TX_CHUNK QS_TX_SIZE
|
||||
#define QS_TIMEOUT_MS 10
|
||||
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
|
||||
/* local variables .........................................................*/
|
||||
static int l_sock = INVALID_SOCKET;
|
||||
static struct timespec const c_10ms = { 0, 10000000L };
|
||||
static struct timespec const c_timeout = { 0, QS_TIMEOUT_MS*1000000L };
|
||||
|
||||
/*..........................................................................*/
|
||||
uint8_t QS_onStartup(void const *arg) {
|
||||
@ -106,7 +107,7 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
}
|
||||
*dst = '\0'; /* zero-terminate hostName */
|
||||
|
||||
/* extract port_remote from 'arg' (hostName:port_remote)... */
|
||||
/* extract serviceName from 'arg' (hostName:serviceName)... */
|
||||
if (*src == ':') {
|
||||
serviceName = src + 1;
|
||||
}
|
||||
@ -198,6 +199,7 @@ void QS_onReset(void) {
|
||||
void QS_onFlush(void) {
|
||||
uint16_t nBytes;
|
||||
uint8_t const *data;
|
||||
QS_CRIT_STAT_
|
||||
|
||||
if (l_sock == INVALID_SOCKET) { /* socket NOT initialized? */
|
||||
fprintf(stderr, "<TARGET> ERROR invalid TCP socket\n");
|
||||
@ -205,15 +207,17 @@ void QS_onFlush(void) {
|
||||
}
|
||||
|
||||
nBytes = QS_TX_CHUNK;
|
||||
QS_CRIT_ENTRY_();
|
||||
while ((data = QS_getBlock(&nBytes)) != (uint8_t *)0) {
|
||||
QS_CRIT_EXIT_();
|
||||
for (;;) { /* for-ever until break or return */
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
nanosleep(&c_10ms, NULL);
|
||||
nanosleep(&c_timeout, NULL);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -222,7 +226,7 @@ void QS_onFlush(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
nanosleep(&c_10ms, NULL); /* sleep for 10ms */
|
||||
nanosleep(&c_timeout, NULL); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -233,7 +237,9 @@ void QS_onFlush(void) {
|
||||
}
|
||||
/* set nBytes for the next call to QS_getBlock() */
|
||||
nBytes = QS_TX_CHUNK;
|
||||
QS_CRIT_ENTRY_();
|
||||
}
|
||||
QS_CRIT_EXIT_();
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QSTimeCtr QS_onGetTime(void) {
|
||||
@ -250,6 +256,7 @@ QSTimeCtr QS_onGetTime(void) {
|
||||
void QS_output(void) {
|
||||
uint16_t nBytes;
|
||||
uint8_t const *data;
|
||||
QS_CRIT_STAT_
|
||||
|
||||
if (l_sock == INVALID_SOCKET) { /* socket NOT initialized? */
|
||||
fprintf(stderr, "<TARGET> ERROR invalid TCP socket\n");
|
||||
@ -257,15 +264,17 @@ void QS_output(void) {
|
||||
}
|
||||
|
||||
nBytes = QS_TX_CHUNK;
|
||||
QS_CRIT_ENTRY_();
|
||||
if ((data = QS_getBlock(&nBytes)) != (uint8_t *)0) {
|
||||
QS_CRIT_EXIT_();
|
||||
for (;;) { /* for-ever until break or return */
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
nanosleep(&c_10ms, NULL);
|
||||
nanosleep(&c_timeout, NULL);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -274,7 +283,7 @@ void QS_output(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
nanosleep(&c_10ms, NULL); /* sleep for 10ms */
|
||||
nanosleep(&c_timeout, NULL); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -284,6 +293,9 @@ void QS_output(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
QS_CRIT_EXIT_();
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void QS_rx_input(void) {
|
||||
|
@ -66,13 +66,14 @@
|
||||
#define QS_TX_SIZE (8*1024)
|
||||
#define QS_RX_SIZE (2*1024)
|
||||
#define QS_TX_CHUNK QS_TX_SIZE
|
||||
#define QS_TIMEOUT_MS 10
|
||||
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
|
||||
/* local variables .........................................................*/
|
||||
static int l_sock = INVALID_SOCKET;
|
||||
static struct timespec const c_10ms = { 0, 10000000L };
|
||||
static struct timespec const c_timeout = { 0, QS_TIMEOUT_MS*1000000L };
|
||||
|
||||
/*..........................................................................*/
|
||||
uint8_t QS_onStartup(void const *arg) {
|
||||
@ -213,10 +214,10 @@ void QS_onFlush(void) {
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
nanosleep(&c_10ms, NULL);
|
||||
nanosleep(&c_timeout, NULL);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -225,7 +226,7 @@ void QS_onFlush(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
nanosleep(&c_10ms, NULL); /* sleep for 10ms */
|
||||
nanosleep(&c_timeout, NULL); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -270,10 +271,10 @@ void QS_output(void) {
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
nanosleep(&c_10ms, NULL);
|
||||
nanosleep(&c_timeout, NULL);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -282,7 +283,7 @@ void QS_output(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
nanosleep(&c_10ms, NULL); /* sleep for 10ms */
|
||||
nanosleep(&c_timeout, NULL); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
|
@ -4,8 +4,8 @@
|
||||
* @ingroup ports
|
||||
* @cond
|
||||
******************************************************************************
|
||||
* Last updated for version 6.5.1
|
||||
* Last updated on 2019-05-31
|
||||
* Last Updated for Version: 6.5.1
|
||||
* Date of the Last Update: 2019-06-18
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ------------------------
|
||||
@ -38,7 +38,7 @@
|
||||
* @endcond
|
||||
*/
|
||||
#ifndef Q_SPY
|
||||
#error "Q_SPY must be defined for QTEST application"
|
||||
#error "Q_SPY must be defined to compile qutest_port.c"
|
||||
#endif /* Q_SPY */
|
||||
|
||||
#define QP_IMPL /* this is QP implementation */
|
||||
@ -69,7 +69,7 @@
|
||||
#define QS_TX_SIZE (8*1024)
|
||||
#define QS_RX_SIZE (2*1024)
|
||||
#define QS_TX_CHUNK QS_TX_SIZE
|
||||
#define QS_IMEOUT_MS 10
|
||||
#define QS_TIMEOUT_MS 10
|
||||
|
||||
/* local variables .........................................................*/
|
||||
static SOCKET l_sock = INVALID_SOCKET;
|
||||
@ -79,7 +79,7 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
static uint8_t qsBuf[QS_TX_SIZE]; /* buffer for QS-TX channel */
|
||||
static uint8_t qsRxBuf[QS_RX_SIZE]; /* buffer for QS-RX channel */
|
||||
char hostName[128];
|
||||
char const *serviceName = "6601"; /* default QSPY server port */
|
||||
char const *serviceName = "6601"; /* default QSPY server port */
|
||||
char const *src;
|
||||
char *dst;
|
||||
int status;
|
||||
@ -95,8 +95,8 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
QS_initBuf(qsBuf, sizeof(qsBuf));
|
||||
QS_rxInitBuf(qsRxBuf, sizeof(qsRxBuf));
|
||||
|
||||
/* initialize Windows sockets */
|
||||
if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) {
|
||||
/* initialize Windows sockets version 2.2 */
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) {
|
||||
fprintf(stderr,
|
||||
"<TARGET> ERROR Windows Sockets cannot be initialized\n");
|
||||
goto error;
|
||||
@ -115,7 +115,7 @@ uint8_t QS_onStartup(void const *arg) {
|
||||
}
|
||||
*dst = '\0'; /* zero-terminate hostName */
|
||||
|
||||
/* extract port_remote from 'arg' (hostName:port_remote)... */
|
||||
/* extract serviceName from 'arg' (hostName:serviceName)... */
|
||||
if (*src == ':') {
|
||||
serviceName = src + 1;
|
||||
}
|
||||
@ -213,10 +213,10 @@ void QS_onFlush(void) {
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
Sleep(10);
|
||||
Sleep(QS_TIMEOUT_MS);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -225,7 +225,7 @@ void QS_onFlush(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
Sleep(10); /* sleep for 10ms */
|
||||
Sleep(QS_TIMEOUT_MS); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -246,7 +246,7 @@ void QS_onTestLoop() {
|
||||
QS_rxPriv_.inTestLoop = true;
|
||||
while (QS_rxPriv_.inTestLoop) {
|
||||
struct timeval timeout = {
|
||||
(long)0, (long)(QS_IMEOUT_MS * 1000)
|
||||
(long)0, (long)(QS_TIMEOUT_MS * 1000)
|
||||
};
|
||||
int status;
|
||||
int ch;
|
||||
|
@ -4,14 +4,14 @@
|
||||
* @ingroup ports
|
||||
* @cond
|
||||
******************************************************************************
|
||||
* Last Updated for Version: 6.3.7
|
||||
* Date of the Last Update: 2018-11-29
|
||||
* Last Updated for Version: 6.5.1
|
||||
* Date of the Last Update: 2019-06-18
|
||||
*
|
||||
* Q u a n t u m L e a P s
|
||||
* ------------------------
|
||||
* Modern Embedded Software
|
||||
*
|
||||
* Copyright (C) 2005-2018 Quantum Leaps, LLC. All rights reserved.
|
||||
* Copyright (C) 2005-2019 Quantum Leaps, LLC. All rights reserved.
|
||||
*
|
||||
* This program is open source software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as published
|
||||
@ -50,13 +50,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <conio.h>
|
||||
#include <ws2tcpip.h> /* for Windows sockets */
|
||||
|
||||
/* Minimum required Windows version is Windows-XP or newer (0x0501) */
|
||||
#ifdef WINVER
|
||||
#undef WINVER
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
|
||||
#define WINVER _WIN32_WINNT_WINXP
|
||||
#define _WIN32_WINNT _WIN32_WINNT_WINXP
|
||||
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
//Q_DEFINE_THIS_MODULE("qs_port")
|
||||
|
||||
#define QS_TX_SIZE (8*1024)
|
||||
#define QS_RX_SIZE (2*1024)
|
||||
#define QS_TX_CHUNK QS_TX_SIZE
|
||||
#define QS_TIMEOUT_MS 10
|
||||
|
||||
/* local variables .........................................................*/
|
||||
static SOCKET l_sock = INVALID_SOCKET;
|
||||
@ -187,6 +200,7 @@ void QS_onReset(void) {
|
||||
void QS_onFlush(void) {
|
||||
uint16_t nBytes;
|
||||
uint8_t const *data;
|
||||
QS_CRIT_STAT_
|
||||
|
||||
if (l_sock == INVALID_SOCKET) { /* socket NOT initialized? */
|
||||
fprintf(stderr, "<TARGET> ERROR invalid TCP socket\n");
|
||||
@ -194,16 +208,18 @@ void QS_onFlush(void) {
|
||||
}
|
||||
|
||||
nBytes = QS_TX_CHUNK;
|
||||
QS_CRIT_ENTRY_();
|
||||
while ((data = QS_getBlock(&nBytes)) != (uint8_t *)0) {
|
||||
QS_CRIT_EXIT_();
|
||||
for (;;) { /* for-ever until break or return */
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
Sleep(10);
|
||||
Sleep(QS_TIMEOUT_MS);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -212,7 +228,7 @@ void QS_onFlush(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
Sleep(10); /* sleep for 10ms */
|
||||
Sleep(QS_TIMEOUT_MS); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -223,7 +239,9 @@ void QS_onFlush(void) {
|
||||
}
|
||||
/* set nBytes for the next call to QS_getBlock() */
|
||||
nBytes = QS_TX_CHUNK;
|
||||
QS_CRIT_ENTRY_();
|
||||
}
|
||||
QS_CRIT_EXIT_();
|
||||
}
|
||||
/*..........................................................................*/
|
||||
QSTimeCtr QS_onGetTime(void) {
|
||||
@ -236,6 +254,7 @@ QSTimeCtr QS_onGetTime(void) {
|
||||
void QS_output(void) {
|
||||
uint16_t nBytes;
|
||||
uint8_t const *data;
|
||||
QS_CRIT_STAT_
|
||||
|
||||
if (l_sock == INVALID_SOCKET) { /* socket NOT initialized? */
|
||||
fprintf(stderr, "<TARGET> ERROR invalid TCP socket\n");
|
||||
@ -243,16 +262,18 @@ void QS_output(void) {
|
||||
}
|
||||
|
||||
nBytes = QS_TX_CHUNK;
|
||||
QS_CRIT_ENTRY_();
|
||||
if ((data = QS_getBlock(&nBytes)) != (uint8_t *)0) {
|
||||
QS_CRIT_EXIT_();
|
||||
for (;;) { /* for-ever until break or return */
|
||||
int nSent = send(l_sock, (char const *)data, (int)nBytes, 0);
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
Sleep(10);
|
||||
Sleep(QS_TIMEOUT_MS);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -261,7 +282,7 @@ void QS_output(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
Sleep(10); /* sleep for 10ms */
|
||||
Sleep(QS_TIMEOUT_MS); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -271,6 +292,9 @@ void QS_output(void) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
QS_CRIT_EXIT_();
|
||||
}
|
||||
}
|
||||
/*..........................................................................*/
|
||||
void QS_rx_input(void) {
|
||||
|
@ -50,13 +50,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <conio.h>
|
||||
#include <ws2tcpip.h> /* for Windows sockets */
|
||||
|
||||
/* Minimum required Windows version is Windows-XP or newer (0x0501) */
|
||||
#ifdef WINVER
|
||||
#undef WINVER
|
||||
#endif
|
||||
#ifdef _WIN32_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#endif
|
||||
|
||||
#define WINVER _WIN32_WINNT_WINXP
|
||||
#define _WIN32_WINNT _WIN32_WINNT_WINXP
|
||||
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
//Q_DEFINE_THIS_MODULE("qs_port")
|
||||
|
||||
#define QS_TX_SIZE (8*1024)
|
||||
#define QS_RX_SIZE (2*1024)
|
||||
#define QS_TX_CHUNK QS_TX_SIZE
|
||||
#define QS_TIMEOUT_MS 10
|
||||
|
||||
/* local variables .........................................................*/
|
||||
static SOCKET l_sock = INVALID_SOCKET;
|
||||
@ -203,10 +216,10 @@ void QS_onFlush(void) {
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
Sleep(10);
|
||||
Sleep(QS_TIMEOUT_MS);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -215,7 +228,7 @@ void QS_onFlush(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
Sleep(10); /* sleep for 10ms */
|
||||
Sleep(QS_TIMEOUT_MS); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
@ -257,10 +270,10 @@ void QS_output(void) {
|
||||
if (nSent == SOCKET_ERROR) { /* sending failed? */
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK) {
|
||||
/* sleep for 10ms and then loop back
|
||||
/* sleep for the timeout and then loop back
|
||||
* to send() the SAME data again
|
||||
*/
|
||||
Sleep(10);
|
||||
Sleep(QS_TIMEOUT_MS);
|
||||
}
|
||||
else { /* some other socket error... */
|
||||
fprintf(stderr, "<TARGET> ERROR sending data over TCP,"
|
||||
@ -269,7 +282,7 @@ void QS_output(void) {
|
||||
}
|
||||
}
|
||||
else if (nSent < (int)nBytes) { /* sent fewer than requested? */
|
||||
Sleep(10); /* sleep for 10ms */
|
||||
Sleep(QS_TIMEOUT_MS); /* sleep for the timeout */
|
||||
/* adjust the data and loop back to send() the rest */
|
||||
data += nSent;
|
||||
nBytes -= (uint16_t)nSent;
|
||||
|
Loading…
x
Reference in New Issue
Block a user