HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
298 stars 189 forks source link

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

Open hypergeome opened 2 years ago

hypergeome commented 2 years ago

I found out the code of _hx_std_socket_send method is wrong. It has no HANDLE_EINTR like _hx_std_socket_send_char for ex. The result is that when I dump a big message, says about 200kb into socket, it keeps throwing Blocked while it should not. If I added label and HANDLE_EINTR like below, it works.

int _hx_std_socket_send( Dynamic o, Array<unsigned char> buf, int p, int l )
{
   SOCKET sock = val_sock(o);
   int dlen = buf->length;
   if( p < 0 || l < 0 || p > dlen || p + l > dlen )
      return 0;

   const char *base = (const char *)&buf[0];
   hx::EnterGCFreeZone();
   POSIX_LABEL(send_data_again);
   dlen = send(sock, base + p , l, MSG_NOSIGNAL);
   if( dlen == SOCKET_ERROR ){
      HANDLE_EINTR(send_data_again);
      block_error();
   }
   hx::ExitGCFreeZone();
   return dlen;
}