Skip to content

Commit

Permalink
fix serialport ERROR_IO_PENDING check bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zlw2019 committed Nov 25, 2024
1 parent 7b93885 commit 50847e2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmake/Thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if(WIN32)
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/curl
CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/curl -DBUILD_TESTING=OFF
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/curl-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release -- /maxcpucount:4
Expand Down
2 changes: 1 addition & 1 deletion unit-test/util/test_tc_serialport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TEST_F(UtilSerialPortTest, test)
TC_SerialPort::Options options;

// options.portName = "/dev/tty.usbmodem00000000050C1";
options.portName = "COM3";
options.portName = "//./COM14";

options.baudRate = 9600;
options.stopBits = 0;
Expand Down
13 changes: 9 additions & 4 deletions util/src/tc_serialport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ void TC_SerialPort::initialize()
{
callback->onOpen();
}

}

void TC_SerialPort::setParserCallback(const onparser_callback & onparser)
Expand Down Expand Up @@ -829,8 +830,9 @@ int TC_SerialPort::send(const void *buf, uint32_t len)
{
int nerr = TC_Exception::getSystemCode();
string err = "send error, errno:" + TC_Common::tostr(nerr) + "," + TC_Exception::parseError(nerr);
HANDLE fd = _serialFd;
close();
throw TC_SerialPortException("TC_SerialPort::send, fd:" + TC_Common::tostr(_serialFd) + ", error:" + err);
throw TC_SerialPortException("TC_SerialPort::send, fd:" + TC_Common::tostr(fd) + ", error:" + err);
}

return dwBytesWritten;
Expand All @@ -841,8 +843,9 @@ int TC_SerialPort::send(const void *buf, uint32_t len)
{
int nerr = TC_Exception::getSystemCode();
string err = "send error, errno:" + TC_Common::tostr(nerr) + "," + TC_Exception::parseError(nerr);
int fd = _serialFd;
close();
throw TC_SerialPortException("TC_SerialPort::send, fd:" + TC_Common::tostr(_serialFd) + ", error:" + err);
throw TC_SerialPortException("TC_SerialPort::send, fd:" + TC_Common::tostr(fd) + ", error:" + err);
}
return iRet;

Expand Down Expand Up @@ -877,8 +880,9 @@ int TC_SerialPort::recv()
{
int nerr = TC_Exception::getSystemCode();
string err = "recv error, errno:" + TC_Common::tostr(nerr) + "," + TC_Exception::parseError(nerr);
HANDLE fd = _serialFd;
close();
throw TC_SerialPortException("TC_SerialPort::recv, fd:" + TC_Common::tostr(_serialFd) + ", error:" + err);
throw TC_SerialPortException("TC_SerialPort::recv, fd:" + TC_Common::tostr(fd) + ", error:" + err);
}

if(dwBytesRead > 0){
Expand All @@ -898,8 +902,9 @@ int TC_SerialPort::recv(void *buf, uint32_t len)
{
int nerr = TC_Exception::getSystemCode();
string err = "recv error, errno:" + TC_Common::tostr(nerr) + "," + TC_Exception::parseError(nerr);
int fd = _serialFd;
close();
throw TC_SerialPortException("TC_SerialPort::recv, fd:" + TC_Common::tostr(_serialFd) + ", error:" + err);
throw TC_SerialPortException("TC_SerialPort::recv, fd:" + TC_Common::tostr(fd) + ", error:" + err);
}
return iRet;
}
Expand Down
4 changes: 2 additions & 2 deletions util/src/tc_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ vector<string> TC_Socket::getLocalHosts(int domain, bool withLoopIp)
bool TC_Socket::isPending()
{
#if TARGET_PLATFORM_WINDOWS
return TC_Exception::getSystemCode() == WSAEWOULDBLOCK;
return TC_Exception::getSystemCode() == WSAEWOULDBLOCK || TC_Exception::getSystemCode() == ERROR_IO_PENDING;
#else
return TC_Exception::getSystemCode() == EAGAIN;
#endif
Expand All @@ -1031,7 +1031,7 @@ bool TC_Socket::isPending()
bool TC_Socket::isInProgress()
{
#if TARGET_PLATFORM_WINDOWS
return TC_Exception::getSystemCode() == WSAEWOULDBLOCK;
return TC_Exception::getSystemCode() == WSAEWOULDBLOCK || TC_Exception::getSystemCode() == ERROR_IO_PENDING;
#else
return TC_Exception::getSystemCode() == EINPROGRESS;
#endif
Expand Down

0 comments on commit 50847e2

Please sign in to comment.