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