/
SocketException.cs
115 lines (96 loc) · 3.94 KB
/
SocketException.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
//------------------------------------------------------------------------------
// <copyright file="SocketException.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Net.Sockets {
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
/// <devdoc>
/// <para>
/// Provides socket exceptions to the application.
/// </para>
/// </devdoc>
[Serializable]
public class SocketException : Win32Exception {
[NonSerialized]
private EndPoint m_EndPoint;
#if MONO
[System.Runtime.CompilerServices.MethodImplAttribute (System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
static extern int WSAGetLastError_internal ();
public SocketException () : base (WSAGetLastError_internal ())
{
}
internal SocketException (int error, string message) : base (error, message)
{
}
#else
/// <devdoc>
/// <para>
/// Creates a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the default error code.
/// </para>
/// </devdoc>
public SocketException() : base(Marshal.GetLastWin32Error()) {
GlobalLog.Print("SocketException::.ctor() " + NativeErrorCode.ToString() + ":" + Message);
}
#endif
internal SocketException(EndPoint endPoint) : base(Marshal.GetLastWin32Error()) {
m_EndPoint = endPoint;
}
/// <devdoc>
/// <para>
/// Creates a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the specified error code.
/// </para>
/// </devdoc>
public SocketException(int errorCode) : base(errorCode) {
GlobalLog.Print("SocketException::.ctor(int) " + NativeErrorCode.ToString() + ":" + Message);
}
internal SocketException(int errorCode, EndPoint endPoint) : base(errorCode) {
m_EndPoint = endPoint;
}
/// <devdoc>
/// <para>
/// Creates a new instance of the <see cref='System.Net.Sockets.SocketException'/> class with the specified error code as SocketError.
/// </para>
/// </devdoc>
internal SocketException(SocketError socketError) : base((int)socketError) {
}
protected SocketException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext) {
GlobalLog.Print("SocketException::.ctor(serialized) " + NativeErrorCode.ToString() + ":" + Message);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override int ErrorCode {
//
// the base class returns the HResult with this property
// we need the Win32 Error Code, hence the override.
//
get {
return NativeErrorCode;
}
}
public override string Message {
get {
// If not null add EndPoint.ToString() to end of base Message
if (m_EndPoint == null) {
return base.Message;
} else {
return base.Message + " " + m_EndPoint.ToString();
}
}
}
public SocketError SocketErrorCode {
//
// the base class returns the HResult with this property
// we need the Win32 Error Code, hence the override.
//
get {
return (SocketError)NativeErrorCode;
}
}
}; // class SocketException
} // namespace System.Net