hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Wrong code in C:\HaxeToolkit\haxe\lib\hxcpp\4,2,1\src\hx\libs\std\Socket.cpp

Open hypergeome opened this issue 3 years ago • 0 comments

I try to use Poll and found out _hx_std_socket_poll_events has issue. First, it does not clear p->outr and outw before memcpy. This result in garbage data in them and result in the next select call cause error slect() function error code:: 10038 - WSAENOTSOCK. It should be changed like below

#ifdef NEKO_WINDOWS
   POSIX_LABEL(select_again);
   memset(p->outr, 0, FDSIZE(p->max)); 
   memset(p->outw, 0, FDSIZE(p->max)); 
   memcpy(p->outr,p->fdr,FDSIZE(p->fdr->fd_count));
   memcpy(p->outw,p->fdw,FDSIZE(p->fdw->fd_count));

I knows it because I added log later

if( select(0/* Ignored */, p->fdr->fd_count ? p->outr : 0, p->fdw->fd_count ?p->outw : 0,NULL,tt) == SOCKET_ERROR )
   {
      hx::ExitGCFreeZone();
      HANDLE_EINTR(select_again);
      #ifdef NEKO_WINDOWS
      hx::Throw( HX_CSTRING("Select error ") + String((int)WSAGetLastError()) );
      #else
      hx::Throw( HX_CSTRING("Select error ") + String((i
[Socket.zip](https://github.com/HaxeFoundation/hxcpp/files/9300538/Socket.zip)
nt)errno) );
      #endif
      return;
   }

Also, as you can see, I add label and HANDLE_EINTR

I also found another issue with _hx_std_socket_select, in the select error block, it should throw correct error no by using WSAGetLastError for NEKO_WINDOWS instead of errno

Attached is the fixed file. Socket.zip

hypergeome avatar Aug 10 '22 13:08 hypergeome