-
Notifications
You must be signed in to change notification settings - Fork 1
/
Engine.cs
4178 lines (3285 loc) · 141 KB
/
Engine.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation. All rights reserved.
// Portions Copyright (c) Secret Labs LLC.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Management;
using Microsoft.Win32;
namespace Microsoft.SPOT.Debugger
{
public delegate void NoiseEventHandler(byte[] buf, int offset, int count);
public delegate void MessageEventHandler(WireProtocol.IncomingMessage msg, string text);
public delegate void CommandEventHandler(WireProtocol.IncomingMessage msg, bool fReply);
[Serializable]
public class ThreadStatus
{
public const uint STATUS_Ready = WireProtocol.Commands.Debugging_Thread_Stack.Reply.TH_S_Ready;
public const uint STATUS_Waiting = WireProtocol.Commands.Debugging_Thread_Stack.Reply.TH_S_Waiting;
public const uint STATUS_Terminated = WireProtocol.Commands.Debugging_Thread_Stack.Reply.TH_S_Terminated;
public const uint FLAGS_Suspended = WireProtocol.Commands.Debugging_Thread_Stack.Reply.TH_F_Suspended;
public uint m_pid;
public uint m_flags;
public uint m_status;
public string[] m_calls;
}
public enum PortFilter
{
Serial,
Usb,
Emulator,
TcpIp,
}
public enum PublicKeyIndex
{
FirmwareKey = 0,
DeploymentKey = 1
};
[Serializable]
public abstract class PortDefinition
{
protected string m_displayName;
protected string m_port;
protected ListDictionary m_properties = new ListDictionary();
protected PortDefinition(string displayName, string port)
{
m_displayName = displayName;
m_port = port;
}
public override bool Equals(object obj)
{
PortDefinition pd = obj as PortDefinition; if (pd == null) return false;
return (pd.UniqueId.Equals(this.UniqueId));
}
public override int GetHashCode()
{
return base.GetHashCode();
}
static public PortDefinition CreateInstanceForSerial(string displayName, string port, uint baudRate)
{
return new PortDefinition_Serial(displayName, port, baudRate);
}
static public PortDefinition CreateInstanceForUsb(string displayName, string port)
{
return new PortDefinition_Usb(displayName, port, new ListDictionary());
}
static public PortDefinition CreateInstanceForEmulator(string displayName, string port, int pid)
{
return new PortDefinition_Emulator(displayName, port, pid);
}
static public PortDefinition CreateInstanceForTcp(IPEndPoint ipEndPoint)
{
return new PortDefinition_Tcp(ipEndPoint);
}
static public PortDefinition CreateInstanceForTcp(string name)
{
PortDefinition portDefinition = null;
//From CorDebug\DebugPort.cs
string hostName = name;
int port = PortDefinition_Tcp.WellKnownPort;
int portIndex = hostName.IndexOf(':');
IPAddress address = null;
if (portIndex > 0)
{
hostName = name.Substring(0, portIndex);
if (portIndex < name.Length - 1)
{
string portString = name.Substring(portIndex + 1);
int portT;
if (int.TryParse(portString, out portT))
{
port = portT;
}
}
}
if (!IPAddress.TryParse(hostName, out address))
{
//Does DNS resolution make sense here?
IPHostEntry iPHostEntry = Dns.GetHostEntry(hostName);
if (iPHostEntry.AddressList.Length > 0)
{
//choose the first one?
address = iPHostEntry.AddressList[0];
}
}
if (address != null)
{
IPEndPoint ipEndPoint = new IPEndPoint(address, port);
portDefinition = new PortDefinition_Tcp(ipEndPoint);
//ping to see if it is alive?
}
return portDefinition;
}
static public ArrayList Enumerate(params PortFilter[] args)
{
ArrayList lst = new ArrayList();
foreach (PortFilter pf in args)
{
PortDefinition[] res;
switch (pf)
{
case PortFilter.Emulator: res = Emulator.EnumeratePipes(); break;
case PortFilter.Serial: res = AsyncSerialStream.EnumeratePorts(); break;
case PortFilter.Usb: res = AsyncUsbStream.EnumeratePorts(); break;
case PortFilter.TcpIp: res = PortDefinition_Tcp.EnumeratePorts(); break;
default: res = null; break;
}
if (res != null)
{
foreach (PortDefinition pd in res)
{
lst.Add(pd);
}
}
}
return lst;
}
public string DisplayName { get { return m_displayName; } }
public ListDictionary Properties { get { return m_properties; } }
public bool TryToOpen()
{
bool fSuccess = false;
try
{
using (Stream stream = CreateStream())
{
fSuccess = true;
stream.Close();
}
}
catch
{
}
return fSuccess;
}
public virtual string Port
{
get
{
return m_port;
}
}
public virtual object UniqueId
{
get
{
return m_port;
}
}
public virtual string PersistName
{
get
{
return this.UniqueId.ToString();
}
}
public virtual Stream Open()
{
Stream stream = CreateStream();
return stream;
}
public abstract Stream CreateStream();
}
public class EndPoint
{
internal class MessageCall
{
public readonly string Name;
public readonly object[] Args;
public MessageCall(string name, object[] args)
{
this.Name = name;
this.Args = args;
}
public static MessageCall CreateFromIMethodMessage(IMethodMessage message)
{
return new MessageCall(message.MethodName, message.Args);
}
public object CreateMessagePayload()
{
return new object[] { this.Name, this.Args };
}
public static MessageCall CreateFromMessagePayload(object payload)
{
object[] data = (object[])payload;
string name = (string)data[0];
object[] args = (object[])data[1];
return new MessageCall(name, args);
}
}
internal Engine m_eng;
internal uint m_type;
internal uint m_id;
internal int m_seq;
private object m_server;
private Type m_serverClassToRemote;
internal EndPoint(Type type, uint id, Engine engine)
{
m_type = BinaryFormatter.LookupHash(type);
m_id = id;
m_seq = 0;
m_eng = engine;
}
public EndPoint(Type type, uint id, object server, Type classToRemote, Engine engine)
: this(type, id, engine)
{
m_server = server;
m_serverClassToRemote = classToRemote;
}
public void Register()
{
m_eng.RpcRegisterEndPoint(this);
}
public void Deregister()
{
m_eng.RpcDeregisterEndPoint(this);
}
internal bool CheckDestination(EndPoint ep)
{
return m_eng.RpcCheck(InitializeAddressForTransmission(ep));
}
internal bool IsRpcServer
{
get { return m_server != null; }
}
private WireProtocol.Commands.Debugging_Messaging_Address InitializeAddressForTransmission(EndPoint epTo)
{
WireProtocol.Commands.Debugging_Messaging_Address addr = new WireProtocol.Commands.Debugging_Messaging_Address();
addr.m_seq = (uint)Interlocked.Increment(ref this.m_seq);
addr.m_from_Type = this.m_type;
addr.m_from_Id = this.m_id;
addr.m_to_Type = epTo.m_type;
addr.m_to_Id = epTo.m_id;
return addr;
}
internal WireProtocol.Commands.Debugging_Messaging_Address InitializeAddressForReception()
{
WireProtocol.Commands.Debugging_Messaging_Address addr = new WireProtocol.Commands.Debugging_Messaging_Address();
addr.m_seq = 0;
addr.m_from_Type = 0;
addr.m_from_Id = 0;
addr.m_to_Type = this.m_type;
addr.m_to_Id = this.m_id;
return addr;
}
internal object SendMessage(EndPoint ep, int timeout, MessageCall call)
{
object data = call.CreateMessagePayload();
byte[] payload = m_eng.CreateBinaryFormatter().Serialize(data);
byte[] res = SendMessageInner(ep, timeout, payload);
if (res == null)
{
throw new RemotingException(string.Format("Remote call '{0}' failed", call.Name));
}
object o = m_eng.CreateBinaryFormatter().Deserialize(res);
Microsoft.SPOT.Messaging.Message.RemotedException ex = o as Microsoft.SPOT.Messaging.Message.RemotedException;
if (ex != null)
{
ex.Raise();
}
return o;
}
internal void DispatchMessage(Message message)
{
object res = null;
try
{
MessageCall call = MessageCall.CreateFromMessagePayload(message.Payload);
object[] args = call.Args;
Type[] argTypes = new Type[(args == null) ? 0 : args.Length];
if (args != null)
{
for (int i = args.Length - 1; i >= 0; i--)
{
object arg = args[i];
argTypes[i] = (arg == null) ? typeof(object) : arg.GetType();
}
}
System.Reflection.MethodInfo mi = this.m_serverClassToRemote.GetMethod(call.Name, argTypes);
if (mi == null) throw new Exception(string.Format("Could not find remote method '{0}'", call.Name));
res = mi.Invoke(this.m_server, call.Args);
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
//If an exception is thrown in the target method, it will be packaged up as the InnerException
ex = ex.InnerException;
}
res = new Microsoft.SPOT.Messaging.Message.RemotedException(ex);
}
try
{
message.Reply(res);
}
catch
{
}
}
internal byte[] SendMessageInner(EndPoint ep, int timeout, byte[] data)
{
return m_eng.RpcSend(InitializeAddressForTransmission(ep), timeout, data);
}
internal void ReplyInner(Message msg, byte[] data)
{
m_eng.RpcReply(msg.m_addr, data);
}
static public object GetObject(Engine eng, Type type, uint id, Type classToRemote)
{
return GetObject(eng, new EndPoint(type, id, eng), classToRemote);
}
static internal object GetObject(Engine eng, EndPoint ep, Type classToRemote)
{
uint id = eng.RpcGetUniqueEndpointId();
EndPoint epLocal = new EndPoint(typeof(EndPointProxy), id, eng);
EndPointProxy prx = new EndPointProxy(eng, epLocal, ep, classToRemote);
return prx.GetTransparentProxy();
}
internal class EndPointProxy : RealProxy, IDisposable
{
private Engine m_eng;
private Type m_type;
private EndPoint m_from;
private EndPoint m_to;
internal EndPointProxy(Engine eng, EndPoint from, EndPoint to, Type type)
: base(type)
{
from.Register();
if (from.CheckDestination(to) == false)
{
from.Deregister();
throw new ArgumentException("Cannot connect to device EndPoint");
}
m_eng = eng;
m_from = from;
m_to = to;
m_type = type;
}
~EndPointProxy()
{
Dispose();
}
public void Dispose()
{
try
{
if (m_from != null)
{
m_from.Deregister();
}
}
catch
{
}
finally
{
m_eng = null;
m_from = null;
m_to = null;
m_type = null;
}
}
public override IMessage Invoke(IMessage message)
{
IMethodMessage myMethodMessage = (IMethodMessage)message;
if (myMethodMessage.MethodSignature is System.Array)
{
foreach (Type t in (System.Array)myMethodMessage.MethodSignature)
{
if (t.IsByRef)
{
throw new NotSupportedException("ByRef parameters are not supported");
}
}
}
MethodInfo mi = myMethodMessage.MethodBase as MethodInfo;
if (mi != null)
{
BinaryFormatter.PopulateFromType(mi.ReturnType);
}
EndPoint.MessageCall call = EndPoint.MessageCall.CreateFromIMethodMessage(myMethodMessage);
object returnValue = m_from.SendMessage(m_to, 60 * 1000, call);
// Build the return message to pass back to the transparent proxy.
return new ReturnMessage(returnValue, null, 0, null, (IMethodCallMessage)message);
}
}
}
internal class Message
{
internal readonly EndPoint m_source;
internal readonly WireProtocol.Commands.Debugging_Messaging_Address m_addr;
internal readonly byte[] m_payload;
internal Message(EndPoint source, WireProtocol.Commands.Debugging_Messaging_Address addr, byte[] payload)
{
m_source = source;
m_addr = addr;
m_payload = payload;
}
public object Payload
{
get
{
return m_source.m_eng.CreateBinaryFormatter().Deserialize(m_payload);
}
}
public void Reply(object data)
{
byte[] payload = m_source.m_eng.CreateBinaryFormatter().Serialize(data);
m_source.ReplyInner(this, payload);
}
}
public class ProcessExitException : Exception
{
}
internal class State
{
public enum Value
{
NotStarted,
Starting,
Started,
Stopping,
Stopped,
Disposing,
Disposed
}
private Value m_value;
private object m_syncObject;
public State(object syncObject)
{
m_value = Value.NotStarted;
m_syncObject = syncObject;
}
public Value GetValue()
{
return m_value;
}
public bool SetValue(Value value)
{
return SetValue(value, false);
}
public bool SetValue(Value value, bool fThrow)
{
lock (m_syncObject)
{
if (m_value < value)
{
m_value = value;
return true;
}
else
{
if (fThrow)
{
throw new ApplicationException(string.Format("Cannot set State to {0}", value));
}
return false;
}
}
}
public bool IsRunning
{
get
{
Value val = m_value;
return val == Value.Starting || val == Value.Started;
}
}
public object SyncObject
{
get { return m_syncObject; }
}
}
public enum ConnectionSource
{
Unknown,
TinyBooter,
TinyCLR,
};
public class Engine : WireProtocol.IControllerHostLocal, IDisposable
{
internal class Request
{
internal Engine m_parent;
internal WireProtocol.OutgoingMessage m_req;
internal WireProtocol.IncomingMessage m_res;
internal int m_retries;
internal TimeSpan m_timeoutRetry;
internal TimeSpan m_timeoutWait;
internal CommandEventHandler m_callback;
internal ManualResetEvent m_event;
internal Timer m_timer;
internal Request(Engine parent, WireProtocol.OutgoingMessage req, int retries, int timeout, CommandEventHandler callback)
{
if (retries < 0)
{
throw new ArgumentException("Value cannot be negative", "retries");
}
if (timeout < 1 || timeout > 60 * 60 * 1000)
{
throw new ArgumentException(String.Format("Value out of bounds: {0}", timeout), "timeout");
}
m_parent = parent;
m_req = req;
m_retries = retries;
m_timeoutRetry = new TimeSpan(timeout * TimeSpan.TicksPerMillisecond);
m_timeoutWait = new TimeSpan((retries == 0 ? 1 : 2 * retries) * timeout * TimeSpan.TicksPerMillisecond);
m_callback = callback;
if (callback == null)
{
m_event = new ManualResetEvent(false);
}
}
internal void SendAsync()
{
m_req.Send();
}
internal bool MatchesReply(WireProtocol.IncomingMessage res)
{
WireProtocol.Packet headerReq = m_req.Header;
WireProtocol.Packet headerRes = res.Header;
if (headerReq.m_cmd == headerRes.m_cmd &&
headerReq.m_seq == headerRes.m_seqReply)
{
return true;
}
return false;
}
internal WireProtocol.IncomingMessage Wait()
{
WireProtocol.IncomingMessage res = m_res;
if (m_event != null)
{
DateTime waitStartTime = DateTime.UtcNow;
bool requestTimedOut = false;
/// Wait for m_timeoutRetry milliseconds, if we did not get a signal by then
/// attempt sending the request again, and then wait more.
while ((requestTimedOut = !m_event.WaitOne(m_timeoutRetry, false)))
{
TimeSpan diff = DateTime.UtcNow - waitStartTime;
if (diff >= m_timeoutWait)
break;
if (m_retries > 0)
{
if (m_req.Send())
{
m_retries--;
}
}
/// m_retries and m_timeoutWait are competing entities. Here I am settling down for m_retries
/// in the event m_retries * m_timeoutRetry < m_timeoutWait.
else
{
break;
}
}
if (requestTimedOut)
{
m_parent.CancelRequest(this);
}
res = m_res;
if (res == null && this.m_parent.m_fThrowOnCommunicationFailure)
{
//do we want a separate exception for aborted requests?
throw new System.IO.IOException("Request failed");
}
}
return res;
}
internal void Signal(WireProtocol.IncomingMessage res)
{
lock (this)
{
if (m_timer != null)
{
m_timer.Dispose();
m_timer = null;
}
m_res = res;
}
Signal();
}
internal void Signal()
{
CommandEventHandler callback;
WireProtocol.IncomingMessage res;
lock (this)
{
callback = m_callback;
res = m_res;
if (m_timer != null)
{
m_timer.Dispose();
m_timer = null;
}
if (m_event != null)
{
m_event.Set();
}
}
if (callback != null)
{
callback(res, true);
}
}
internal void Retry(object state)
{
bool fCancel = false;
TimeSpan ts = TimeSpan.MinValue;
lock (this)
{
if (m_res != null || m_timer == null) return;
try
{
while (true)
{
DateTime now = DateTime.UtcNow;
ts = now - m_parent.LastActivity;
if (ts < m_timeoutRetry)
{
//
// There was some activity going on, compensate for that.
//
ts = m_timeoutRetry - ts;
break;
}
if (m_retries > 0)
{
if (m_req.Send())
{
m_retries--;
ts = m_timeoutRetry;
}
else
{
//
// Too many pending requests, retry in a bit.
//
ts = new TimeSpan(10 * TimeSpan.TicksPerMillisecond);
}
break;
}
fCancel = true;
break;
}
}
catch
{
fCancel = true;
}
if (!fCancel)
{
m_timer.Change((int)ts.TotalMilliseconds, Timeout.Infinite);
}
}
//
// Call can go out-of-proc, you need to release locks before the call to avoid deadlocks.
//
if (fCancel)
{
m_parent.CancelRequest(this);
}
}
}
public enum RebootOption
{
EnterBootloader,
RebootClrOnly,
NormalReboot,
NoReconnect,
RebootClrWaitForDebugger,
};
private class RebootTime
{
public const int c_RECONNECT_RETRIES_DEFAULT = 5;
public const int c_RECONNECT_HARD_TIMEOUT_DEFAULT_MS = 1000; // one second
public const int c_RECONNECT_SOFT_TIMEOUT_DEFAULT_MS = 500; // 500 milliseconds
public const int c_MIN_RECONNECT_RETRIES = 1;
public const int c_MAX_RECONNECT_RETRIES = 1000;
public const int c_MIN_TIMEOUT_MS = 1 * 50; // fifty milliseconds
public const int c_MAX_TIMEOUT_MS = 60 * 1000; // sixty seconds
int m_retriesCount;
int m_waitHardMs;
int m_waitSoftMs;
public RebootTime()
{
m_waitSoftMs = c_RECONNECT_SOFT_TIMEOUT_DEFAULT_MS;
m_waitHardMs = c_RECONNECT_HARD_TIMEOUT_DEFAULT_MS;
bool fOverride = false;
string timingKey = @"\NonVersionSpecific\Timing\AnyDevice";
RegistryAccess.GetBoolValue(timingKey, "override", out fOverride, false);
if (RegistryAccess.GetIntValue(timingKey, "retries", out m_retriesCount, c_RECONNECT_RETRIES_DEFAULT))
{
if (!fOverride)
{
if (m_retriesCount < c_MIN_RECONNECT_RETRIES) m_retriesCount = c_MIN_RECONNECT_RETRIES;
if (m_retriesCount > c_MAX_RECONNECT_RETRIES) m_retriesCount = c_MAX_RECONNECT_RETRIES;
}
}
if (RegistryAccess.GetIntValue(timingKey, "timeout", out m_waitHardMs, c_RECONNECT_HARD_TIMEOUT_DEFAULT_MS))
{
if (!fOverride)
{
if (m_waitHardMs < c_MIN_TIMEOUT_MS) m_waitHardMs = c_MIN_TIMEOUT_MS;
if (m_waitHardMs > c_MAX_TIMEOUT_MS) m_waitHardMs = c_MAX_TIMEOUT_MS;
}
m_waitSoftMs = m_waitHardMs;
}
}
public int Retries
{
get
{
return m_retriesCount;
}
}
public int WaitMs(bool fSoftReboot)
{
return (fSoftReboot ? m_waitSoftMs : m_waitHardMs);
}
}
private const int RETRIES_DEFAULT = 5;
private const int TIMEOUT_DEFAULT = 1000;
PortDefinition m_portDefinition;
WireProtocol.IController m_ctrl;
bool m_silent;
bool m_stopDebuggerOnConnect;
bool m_connected;
ConnectionSource m_connectionSource;
bool m_targetIsBigEndian;
DateTime m_lastNoise = DateTime.Now;
event NoiseEventHandler m_eventNoise;
event MessageEventHandler m_eventMessage;
event CommandEventHandler m_eventCommand;
event EventHandler m_eventProcessExit;
/// <summary>
/// Notification thread is essentially the Tx thread. Other threads pump outgoing data into it, which after potential
/// processing is sent out to destination synchronously.
/// </summary>
Thread m_notificationThread;
AutoResetEvent m_notifyEvent;
ArrayList m_notifyQueue;
WireProtocol.FifoBuffer m_notifyNoise;
AutoResetEvent m_rpcEvent;
ArrayList m_rpcQueue;
ArrayList m_rpcEndPoints;
ManualResetEvent m_evtShutdown;
ManualResetEvent m_evtPing;
ArrayList m_requests;
TypeSysLookup m_typeSysLookup;
State m_state;
bool m_fProcessExited;
CLRCapabilities m_capabilities;
bool m_fThrowOnCommunicationFailure;
RebootTime m_RebootTime;
private class TypeSysLookup
{
public enum Type : uint
{
Type,
Method,
Field
}
private Hashtable m_lookup;
private void EnsureHashtable()
{
lock (this)
{
if (m_lookup == null)
{
m_lookup = Hashtable.Synchronized(new Hashtable());
}
}
}
private ulong KeyFromTypeToken(TypeSysLookup.Type type, uint token)
{
return ((ulong)type) << 32 | (ulong)token;
}
public object Lookup(TypeSysLookup.Type type, uint token)