Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Dispose() [2/2]

virtual void System.Net.Sockets.Socket.Dispose ( bool disposing)
inlineprotectedvirtual

Definition at line 3294 of file Socket.cs.

3295 {
3296 if (System.Net.NetEventSource.Log.IsEnabled())
3297 {
3298 try
3299 {
3300 System.Net.NetEventSource.Info(this, $"disposing:{disposing} Disposed:{Disposed}", "Dispose");
3301 }
3302 catch (Exception exception) when (!ExceptionCheck.IsFatal(exception))
3303 {
3304 }
3305 }
3306 if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 1)
3307 {
3308 return;
3309 }
3311 SafeSocketHandle handle = _handle;
3312 if (handle != null && handle.OwnsHandle)
3313 {
3314 if (!disposing)
3315 {
3316 if (System.Net.NetEventSource.Log.IsEnabled())
3317 {
3318 System.Net.NetEventSource.Info(this, "Calling _handle.Dispose()", "Dispose");
3319 }
3320 handle.Dispose();
3321 }
3322 else
3323 {
3324 try
3325 {
3327 if (closeTimeout == 0)
3328 {
3329 if (System.Net.NetEventSource.Log.IsEnabled())
3330 {
3331 System.Net.NetEventSource.Info(this, "Calling _handle.CloseAsIs()", "Dispose");
3332 }
3333 handle.CloseAsIs(abortive: true);
3334 }
3335 else
3336 {
3338 {
3339 bool willBlock;
3340 SocketError socketError = SocketPal.SetBlocking(handle, shouldBlock: false, out willBlock);
3341 if (System.Net.NetEventSource.Log.IsEnabled())
3342 {
3343 System.Net.NetEventSource.Info(this, $"handle:{handle} ioctlsocket(FIONBIO):{socketError}", "Dispose");
3344 }
3345 }
3346 if (closeTimeout < 0)
3347 {
3348 if (System.Net.NetEventSource.Log.IsEnabled())
3349 {
3350 System.Net.NetEventSource.Info(this, "Calling _handle.CloseAsIs()", "Dispose");
3351 }
3352 handle.CloseAsIs(abortive: false);
3353 }
3354 else
3355 {
3356 SocketError socketError = SocketPal.Shutdown(handle, _isConnected, _isDisconnected, SocketShutdown.Send);
3357 if (System.Net.NetEventSource.Log.IsEnabled())
3358 {
3359 System.Net.NetEventSource.Info(this, $"handle:{handle} shutdown():{socketError}", "Dispose");
3360 }
3361 socketError = SocketPal.SetSockOpt(handle, SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, closeTimeout);
3362 if (System.Net.NetEventSource.Log.IsEnabled())
3363 {
3364 System.Net.NetEventSource.Info(this, $"handle:{handle} setsockopt():{socketError}", "Dispose");
3365 }
3366 if (socketError != 0)
3367 {
3368 handle.CloseAsIs(abortive: true);
3369 }
3370 else
3371 {
3372 socketError = SocketPal.Receive(handle, Array.Empty<byte>(), 0, 0, SocketFlags.None, out var _);
3373 if (System.Net.NetEventSource.Log.IsEnabled())
3374 {
3375 System.Net.NetEventSource.Info(this, $"handle:{handle} recv():{socketError}", "Dispose");
3376 }
3377 if (socketError != 0)
3378 {
3379 handle.CloseAsIs(abortive: true);
3380 }
3381 else
3382 {
3383 int available = 0;
3384 socketError = SocketPal.GetAvailable(handle, out available);
3385 if (System.Net.NetEventSource.Log.IsEnabled())
3386 {
3387 System.Net.NetEventSource.Info(this, $"handle:{handle} ioctlsocket(FIONREAD):{socketError}", "Dispose");
3388 }
3389 if (socketError != 0 || available != 0)
3390 {
3391 handle.CloseAsIs(abortive: true);
3392 }
3393 else
3394 {
3395 handle.CloseAsIs(abortive: false);
3396 }
3397 }
3398 }
3399 }
3400 }
3401 }
3402 catch (ObjectDisposedException)
3403 {
3404 }
3405 }
3406 if (_rightEndPoint is UnixDomainSocketEndPoint { BoundFileName: not null } unixDomainSocketEndPoint)
3407 {
3408 try
3409 {
3410 File.Delete(unixDomainSocketEndPoint.BoundFileName);
3411 }
3412 catch
3413 {
3414 }
3415 }
3416 }
3418 }
static void Delete(string path)
Definition File.cs:88
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
void DisposeCachedTaskSocketAsyncEventArgs()
Definition Socket.cs:4355
SafeSocketHandle _handle
Definition Socket.cs:533
static int CompareExchange(ref int location1, int value, int comparand)

References System.Net.Sockets.Socket._closeTimeout, System.Net.Sockets.Socket._disposed, System.Net.Sockets.Socket._handle, System.Net.Sockets.Socket._isConnected, System.Net.Sockets.Socket._isDisconnected, System.Net.Sockets.Socket._rightEndPoint, System.Net.Sockets.Socket._willBlock, System.Net.Sockets.Socket._willBlockInternal, System.Threading.Interlocked.CompareExchange(), System.IO.File.Delete(), System.Net.Sockets.Socket.DisposeCachedTaskSocketAsyncEventArgs(), System.exception, System.Net.Sockets.SocketPal.GetAvailable(), System.handle, System.Net.NetEventSource.Info(), System.Net.ExceptionCheck.IsFatal(), System.Net.NetEventSource.Log, System.Net.Sockets.SocketPal.Receive(), System.Net.Sockets.SocketPal.SetBlocking(), System.Net.Sockets.SocketPal.SetSockOpt(), System.Net.Sockets.Socket.SetToDisconnected(), and System.Net.Sockets.SocketPal.Shutdown().

Referenced by System.Net.Sockets.SocketAsyncEventArgs.CancelConnectAsync(), System.Net.Sockets.TcpClient.Connect(), System.Net.Sockets.UdpClient.Dispose(), System.Net.Sockets.SocketAsyncEventArgs.DnsConnectAsync(), and System.Net.Sockets.TcpListener.Stop().