HaxeFoundation / HaxeFoundation/hxcpp
Wrong code in C:\HaxeToolkit\haxe\lib\hxcpp\4,2,1\src\hx\libs\std\Socket.cpp
- Dominant language
- C++
- Stars
- 330
- Forks
- 227
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 18
Description
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
```cpp
#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
```cpp
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](https://github.com/HaxeFoundation/hxcpp/files/9300540/Socket.zip)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.