Skip to content

Commit 5a61168

Browse files
committed
Merge pull request #111 from nayato/port
Moving towards .NET Platform compatibility
2 parents c0d9ed2 + ebc82c4 commit 5a61168

12 files changed

Lines changed: 22 additions & 111 deletions

File tree

src/DotNetty.Codecs/CodecException.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace DotNetty.Codecs
88
/// <summary>
99
/// An <see cref="Exception" /> which is thrown by a codec.
1010
/// </summary>
11-
[Serializable]
1211
public class CodecException : Exception
1312
{
1413
public CodecException()

src/DotNetty.Codecs/Strings/StringDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class StringDecoder : MessageToMessageDecoder<IByteBuffer>
4343
/// character set.
4444
/// </summary>
4545
public StringDecoder()
46-
: this(Encoding.Default)
46+
: this(Encoding.GetEncoding(0))
4747
{
4848
}
4949

src/DotNetty.Codecs/Strings/StringEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class StringEncoder : MessageToMessageEncoder<string>
4040
/// character set.
4141
/// </summary>
4242
public StringEncoder()
43-
: this(Encoding.Default)
43+
: this(Encoding.GetEncoding(0))
4444
{
4545
}
4646

src/DotNetty.Codecs/UnsupportedMessageTypeException.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ namespace DotNetty.Codecs
99
/// <summary>
1010
/// Thrown if an unsupported message is received by an codec.
1111
/// </summary>
12-
[Serializable]
1312
public class UnsupportedMessageTypeException : CodecException
1413
{
15-
public UnsupportedMessageTypeException(
16-
object message, params Type[] expectedTypes)
17-
: base(ComposeMessage(
18-
message?.GetType().Name ?? "null", expectedTypes))
14+
public UnsupportedMessageTypeException(object message, params Type[] expectedTypes)
15+
: base(ComposeMessage(message?.GetType().Name ?? "null", expectedTypes))
1916
{
2017
}
2118

src/DotNetty.Common/Deque.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Nito
88
using System.Collections.Generic;
99
using System.Diagnostics;
1010
using System.Linq;
11+
using System.Reflection;
1112

1213
/// <summary>
1314
/// A double-ended queue (deque), which provides O(1) indexed access, O(1) removals from the front and back, amortized
@@ -276,12 +277,12 @@ bool ObjectIsT(object item)
276277

277278
if (item == null)
278279
{
279-
Type type = typeof(T);
280-
if (type.IsClass && !type.IsPointer)
280+
TypeInfo typeInfo = typeof(T).GetTypeInfo();
281+
if (typeInfo.IsClass && !typeInfo.IsPointer)
281282
return true; // classes, arrays, and delegates
282-
if (type.IsInterface)
283+
if (typeInfo.IsInterface)
283284
return true; // interfaces
284-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
285+
if (typeInfo.IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(Nullable<>))
285286
return true; // nullable value types
286287
}
287288

src/DotNetty.Common/ResourceLeakDetector.cs

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace DotNetty.Common
66
using System;
77
using System.Collections.Concurrent;
88
using System.Collections.Generic;
9-
using System.Diagnostics;
109
using System.Diagnostics.Contracts;
1110
using System.Runtime.CompilerServices;
1211
using System.Text;
@@ -210,7 +209,7 @@ public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
210209
DetectionLevel level = Level;
211210
if (level >= DetectionLevel.Advanced)
212211
{
213-
this.creationRecord = NewRecord(null, 3);
212+
this.creationRecord = NewRecord(null);
214213
}
215214
else
216215
{
@@ -226,15 +225,15 @@ public DefaultResourceLeak(ResourceLeakDetector owner, object referent)
226225
}
227226
}
228227

229-
public void Record() => this.RecordInternal(null, 3);
228+
public void Record() => this.RecordInternal(null);
230229

231-
public void Record(object hint) => this.RecordInternal(hint, 3);
230+
public void Record(object hint) => this.RecordInternal(hint);
232231

233-
void RecordInternal(object hint, int recordsToSkip)
232+
void RecordInternal(object hint)
234233
{
235234
if (this.creationRecord != null)
236235
{
237-
string value = NewRecord(hint, recordsToSkip);
236+
string value = NewRecord(hint);
238237

239238
lock (this.lastRecords)
240239
{
@@ -310,15 +309,7 @@ public override string ToString()
310309
}
311310
}
312311

313-
static readonly string[] StackTraceElementExclusions =
314-
{
315-
"DotNetty.Common.Utilities.ReferenceCountUtil.Touch(",
316-
"DotNetty.Buffers.AdvancedLeakAwareByteBuf.Touch(",
317-
"DotNetty.Buffers.AbstractByteBufAllocator.ToLeakAwareBuffer(",
318-
"DotNetty.Buffers.AdvancedLeakAwareByteBuf.RecordLeakNonRefCountingOperation("
319-
};
320-
321-
static string NewRecord(object hint, int recordsToSkip)
312+
static string NewRecord(object hint)
322313
{
323314
Contract.Ensures(Contract.Result<string>() != null);
324315

@@ -342,39 +333,7 @@ static string NewRecord(object hint, int recordsToSkip)
342333
}
343334

344335
// Append the stack trace.
345-
StackFrame[] array = new StackTrace().GetFrames();
346-
if (array != null)
347-
{
348-
foreach (StackFrame e in array)
349-
{
350-
if (recordsToSkip > 0)
351-
{
352-
recordsToSkip--;
353-
}
354-
else
355-
{
356-
string estr = e.ToString();
357-
358-
// Strip the noisy stack trace elements.
359-
bool excluded = false;
360-
foreach (string exclusion in StackTraceElementExclusions)
361-
{
362-
if (estr.StartsWith(exclusion, StringComparison.InvariantCulture))
363-
{
364-
excluded = true;
365-
break;
366-
}
367-
}
368-
369-
if (!excluded)
370-
{
371-
buf.Append('\t');
372-
buf.Append(estr);
373-
buf.Append(StringUtil.Newline);
374-
}
375-
}
376-
}
377-
}
336+
buf.Append(Environment.StackTrace);
378337

379338
return buf.ToString();
380339
}

src/DotNetty.Transport/Channels/ChannelException.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
namespace DotNetty.Transport.Channels
55
{
66
using System;
7-
using System.Runtime.Serialization;
87

9-
[Serializable]
108
public class ChannelException : Exception
119
{
1210
public ChannelException()
@@ -23,11 +21,6 @@ public ChannelException(string message, Exception innerException)
2321
{
2422
}
2523

26-
protected ChannelException(SerializationInfo info, StreamingContext context)
27-
: base(info, context)
28-
{
29-
}
30-
3124
public ChannelException(Exception innerException)
3225
: base(null, innerException)
3326
{

src/DotNetty.Transport/Channels/ChannelHandlerInvokerUtil.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace DotNetty.Transport.Channels
55
{
66
using System;
7-
using System.Diagnostics;
8-
using System.Linq.Expressions;
97
using System.Net;
108
using System.Threading.Tasks;
119
using DotNetty.Common.Utilities;
@@ -242,32 +240,8 @@ static void NotifyHandlerException(IChannelHandlerContext ctx, Exception cause)
242240
static Task ComposeExceptionTask(Exception cause) => TaskEx.FromException(cause);
243241

244242
// todo: use "nameof" once available
245-
static readonly string ExceptionCaughtMethodName = ((MethodCallExpression)((Expression<Action<IChannelHandler>>)(_ => _.ExceptionCaught(null, null))).Body).Method.Name;
243+
static readonly string ExceptionCaughtMethodName = nameof(IChannelHandler.ExceptionCaught);
246244

247-
static bool InExceptionCaught(Exception cause)
248-
{
249-
do
250-
{
251-
var trace = new StackTrace(cause);
252-
for (int index = 0; index < trace.FrameCount; index++)
253-
{
254-
StackFrame frame = trace.GetFrame(index);
255-
if (frame == null)
256-
{
257-
break;
258-
}
259-
260-
if (ExceptionCaughtMethodName.Equals(frame.GetMethod().Name, StringComparison.Ordinal))
261-
{
262-
return true;
263-
}
264-
}
265-
266-
cause = cause.InnerException;
267-
}
268-
while (cause != null);
269-
270-
return false;
271-
}
245+
static bool InExceptionCaught(Exception cause) => cause.StackTrace.IndexOf("." + ExceptionCaughtMethodName + "(", StringComparison.Ordinal) >= 0;
272246
}
273247
}

src/DotNetty.Transport/Channels/ChannelOutboundBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ internal void Close(ClosedChannelException cause)
622622
this.ClearNioBuffers();
623623
}
624624

625-
public long TotalPendingWriteBytes() => Thread.VolatileRead(ref this.totalPendingSize);
625+
public long TotalPendingWriteBytes() => Volatile.Read(ref this.totalPendingSize);
626626

627627
/// <summary>
628628
/// Call {@link IMessageProcessor#processMessage(Object)} for each flushed message

src/DotNetty.Transport/Channels/DefaultChannelConfiguration.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class DefaultChannelConfiguration : IChannelConfiguration
2626
volatile int maxMessagesPerRead;
2727
volatile int writeBufferHighWaterMark = 64 * 1024;
2828
volatile int writeBufferLowWaterMark = 32 * 1024;
29-
TimeSpan connectTimeout = DefaultConnectTimeout;
29+
long connectTimeout = DefaultConnectTimeout.Ticks;
3030

3131
protected readonly IChannel Channel;
3232

@@ -150,17 +150,11 @@ protected virtual void Validate<T>(ChannelOption<T> option, T value)
150150

151151
public TimeSpan ConnectTimeout
152152
{
153-
get
154-
{
155-
TimeSpan result = this.connectTimeout;
156-
Thread.MemoryBarrier();
157-
return result;
158-
}
153+
get { return new TimeSpan(Volatile.Read(ref this.connectTimeout)); }
159154
set
160155
{
161156
Contract.Requires(value >= TimeSpan.Zero);
162-
Thread.MemoryBarrier();
163-
this.connectTimeout = value;
157+
Volatile.Write(ref this.connectTimeout, value.Ticks);
164158
}
165159
}
166160

0 commit comments

Comments
 (0)