Merge pull request #70 from vibe-d/fix_connectionpool_tcpconnection

Fix compilation of ConnectionPool!struct. Fixes vibe-d/vibe.d#2109.
This commit is contained in:
Sönke Ludwig 2018-03-11 12:21:19 +01:00 committed by GitHub
commit 24ee40ea25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -90,6 +90,7 @@ final class ConnectionPool(Connection)
} else {
logDebug("creating new %s connection, all %d are in use", Connection.stringof, m_connections.length);
conn = m_connectionFactory(); // NOTE: may block
static if (is(typeof(cast(void*)conn)))
logDebug(" ... %s", () @trusted { return cast(void*)conn; } ());
}
m_lockCount[conn] = 1;
@ -131,6 +132,12 @@ unittest {
c3.write();
}
unittest { // issue vibe-d#2109
import vibe.core.net : TCPConnection, connectTCP;
new ConnectionPool!TCPConnection({ return connectTCP("127.0.0.1", 8080); });
}
struct LockedConnection(Connection) {
import vibe.core.task : Task;
@ -145,7 +152,7 @@ struct LockedConnection(Connection) {
private this(ConnectionPool!Connection pool, Connection conn)
{
assert(conn !is null);
assert(!!conn);
m_pool = pool;
m_conn = conn;
m_task = Task.getThis();
@ -154,10 +161,11 @@ struct LockedConnection(Connection) {
this(this)
{
debug assert(m_magic == 0xB1345AC2, "LockedConnection value corrupted.");
if( m_conn ){
if (!!m_conn) {
auto fthis = Task.getThis();
assert(fthis is m_task);
m_pool.m_lockCount[m_conn]++;
static if (is(typeof(cast(void*)conn)))
logTrace("conn %s copy %d", () @trusted { return cast(void*)m_conn; } (), m_pool.m_lockCount[m_conn]);
}
}
@ -165,7 +173,7 @@ struct LockedConnection(Connection) {
~this()
{
debug assert(m_magic == 0xB1345AC2, "LockedConnection value corrupted.");
if( m_conn ){
if (!!m_conn) {
auto fthis = Task.getThis();
assert(fthis is m_task, "Locked connection destroyed in foreign task.");
auto plc = m_conn in m_pool.m_lockCount;
@ -176,7 +184,7 @@ struct LockedConnection(Connection) {
() @trusted { m_pool.m_sem.unlock(); } ();
//logTrace("conn %s release", cast(void*)m_conn);
}
m_conn = null;
m_conn = Connection.init;
}
}