Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SocketsTelemetry.cs
Go to the documentation of this file.
4
5namespace System.Net.Sockets;
6
7[EventSource(Name = "System.Net.Sockets")]
8internal sealed class SocketsTelemetry : EventSource
9{
10 public static readonly SocketsTelemetry Log = new SocketsTelemetry();
11
13
15
17
19
21
23
25
27
28 private long _bytesReceived;
29
30 private long _bytesSent;
31
32 private long _datagramsReceived;
33
34 private long _datagramsSent;
35
36 [Event(1, Level = EventLevel.Informational)]
37 private void ConnectStart(string address)
38 {
39 WriteEvent(1, address);
40 }
41
42 [Event(2, Level = EventLevel.Informational)]
43 private void ConnectStop()
44 {
45 if (IsEnabled(EventLevel.Informational, EventKeywords.All))
46 {
47 WriteEvent(2);
48 }
49 }
50
51 [Event(3, Level = EventLevel.Error)]
52 private void ConnectFailed(SocketError error, string exceptionMessage)
53 {
54 if (IsEnabled(EventLevel.Error, EventKeywords.All))
55 {
56 WriteEvent(3, (int)error, exceptionMessage);
57 }
58 }
59
60 [Event(4, Level = EventLevel.Informational)]
61 private void AcceptStart(string address)
62 {
63 WriteEvent(4, address);
64 }
65
66 [Event(5, Level = EventLevel.Informational)]
67 private void AcceptStop()
68 {
69 if (IsEnabled(EventLevel.Informational, EventKeywords.All))
70 {
71 WriteEvent(5);
72 }
73 }
74
75 [Event(6, Level = EventLevel.Error)]
76 private void AcceptFailed(SocketError error, string exceptionMessage)
77 {
78 if (IsEnabled(EventLevel.Error, EventKeywords.All))
79 {
80 WriteEvent(6, (int)error, exceptionMessage);
81 }
82 }
83
84 [NonEvent]
86 {
87 if (IsEnabled(EventLevel.Informational, EventKeywords.All))
88 {
89 ConnectStart(address.ToString());
90 }
91 }
92
93 [NonEvent]
94 public void AfterConnect(SocketError error, string exceptionMessage = null)
95 {
96 if (error == SocketError.Success)
97 {
99 }
100 else
101 {
102 ConnectFailed(error, exceptionMessage);
103 }
104 ConnectStop();
105 }
106
107 [NonEvent]
109 {
110 if (IsEnabled(EventLevel.Informational, EventKeywords.All))
111 {
112 AcceptStart(address.ToString());
113 }
114 }
115
116 [NonEvent]
117 public void AcceptStart(EndPoint address)
118 {
119 if (IsEnabled(EventLevel.Informational, EventKeywords.All))
120 {
121 AcceptStart(address.Serialize().ToString());
122 }
123 }
124
125 [NonEvent]
126 public void AfterAccept(SocketError error, string exceptionMessage = null)
127 {
128 if (error == SocketError.Success)
129 {
131 }
132 else
133 {
134 AcceptFailed(error, exceptionMessage);
135 }
136 AcceptStop();
137 }
138
139 [NonEvent]
140 public void BytesReceived(int count)
141 {
143 }
144
145 [NonEvent]
146 public void BytesSent(int count)
147 {
149 }
150
151 [NonEvent]
152 public void DatagramReceived()
153 {
155 }
156
157 [NonEvent]
158 public void DatagramSent()
159 {
161 }
162
163 protected override void OnEventCommand(EventCommandEventArgs command)
164 {
165 if (command.Command != EventCommand.Enable)
166 {
167 return;
168 }
170 {
171 _outgoingConnectionsEstablishedCounter = new PollingCounter("outgoing-connections-established", this, () => Interlocked.Read(ref _outgoingConnectionsEstablished))
172 {
173 DisplayName = "Outgoing Connections Established"
174 };
175 }
177 {
178 _incomingConnectionsEstablishedCounter = new PollingCounter("incoming-connections-established", this, () => Interlocked.Read(ref _incomingConnectionsEstablished))
179 {
180 DisplayName = "Incoming Connections Established"
181 };
182 }
183 if (_bytesReceivedCounter == null)
184 {
185 _bytesReceivedCounter = new PollingCounter("bytes-received", this, () => Interlocked.Read(ref _bytesReceived))
186 {
187 DisplayName = "Bytes Received"
188 };
189 }
190 if (_bytesSentCounter == null)
191 {
192 _bytesSentCounter = new PollingCounter("bytes-sent", this, () => Interlocked.Read(ref _bytesSent))
193 {
194 DisplayName = "Bytes Sent"
195 };
196 }
197 if (_datagramsReceivedCounter == null)
198 {
199 _datagramsReceivedCounter = new PollingCounter("datagrams-received", this, () => Interlocked.Read(ref _datagramsReceived))
200 {
201 DisplayName = "Datagrams Received"
202 };
203 }
204 if (_datagramsSentCounter == null)
205 {
206 _datagramsSentCounter = new PollingCounter("datagrams-sent", this, () => Interlocked.Read(ref _datagramsSent))
207 {
208 DisplayName = "Datagrams Sent"
209 };
210 }
211 }
212}
unsafe void WriteEvent(int eventId)
virtual SocketAddress Serialize()
Definition EndPoint.cs:15
override string ToString()
void AfterConnect(SocketError error, string exceptionMessage=null)
PollingCounter _outgoingConnectionsEstablishedCounter
void AcceptFailed(SocketError error, string exceptionMessage)
void ConnectStart(System.Net.Internals.SocketAddress address)
PollingCounter _incomingConnectionsEstablishedCounter
void ConnectFailed(SocketError error, string exceptionMessage)
void AfterAccept(SocketError error, string exceptionMessage=null)
static readonly SocketsTelemetry Log
void AcceptStart(System.Net.Internals.SocketAddress address)
override void OnEventCommand(EventCommandEventArgs command)
static long Read(ref long location)
static int Add(ref int location1, int value)
static int Increment(ref int location)