Merge remote-tracking branch 'origin/master' into enhanced_device

# Conflicts:
#	src/lib/ebus/device.cpp
This commit is contained in:
john30
2020-01-25 15:27:11 +01:00
13 changed files with 103 additions and 35 deletions
+30 -1
View File
@@ -515,6 +515,17 @@ void SerialDevice::checkDevice() {
}
}
#ifdef __CYGWIN__
#ifndef TCP_KEEPCNT
#define TCP_KEEPCNT 8
#endif
#ifndef TCP_KEEPINTVL
#define TCP_KEEPINTVL 150
#endif
#ifndef TCP_KEEPIDLE
#define TCP_KEEPIDLE 14400
#endif
#endif
result_t NetworkDevice::open() {
result_t result = Device::open();
@@ -535,6 +546,12 @@ result_t NetworkDevice::open() {
ret = setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<void*>(&value), sizeof(value));
value = 1;
setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<void*>(&value), sizeof(value));
value = 3; // send keepalive after 3 seconds of silence
setsockopt(m_fd, IPPROTO_TCP, TCP_KEEPIDLE, reinterpret_cast<void*>(&value), sizeof(value));
value = 2; // send keepalive in interval of 2 seconds
setsockopt(m_fd, IPPROTO_TCP, TCP_KEEPINTVL, reinterpret_cast<void*>(&value), sizeof(value));
value = 2; // drop connection after 2 failed keep alive sends
setsockopt(m_fd, IPPROTO_TCP, TCP_KEEPCNT, reinterpret_cast<void*>(&value), sizeof(value));
}
if (ret >= 0) {
ret = connect(m_fd, (struct sockaddr*)&m_address, sizeof(m_address));
@@ -548,13 +565,25 @@ result_t NetworkDevice::open() {
}
int cnt;
symbol_t buf[MTU];
while (ioctl(m_fd, FIONREAD, &cnt) >= 0 && cnt > 1) {
int ioerr;
while ((ioerr=ioctl(m_fd, FIONREAD, &cnt)) >= 0 && cnt > 1) {
// skip buffered input
ssize_t read = ::read(m_fd, &buf, MTU);
if (read <= 0) {
break;
}
}
if (ioerr < 0) {
close();
return RESULT_ERR_GENERIC_IO;
}
if (m_bufSize == 0) {
m_bufSize = MAX_LEN+1;
m_buffer = reinterpret_cast<symbol_t*>(malloc(m_bufSize));
if (!m_buffer) {
m_bufSize = 0;
}
}
m_bufLen = 0;
if (m_initialSend && !write(ESC)) {
return RESULT_ERR_SEND;