Code to reproduce:
import haxe.Timer;
import haxe.io.Error;
class Main {
static function main() {
var socket = new sys.ssl.Socket();
try {
socket.setBlocking(false);
socket.connect(new sys.net.Host("haxe.org"), 443);
}
catch (e:Dynamic) {}
function tryHandshake():Void {
var result = sys.net.Socket.select(null, [socket], null, 0);
if (result.write[0] != socket) {
Timer.delay(tryHandshake, 16);
return;
}
try {
socket.handshake();
}
catch (e:Error)
{
switch (e)
{
case Error.Blocked:
Timer.delay(tryHandshake, 16);
case Error.Custom(Error.Blocked):
Timer.delay(tryHandshake, 16);
default:
trace("handshake failed 1: " + e);
}
return;
}
catch (e:Dynamic)
{
trace("handshake failed 2: " + e);
return;
}
trace("handshake succeeded");
}
Timer.delay(tryHandshake, 16);
}
}
Build command:
haxe -cp src -main Main -debug -cpp out -D HXCPP_M64
If you remove one of -debug
or -D HXCPP_M64
(or both), the handshake completes successfully. If the socket is blocking, the handshake completes successfully.
I confirmed that it works correctly with all combinations on macOS.
Haxe 4.2.5
hxcpp 4.2.1
Windows 11 Pro 22H2 (a colleague also reproduces on Windows 10)
For reference, I also reported this as issue hxcpp#1033, but I wanted to cross-post here for wider visibility.