HaxeFoundation / HaxeFoundation/haxe
haxe.io.Error.Blocked vs haxe.io.Error.Blocking
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
Sockets blocking operations in non-blocking mode throw something strange.
Documentation says:
http://api.haxe.org/sys/net/Socket.html
> setBlocking (b:Bool):Void
>
> Change the blocking mode of the socket. A blocking socket is the default behavior. A non-blocking socket will abort blocking operations immediatly by throwing a **haxe.io.Error.Blocking** value.
http://api.haxe.org/haxe/io/Error.html
> **Blocked**
>
> The IO is set into nonblocking mode and some data cannot be read or written
It looks like a typo in documentation: Blocked vs Blocking. But both parts of documentation are correct. Sockets really throws 'Blocking' and Error really only have 'Blocked'.
``` haxe
import haxe.io.Error;
import sys.net.Host;
import sys.net.Socket;
class Main {
static function main() {
var socket = new Socket();
socket.connect(new Host('google.com'), 80);
socket.setBlocking(false);
try {
throw Error.Blocked;
}
catch(e:Error) {
trace('catched $e'); // trace: Main.hx:17: catched Blocked
}
try {
trace(socket.read());
}
catch(e:Dynamic) {
trace('catched $e', Reflect.isEnumValue(e), Reflect.isObject(e), Type.getClass(e));
// trace: Main.hx:23: catched Blocking,false,true,String
}
try {
trace(socket.read());
}
catch(e:Error) {
trace('catched $e'); // never executed, but get unhandled exception:
//Called from hxcpp::__hxcpp_main
//Called from Main::main Main.hx line 28
//Error : Blocking
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.