Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit c50aec1

Browse files
committed
Adding comments to meaningless field names
1 parent dffd977 commit c50aec1

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ abstract public class ListenerPrimary : Listener
1717
{
1818
private List<UvPipeHandle> _dispatchPipes = new List<UvPipeHandle>();
1919
private int _dispatchIndex;
20-
private ArraySegment<ArraySegment<byte>> _binaryOneTwoThreeFour = new ArraySegment<ArraySegment<byte>>(new[] { new ArraySegment<byte>(new byte[] { 1, 2, 3, 4 }) });
20+
21+
// this message is passed to write2 because it must be non-zero-length,
22+
// but it has no other functional significance
23+
private readonly ArraySegment<ArraySegment<byte>> _dummyMessage = new ArraySegment<ArraySegment<byte>>(new[] { new ArraySegment<byte>(new byte[] { 1, 2, 3, 4 }) });
2124

2225
protected ListenerPrimary(IMemoryPool memory) : base(memory)
2326
{
@@ -79,7 +82,7 @@ protected override void DispatchConnection(UvStreamHandle socket)
7982
write.Init(Thread.Loop);
8083
write.Write2(
8184
dispatchPipe,
82-
_binaryOneTwoThreeFour,
85+
_dummyMessage,
8386
socket,
8487
(write2, status, error, state) =>
8588
{

src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel
1616
/// </summary>
1717
public class KestrelThread
1818
{
19-
private static Action<object, object> _objectCallback = (cb, obj) => ((Action<object>)cb).Invoke(obj);
19+
private static Action<object, object> _objectCallbackAdapter = (callback, state) => ((Action<object>)callback).Invoke(state);
2020
private KestrelEngine _engine;
2121
private Thread _thread;
2222
private UvLoopHandle _loop;
@@ -103,7 +103,7 @@ public void Post(Action<object> callback, object state)
103103
{
104104
lock (_workSync)
105105
{
106-
_workAdding.Enqueue(new Work { Callback1 = _objectCallback, Callback2 = callback, State = state });
106+
_workAdding.Enqueue(new Work { CallbackAdapter = _objectCallbackAdapter, Callback = callback, State = state });
107107
}
108108
_post.Send();
109109
}
@@ -114,8 +114,8 @@ public void Post<T>(Action<T> callback, T state)
114114
{
115115
_workAdding.Enqueue(new Work
116116
{
117-
Callback1 = (state1, state2) => ((Action<T>)state1).Invoke((T)state2),
118-
Callback2 = callback,
117+
CallbackAdapter = (callback2, state2) => ((Action<T>)callback2).Invoke((T)state2),
118+
Callback = callback,
119119
State = state
120120
});
121121
}
@@ -129,8 +129,8 @@ public Task PostAsync(Action<object> callback, object state)
129129
{
130130
_workAdding.Enqueue(new Work
131131
{
132-
Callback1 = _objectCallback,
133-
Callback2 = callback,
132+
CallbackAdapter = _objectCallbackAdapter,
133+
Callback = callback,
134134
State = state,
135135
Completion = tcs
136136
});
@@ -146,8 +146,8 @@ public Task PostAsync<T>(Action<T> callback, T state)
146146
{
147147
_workAdding.Enqueue(new Work
148148
{
149-
Callback1 = (state1, state2) => ((Action<T>)state1).Invoke((T)state2),
150-
Callback2 = callback,
149+
CallbackAdapter = (state1, state2) => ((Action<T>)state1).Invoke((T)state2),
150+
Callback = callback,
151151
State = state,
152152
Completion = tcs
153153
});
@@ -250,7 +250,7 @@ private void DoPostWork()
250250
var work = queue.Dequeue();
251251
try
252252
{
253-
work.Callback1(work.Callback2, work.State);
253+
work.CallbackAdapter(work.Callback, work.State);
254254
if (work.Completion != null)
255255
{
256256
ThreadPool.QueueUserWorkItem(
@@ -299,8 +299,8 @@ private void DoPostCloseHandle()
299299

300300
private struct Work
301301
{
302-
public Action<object, object> Callback1;
303-
public object Callback2;
302+
public Action<object, object> CallbackAdapter;
303+
public object Callback;
304304
public object State;
305305
public TaskCompletionSource<int> Completion;
306306
}

src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ public uv_buf_t buf_init(IntPtr memory, int len)
395395

396396
public struct sockaddr
397397
{
398+
// this type represents native memory occupied by sockaddr struct
399+
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx
400+
// although the c/c++ header defines it as a 2-byte short followed by a 14-byte array,
401+
// the simplest way to reserve the same size in c# is with four nameless long values
402+
398403
private long _field0;
399404
private long _field1;
400405
private long _field2;
@@ -405,8 +410,16 @@ public struct sockaddr
405410

406411
public struct uv_buf_t
407412
{
408-
public IntPtr _field0;
409-
public IntPtr _field1;
413+
// this type represents a WSABUF struct on Windows
414+
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms741542(v=vs.85).aspx
415+
// and an iovec struct on *nix
416+
// http://man7.org/linux/man-pages/man2/readv.2.html
417+
// because the order of the fields in these structs is different, the field
418+
// names in this type don't have meaningful symbolic names. instead, they are
419+
// assigned in the correct order by the constructor at runtime
420+
421+
private readonly IntPtr _field0;
422+
private readonly IntPtr _field1;
410423

411424
public uv_buf_t(IntPtr memory, int len, bool IsWindows)
412425
{

0 commit comments

Comments
 (0)