Skip to content

Commit

Permalink
Remove _linger
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Oct 15, 2019
1 parent ab92697 commit b972018
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ To be released.
disposed to clean up its internal resources. [[#485]]
- `IStore.IterateStateReferences()` method became to receive
`highestIndex`, `lowestIndex`, and `limit` parameters. [[#447], [#545]]
- Reworked `BlockChain<T>.GetStates()` into `GetState()` which takes only one `Address` instead of `IEnumerable<Address>`. [[#510], [#563]]
- Reworked `BlockChain<T>.GetStates()` into `GetState()` which takes only one
`Address` instead of `IEnumerable<Address>`. [[#510], [#563]]
- Removed the `linger` parameter from the `Swarm<T>` constructor and added `waitFor` to `Swarm<T>.StopAsync()`. [TBD]

### Added interfaces

Expand Down
19 changes: 11 additions & 8 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class Swarm<T> : IDisposable
private readonly AsyncLock _blockSyncMutex;
private readonly string _host;
private readonly IList<IceServer> _iceServers;
private readonly TimeSpan _linger;

private readonly ILogger _logger;

Expand Down Expand Up @@ -87,7 +86,6 @@ public Swarm(
PrivateKey privateKey,
int appProtocolVersion,
int millisecondsDialTimeout = 15000,
int millisecondsLinger = 1000,
string host = null,
int? listenPort = null,
DateTimeOffset? createdAt = null,
Expand All @@ -99,7 +97,6 @@ public Swarm(
privateKey,
appProtocolVersion,
TimeSpan.FromMilliseconds(millisecondsDialTimeout),
TimeSpan.FromMilliseconds(millisecondsLinger),
host,
listenPort,
createdAt,
Expand All @@ -113,7 +110,6 @@ public Swarm(
PrivateKey privateKey,
int appProtocolVersion,
TimeSpan dialTimeout,
TimeSpan linger,
string host = null,
int? listenPort = null,
DateTimeOffset? createdAt = null,
Expand Down Expand Up @@ -142,7 +138,6 @@ public Swarm(
_host = host;
_listenPort = listenPort;
_appProtocolVersion = appProtocolVersion;
_linger = linger;

if (_host != null && _listenPort is int listenPortAsInt)
{
Expand Down Expand Up @@ -286,15 +281,24 @@ public void Dispose()
}

public async Task StopAsync(
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default(CancellationToken)
)
{
await StopAsync(TimeSpan.FromSeconds(1), cancellationToken);
}

public async Task StopAsync(
TimeSpan waitFor,
CancellationToken cancellationToken = default(CancellationToken)
)
{
_workerCancellationTokenSource?.Cancel();
_logger.Debug("Stopping...");
using (await _runningMutex.LockAsync())
{
if (Running)
{
await Task.Delay(_linger, cancellationToken);
await Task.Delay(waitFor, cancellationToken);

_broadcastQueue.ReceiveReady -= DoBroadcast;
_replyQueue.ReceiveReady -= DoReply;
Expand Down Expand Up @@ -2024,7 +2028,6 @@ private async Task ProcessRuntime(

using (var dealer = new DealerSocket(ToNetMQAddress(req.Peer)))
{
dealer.Options.Linger = _linger;
_logger.Debug(
"Trying to send {@Message} to {PeerAddress}...",
req.Message,
Expand Down

0 comments on commit b972018

Please sign in to comment.