File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
projects/client/RabbitMQ.Client/src/client/impl Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public TcpClientAdapter(Socket socket)
24
24
25
25
public virtual async Task ConnectAsync ( string host , int port )
26
26
{
27
+ AssertSocket ( ) ;
27
28
var adds = await Dns . GetHostAddressesAsync ( host ) . ConfigureAwait ( false ) ;
28
29
var ep = adds . FirstOrDefault ( a => a . AddressFamily == sock . AddressFamily ) ;
29
30
if ( ep == default ( IPAddress ) )
@@ -40,11 +41,14 @@ public virtual async Task ConnectAsync(string host, int port)
40
41
41
42
public virtual void Close ( )
42
43
{
43
- sock . Dispose ( ) ;
44
+ if ( sock != null )
45
+ sock . Dispose ( ) ;
46
+ sock = null ;
44
47
}
45
48
46
49
public virtual NetworkStream GetStream ( )
47
50
{
51
+ AssertSocket ( ) ;
48
52
return new NetworkStream ( sock ) ;
49
53
}
50
54
@@ -58,20 +62,34 @@ public virtual Socket Client
58
62
59
63
public virtual bool Connected
60
64
{
61
- get { return sock . Connected ; }
65
+ get
66
+ {
67
+ if ( sock == null ) return false ;
68
+ return sock . Connected ;
69
+ }
62
70
}
63
71
64
72
public virtual int ReceiveTimeout
65
73
{
66
74
get
67
75
{
76
+ AssertSocket ( ) ;
68
77
return sock . ReceiveTimeout ;
69
78
}
70
79
set
71
80
{
81
+ AssertSocket ( ) ;
72
82
sock . ReceiveTimeout = value ;
73
83
}
74
84
}
85
+
86
+ private void AssertSocket ( )
87
+ {
88
+ if ( sock == null )
89
+ {
90
+ throw new InvalidOperationException ( "Cannot perform operation as socket is null" ) ;
91
+ }
92
+ }
75
93
}
76
94
}
77
95
#endif
You can’t perform that action at this time.
0 commit comments