diff options
author | Iain Buclaw <ibuclaw@gcc.gnu.org> | 2019-02-10 14:27:17 +0000 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gcc.gnu.org> | 2019-02-10 14:27:17 +0000 |
commit | ab23d6fa98c395c4eb5dba58fa42397942e9da63 (patch) | |
tree | b10f91edff542464fc2e9071499eb9180c2f20ce /libphobos/src | |
parent | 2a484d14535e5a3bc4791a2faf4453c2f14fcfad (diff) | |
download | gcc-ab23d6fa98c395c4eb5dba58fa42397942e9da63.zip gcc-ab23d6fa98c395c4eb5dba58fa42397942e9da63.tar.gz gcc-ab23d6fa98c395c4eb5dba58fa42397942e9da63.tar.bz2 |
libphobos: Merge phobos upstream 6c9fb28b0
Fixes a thread deadlock that occurs in the test runner if libcurl is
missing.
Library fix for https://gcc.gnu.org/PR88654
Reviewed-on: https://github.com/dlang/phobos/pull/6824
From-SVN: r268746
Diffstat (limited to 'libphobos/src')
-rw-r--r-- | libphobos/src/MERGE | 2 | ||||
-rw-r--r-- | libphobos/src/std/net/curl.d | 33 |
2 files changed, 29 insertions, 6 deletions
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index eee4139..aef240e 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -d4933a90b1e8446c04d64cd044658f2b33250bd3 +6c9fb28b0f8813d41798202a9d19c6b37ba5da5f The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/std/net/curl.d b/libphobos/src/std/net/curl.d index 9d75141..e3ce527 100644 --- a/libphobos/src/std/net/curl.d +++ b/libphobos/src/std/net/curl.d @@ -178,7 +178,7 @@ version (unittest) import std.range; import std.stdio; - import std.socket : Address, INADDR_LOOPBACK, Socket, TcpSocket; + import std.socket : Address, INADDR_LOOPBACK, Socket, SocketShutdown, TcpSocket; private struct TestServer { @@ -192,6 +192,7 @@ version (unittest) private: string _addr; Tid tid; + TcpSocket sock; static void loop(shared TcpSocket listener) { @@ -215,20 +216,34 @@ version (unittest) private TestServer startServer() { + tlsInit = true; auto sock = new TcpSocket; sock.bind(new InternetAddress(INADDR_LOOPBACK, InternetAddress.PORT_ANY)); sock.listen(1); auto addr = sock.localAddress.toString(); auto tid = spawn(&TestServer.loop, cast(shared) sock); - return TestServer(addr, tid); + return TestServer(addr, tid, sock); } + __gshared TestServer server; + bool tlsInit; + private ref TestServer testServer() { - __gshared TestServer server; return initOnce!server(startServer()); } + static ~this() + { + // terminate server from a thread local dtor of the thread that started it, + // because thread_joinall is called before shared module dtors + if (tlsInit && server.sock) + { + server.sock.shutdown(SocketShutdown.RECEIVE); + server.sock.close(); + } + } + private struct Request(T) { string hdrs; @@ -429,7 +444,11 @@ if (isCurlConn!Conn) s.send(httpOK("Hello world")); }); auto fn = std.file.deleteme; - scope (exit) std.file.remove(fn); + scope (exit) + { + if (std.file.exists(fn)) + std.file.remove(fn); + } download(host, fn); assert(std.file.readText(fn) == "Hello world"); } @@ -491,7 +510,11 @@ if (isCurlConn!Conn) foreach (host; [testServer.addr, "http://"~testServer.addr]) { auto fn = std.file.deleteme; - scope (exit) std.file.remove(fn); + scope (exit) + { + if (std.file.exists(fn)) + std.file.remove(fn); + } std.file.write(fn, "upload data\n"); testServer.handle((s) { auto req = s.recvReq; |