Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions std/lua/_std/sys/net/Socket.hx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Socket {

var custom:Dynamic;

var _socket:LuaSocket;
var _socket:Null<LuaSocket>;

var blocking = false;
var timeout = null;
Expand All @@ -86,7 +86,8 @@ class Socket {
}

public function close():Void {
_socket.close();
if (_socket != null)
_socket.close();
}

public function read():String {
Expand Down
5 changes: 3 additions & 2 deletions std/lua/_std/sys/ssl/Socket.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import haxe.io.Error;

@:coreApi(check = Off)
class Socket extends sys.net.Socket {
var _sslSocket:SslTcpClient;
var _sslSocket:Null<SslTcpClient>;

private function wrap(sock:LuaSocket):SslTcpClient {
var res = LuaSecSsl.wrap(sock, {mode: Client, protocol: Any});
Expand Down Expand Up @@ -78,7 +78,8 @@ class Socket extends sys.net.Socket {
}

public override function close():Void {
_sslSocket.close();
if (_sslSocket != null)
_sslSocket.close();
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/sys/src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Main {
#if false
runner.addCase(new net.TestAsyncSocket( #if (hl_ver < version("1.16.0")) false #end ));
#end
#if (!jvm && !php && !js && !python)
runner.addCase(new ssl.TestSocket());
#end
var report = Report.create(runner);
report.displayHeader = AlwaysShowHeader;
report.displaySuccessResults = NeverShowSuccessResults;
Expand Down
10 changes: 10 additions & 0 deletions tests/sys/src/net/TestSocket.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ class TestSocket extends utest.Test {
Assert.pass();
}
#end

function testImmediateClose() {
try {
final socket = new Socket();
socket.close();
Assert.pass();
} catch (e) {
Assert.fail('Closing unused socket failed: ${e}');
}
}
}
16 changes: 16 additions & 0 deletions tests/sys/src/ssl/TestSocket.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ssl;

import sys.ssl.*;
import utest.Assert;

class TestSocket extends utest.Test {
function testImmediateClose() {
try {
final socket = new Socket();
socket.close();
Assert.pass();
} catch (e) {
Assert.fail('Closing unused socket failed: ${e}');
}
}
}
2 changes: 0 additions & 2 deletions tests/unit/src/unit/issues/Issue13031.hx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ private class RequestSocket extends sys.net.Socket {
public override function close() {
input = originalInput;
output = originalOutput;
#if !lua
super.close();
#end
}
}
#end
Loading