Fix socket connecting synchronously (#413)

This commit is contained in:
Varun Puranik 2018-08-08 10:11:25 -07:00 коммит произвёл Max Gortman
Родитель f5a7f3bf03
Коммит e67df7994f
2 изменённых файлов: 16 добавлений и 13 удалений

Просмотреть файл

@ -318,16 +318,6 @@ namespace DotNetty.Transport.Channels.Sockets
void FulfillConnectPromise(bool wasActive)
{
TaskCompletionSource promise = this.Channel.connectPromise;
if (promise == null)
{
// Closed via cancellation and the promise has been notified already.
return;
}
// trySuccess() will return false if a user cancelled the connection attempt.
bool promiseSet = promise.TryComplete();
// Regardless if the connection attempt was cancelled, channelActive() event should be triggered,
// because what happened is what happened.
if (!wasActive && this.channel.Active)
@ -335,10 +325,19 @@ namespace DotNetty.Transport.Channels.Sockets
this.channel.Pipeline.FireChannelActive();
}
// If a user cancelled the connection attempt, close the channel, which is followed by channelInactive().
if (!promiseSet)
TaskCompletionSource promise = this.Channel.connectPromise;
// If promise is null, then it the channel was Closed via cancellation and the promise has been notified already.
if (promise != null)
{
this.CloseSafe();
// trySuccess() will return false if a user cancelled the connection attempt.
bool promiseSet = promise.TryComplete();
// If a user cancelled the connection attempt, close the channel, which is followed by channelInactive().
if (!promiseSet)
{
this.CloseSafe();
}
}
}

Просмотреть файл

@ -126,6 +126,10 @@ namespace DotNetty.Transport.Channels.Sockets
var eventPayload = new SocketChannelAsyncOperation(this, false);
eventPayload.RemoteEndPoint = remoteAddress;
bool connected = !this.Socket.ConnectAsync(eventPayload);
if(connected)
{
this.DoFinishConnect(eventPayload);
}
success = true;
return connected;
}