weixin_39939993
weixin_39939993
2021-01-12 06:07

NetSSL_Win: I/O error: bad address in SSL handshake

See http://pocoproject.org/forum/viewtopic.php?p=12721&sid=5f0a570b5fa0f2a0f067de91f58bbdbf#p12721 for explanation.

Patch:


diff --git a/Net/src/SocketImpl.cpp b/Net/src/SocketImpl.cpp
index a142807..70d7883 100644
--- a/Net/src/SocketImpl.cpp
+++ b/Net/src/SocketImpl.cpp
@@ -19,6 +19,7 @@
 #include "Poco/Net/StreamSocketImpl.h"
 #include "Poco/NumberFormatter.h"
 #include "Poco/Timestamp.h"
+#include "Poco/Thread.h"
 #include <string.h> // FD_SET needs memset on some platforms, so we can't use <cstring>
 #if defined(POCO_HAVE_FD_EPOLL)
 #include <sys>
@@ -43,6 +44,7 @@ using Poco::TimeoutException;
 using Poco::InvalidArgumentException;
 using Poco::NumberFormatter;
 using Poco::Timespan;
+using Poco::Thread;


 namespace Poco {
@@ -322,6 +324,10 @@ int SocketImpl::receiveBytes(void* buffer, int length, int flags)
        {
                if (_sockfd == POCO_INVALID_SOCKET) throw InvalidSocketException();
                rc = ::recv(_sockfd, reinterpret_cast<char>(buffer), length, flags);
+               if (rc < 0 && lastError() == POCO_EFAULT) {
+                       Thread::sleep(1);
+                       rc = ::recv(_sockfd, reinterpret_cast<char>(buffer), length, flags);
+               }
        }
        while (_blocking && rc < 0 && lastError() == POCO_EINTR);
        if (rc < 0)
</char></char></sys></cstring></string.h>

该提问来源于开源项目:pocoproject/poco

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39705065 weixin_39705065 4月前

    In further testing I still noticed I/O Errors to appear even with the workaround patch. There may be other cases, probably caused by same WSA bug and this is just minor improvement.

    点赞 评论 复制链接分享
  • weixin_39939993 weixin_39939993 4月前

    Will try to fix it for 1.7.6, but cannot make any promises it will make that release.

    点赞 评论 复制链接分享
  • weixin_39705065 weixin_39705065 4月前

    Additional note: This issue is not reproducible when using PocoNetSSL with OpenSSL instead of PocoNetSSLWin on Windows.

    点赞 评论 复制链接分享
  • weixin_39786534 weixin_39786534 4月前

    Hi, is there any ETA on a fix for this problem?

    点赞 评论 复制链接分享
  • weixin_39939993 weixin_39939993 4月前

    Probably will have to wait until I feel masochistic enough to expose myself to the SChannel API again. Someone sponsoring this kind of work could help alleviate the pain, though ;-) Also, contributions welcome.

    点赞 评论 复制链接分享