HaxeFoundation / HaxeFoundation/haxe

sys.ssl.Socket eof

Open
#6,244 1 comment 0 reactions 0 assignees View on GitHub
standard library
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Haxe: 3.4.2
Tested targets: neko & cpp

When `readBytes` from an ssl socket which is closed/ended, it should throw `Eof`.
But currently it throws `Custom(ssl@ssl_rev)`, reading one more time then it throws `Eof`

Code:
```haxe
class Main {
static function main() {
var socket = new sys.ssl.Socket(), port = 443;
// var socket = new sys.net.Socket(), port = 80;
socket.connect(new sys.net.Host('httpbin.org'), port);
socket.output.write(haxe.io.Bytes.ofString('GET /get?a=1&b=2 HTTP/1.1\r\nhost: httpbin.org\r\nconnection: close\r\n\r\n'));

function read(msg) {
try {
var res = haxe.io.Bytes.alloc(1024);
var read = socket.input.readBytes(res, 0, 1024);
trace('$msg: $read: ' + haxe.Json.stringify(res.sub(0, read).toString()));
} catch (e:Dynamic) {
trace('$msg: $e');
}
}

read('first read');
read('second read');
read('third read');
}
}
```

On my machine it prints:

```
Main.hx:12: first read: 439: "HTTP/1.1 200 OK..."
Main.hx:14: second read: Custom(ssl@ssl_recv)
Main.hx:14: third read: Eof
```

Note that in second read it throws a `ssl_recv` error, but I think should be `Eof` instead.

Uncommenting the insecure (port 80) counterpart, it prints:

```
Main.hx:12: first read: 296: "HTTP/1.1 200 OK..."
Main.hx:12: second read: 211: "..."
Main.hx:14: third read: Eof
```

Note that it throws `Eof` immediately when the socket is ended.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.