Skip to content

Commit

Permalink
Started to use Socket.ExclusiveAddressUse.
Browse files Browse the repository at this point in the history
Fixed ASYNC code.
Enhanced v3 too big check.
  • Loading branch information
lextm committed Nov 11, 2010
1 parent 7538e7b commit 7bfe3eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 12 additions & 7 deletions SharpSnmpLib/Messaging/ListenerBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void Start()
return;
}

_socket = new Socket(addressFamily, SocketType.Dgram, ProtocolType.Udp);
_socket = new Socket(addressFamily, SocketType.Dgram, ProtocolType.Udp) { ExclusiveAddressUse = true };

try
{
Expand Down Expand Up @@ -244,10 +244,10 @@ private void AsyncBeginReceive()
while (true)
{
// If no more active, then stop.
if (Interlocked.Read(ref _active) == 0)
if (Interlocked.Read(ref _active) == Inactive)
{
return;

//Console.WriteLine("Waiting");
}

byte[] buffer = new byte[_bufferSize];
EndPoint remote = new IPEndPoint(IPAddress.Any, 0);
Expand All @@ -271,16 +271,21 @@ private void AsyncBeginReceive()
}
}

iar.AsyncWaitHandle.WaitOne();
if (iar != null)
{
iar.AsyncWaitHandle.WaitOne();
}
}
}

private void AsyncEndReceive(IAsyncResult iar)
{
// If no more active, then stop. This discards the received packet, if any (indeed, we may be there either
// because we've received a packet, or because the socket has been closed).
if (Interlocked.Read(ref _active) == 0)
if (Interlocked.Read(ref _active) == Inactive)
{
return;
}

//// We start another receive operation.
//AsyncBeginReceive();
Expand All @@ -289,7 +294,7 @@ private void AsyncEndReceive(IAsyncResult iar)

try
{
EndPoint remote = new IPEndPoint(IPAddress.Any, 0);
EndPoint remote = _socket.AddressFamily == AddressFamily.InterNetwork ? new IPEndPoint(IPAddress.Any, 0) : new IPEndPoint(IPAddress.IPv6Any, 0);
int count = _socket.EndReceiveFrom(iar, ref remote);
HandleMessage(new MessageParams(buffer, count, remote));
}
Expand Down
5 changes: 5 additions & 0 deletions SharpSnmpLib/Pipeline/SecureSnmpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public override void GenerateTooBig()
Request.Pdu.Variables)),
privacy,
true);
if (TooBig)
{
Response = null;
// TODO: snmpSilentDrops++;
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SharpSnmpLib/SharpSnmpLib.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down

0 comments on commit 7bfe3eb

Please sign in to comment.