Skip to content

Commit

Permalink
Changed the way how active disconnects are done for libevent based TC…
Browse files Browse the repository at this point in the history
…P connections - should fix the remaining part of issue #43.
  • Loading branch information
s-ludwig committed Jun 27, 2012
1 parent 5602e36 commit 4997de4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions source/vibe/core/drivers/libevent2_tcp.d
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ package class Libevent2TcpConnection : TcpConnection {
TcpContext* m_ctx;
string m_peerAddress;
ubyte[64] m_peekBuffer;

}

this(TcpContext* ctx)
Expand Down Expand Up @@ -119,14 +120,20 @@ package class Libevent2TcpConnection : TcpConnection {
checkConnected();
auto fd = bufferevent_getfd(m_event);
m_ctx.shutdown = true;
bufferevent_setwatermark(m_event, EV_WRITE, 1, 0);
bufferevent_flush(m_event, EV_WRITE, bufferevent_flush_mode.BEV_FLUSH);
bufferevent_flush(m_event, EV_WRITE, bufferevent_flush_mode.BEV_FINISHED);
bufferevent_setwatermark(m_event, EV_WRITE, 1, 0);
logTrace("Closing socket %d...", fd);
while( m_ctx.event )
auto buf = bufferevent_get_output(m_ctx.event);
while( m_ctx.event && evbuffer_get_length(buf) > 0 )
m_ctx.core.yieldForEvent();

version(Windows) shutdown(m_ctx.socketfd, SD_SEND);
else shutdown(m_ctx.socketfd, SHUT_WR);
bufferevent_free(m_ctx.event);
heap_delete(m_ctx);
m_ctx = null;
logTrace("...socket %d closed.", fd);
}

/// The 'connected' status of this connection
Expand Down Expand Up @@ -414,12 +421,7 @@ package extern(C)
auto ctx = cast(TcpContext*)arg;
assert(ctx.event is buf_event, "Write event on bufferevent that does not match the TcpContext");
logTrace("socket %d write event (%s)!", ctx.socketfd, ctx.shutdown);
if( ctx.shutdown ){
version(Windows) shutdown(ctx.socketfd, SD_SEND);
else shutdown(ctx.socketfd, SHUT_WR);
bufferevent_free(buf_event);
ctx.event = null;
} else if( ctx.task && ctx.task.state != Fiber.State.TERM ){
if( ctx.task && ctx.task.state != Fiber.State.TERM ){
bufferevent_flush(buf_event, EV_WRITE, bufferevent_flush_mode.BEV_FLUSH);
}
if( ctx.task ) ctx.core.resumeTask(ctx.task);
Expand Down

0 comments on commit 4997de4

Please sign in to comment.