Skip to content

Commit 65a3848

Browse files
merge bug26131 into bug26133
2 parents 40f9132 + c823046 commit 65a3848

File tree

7 files changed

+61
-212
lines changed

7 files changed

+61
-212
lines changed

projects/client/RabbitMQ.Client/src/client/api/AmqpTcpEndpoint.cs

Lines changed: 28 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545

4646
namespace RabbitMQ.Client
4747
{
48-
///<summary>Represents a TCP-addressable AMQP peer, including the
49-
///protocol variant to use, and a host name and port
48+
///<summary>Represents a TCP-addressable AMQP peer: a host name and port
5049
///number.</summary>
5150
///<para>
5251
/// Some of the constructors take, as a convenience, a System.Uri
@@ -62,12 +61,10 @@ public class AmqpTcpEndpoint
6261
public const int DefaultAmqpSslPort = 5671;
6362
public const int UseDefaultPort = -1;
6463

65-
private IProtocol m_protocol;
66-
///<summary>Retrieve or set the IProtocol of this AmqpTcpEndpoint.</summary>
64+
///<summary>Retrieve IProtocol of this AmqpTcpEndpoint.</summary>
6765
public IProtocol Protocol
6866
{
69-
get { return m_protocol; }
70-
set { m_protocol = value; }
67+
get { return Protocols.DefaultProtocol; }
7168
}
7269

7370
private string m_hostName;
@@ -81,15 +78,15 @@ public string HostName
8178
private int m_port;
8279
///<summary>Retrieve or set the port number of this
8380
///AmqpTcpEndpoint. A port number of -1 causes the default
84-
///port number for the IProtocol to be used.</summary>
81+
///port number.</summary>
8582
public int Port
8683
{
8784
get {
8885
if (m_port != UseDefaultPort)
8986
return m_port;
9087
if (m_ssl.Enabled)
9188
return DefaultAmqpSslPort;
92-
return m_protocol.DefaultPort;
89+
return Protocol.DefaultPort;
9390
}
9491
set { m_port = value; }
9592
}
@@ -105,100 +102,56 @@ public SslOption Ssl
105102
}
106103

107104
///<summary>Construct an AmqpTcpEndpoint with the given
108-
///IProtocol, hostname, port number and ssl option. If the port
109-
///number is -1, the default port number for the IProtocol
110-
///will be used.</summary>
111-
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne, SslOption ssl)
105+
///hostname, port number and ssl option. If the port
106+
///number is -1, the default port number will be used.</summary>
107+
public AmqpTcpEndpoint(string hostName, int portOrMinusOne, SslOption ssl)
112108
{
113-
m_protocol = protocol;
114109
m_hostName = hostName;
115110
m_port = portOrMinusOne;
116111
m_ssl = ssl;
117112
}
118113

119114
///<summary>Construct an AmqpTcpEndpoint with the given
120-
///IProtocol, hostname, and port number. If the port number is
121-
///-1, the default port number for the IProtocol will be
122-
///used.</summary>
123-
public AmqpTcpEndpoint(IProtocol protocol, string hostName, int portOrMinusOne) :
124-
this(protocol, hostName, portOrMinusOne, new SslOption())
125-
{
126-
}
127-
128-
///<summary>Construct an AmqpTcpEndpoint with the given
129-
///IProtocol and hostname, using the default port for the
130-
///IProtocol.</summary>
131-
public AmqpTcpEndpoint(IProtocol protocol, string hostName) :
132-
this(protocol, hostName, -1)
133-
{
134-
}
135-
136-
///<summary>Construct an AmqpTcpEndpoint with the given
137-
///IProtocol, "localhost" as the hostname, and using the
138-
///default port for the IProtocol.</summary>
139-
public AmqpTcpEndpoint(IProtocol protocol) :
140-
this(protocol, "localhost", -1)
141-
{
142-
}
143-
144-
///<summary>Construct an AmqpTcpEndpoint with the given
145-
///hostname and port number, using Protocols.DefaultProtocol. If the port number is
146-
///-1, the default port number for the IProtocol will be
115+
///hostname, and port number. If the port number is
116+
///-1, the default port number will be
147117
///used.</summary>
148118
public AmqpTcpEndpoint(string hostName, int portOrMinusOne) :
149-
this(Protocols.DefaultProtocol, hostName, portOrMinusOne)
119+
this(hostName, portOrMinusOne, new SslOption())
150120
{
151121
}
152122

153123
///<summary>Construct an AmqpTcpEndpoint with the given
154-
///hostname, using the IProtocol from
155-
///Protocols.DefaultProtocol, and the default port number of
156-
///that IProtocol.</summary>
124+
///hostname, using the default port.</summary>
157125
public AmqpTcpEndpoint(string hostName) :
158-
this(Protocols.DefaultProtocol, hostName)
126+
this(hostName, -1)
159127
{
160128
}
161129

162-
///<summary>Construct an AmqpTcpEndpoint with a hostname of
163-
///"localhost", using the IProtocol from
164-
///Protocols.DefaultProtocol, and the default port number of
165-
///that IProtocol.</summary>
130+
///<summary>Construct an AmqpTcpEndpoint with "localhost" as
131+
///the hostname, and using the default port.</summary>
166132
public AmqpTcpEndpoint() :
167-
this(Protocols.DefaultProtocol)
133+
this("localhost", -1)
168134
{
169135
}
170136

171137
///<summary>Construct an AmqpTcpEndpoint with the given
172-
///IProtocol, Uri and ssl options.</summary>
138+
///Uri and ssl options.</summary>
173139
///<remarks>
174140
/// Please see the class overview documentation for
175141
/// information about the Uri format in use.
176142
///</remarks>
177-
public AmqpTcpEndpoint(IProtocol protocol, Uri uri, SslOption ssl) :
178-
this(protocol, uri.Host, uri.Port, ssl)
143+
public AmqpTcpEndpoint(Uri uri, SslOption ssl) :
144+
this(uri.Host, uri.Port, ssl)
179145
{
180146
}
181147

182-
///<summary>Construct an AmqpTcpEndpoint with the given
183-
///IProtocol and Uri.</summary>
184-
///<remarks>
185-
/// Please see the class overview documentation for
186-
/// information about the Uri format in use.
187-
///</remarks>
188-
public AmqpTcpEndpoint(IProtocol protocol, Uri uri) :
189-
this(protocol, uri.Host, uri.Port)
190-
{
191-
}
192-
193-
///<summary>Construct an AmqpTcpEndpoint with the given
194-
///Uri, using the IProtocol from
195-
///Protocols.DefaultProtocol.</summary>
148+
///<summary>Construct an AmqpTcpEndpoint with the given Uri.</summary>
196149
///<remarks>
197150
/// Please see the class overview documentation for
198151
/// information about the Uri format in use.
199152
///</remarks>
200153
public AmqpTcpEndpoint(Uri uri) :
201-
this(Protocols.DefaultProtocol, uri)
154+
this(uri.Host, uri.Port)
202155
{
203156
}
204157

@@ -209,7 +162,7 @@ public AmqpTcpEndpoint(Uri uri) :
209162
///</remarks>
210163
public override string ToString()
211164
{
212-
return "amqp-" + Protocol + "://" + HostName + ":" + Port;
165+
return "amqp://" + HostName + ":" + Port;
213166
}
214167

215168
///<summary>Compares this instance by value (protocol,
@@ -218,7 +171,6 @@ public override bool Equals(object obj)
218171
{
219172
AmqpTcpEndpoint other = obj as AmqpTcpEndpoint;
220173
if (other == null) return false;
221-
if (other.Protocol != Protocol) return false;
222174
if (other.HostName != HostName) return false;
223175
if (other.Port != Port) return false;
224176
return true;
@@ -230,7 +182,6 @@ public override bool Equals(object obj)
230182
public override int GetHashCode()
231183
{
232184
return
233-
Protocol.GetHashCode() ^
234185
HostName.GetHashCode() ^
235186
Port;
236187
}
@@ -245,7 +196,7 @@ public override int GetHashCode()
245196
/// variant specified).
246197
/// Hostnames provided as IPv6 must appear in square brackets ([]).
247198
///</remarks>
248-
public static AmqpTcpEndpoint Parse(IProtocol protocol, string address) {
199+
public static AmqpTcpEndpoint Parse(string address) {
249200
Match match = Regex.Match(address, @"^\s*\[([%:0-9A-Fa-f]+)\](:(.*))?\s*$");
250201
if (match.Success)
251202
{
@@ -256,18 +207,16 @@ public static AmqpTcpEndpoint Parse(IProtocol protocol, string address) {
256207
string portStr = groups[3].Value;
257208
portNum = (portStr.Length == 0) ? -1 : int.Parse(portStr);
258209
}
259-
return new AmqpTcpEndpoint(protocol,
260-
match.Groups[1].Value,
210+
return new AmqpTcpEndpoint(match.Groups[1].Value,
261211
portNum);
262212
}
263213
int index = address.LastIndexOf(':');
264214
if (index == -1) {
265-
return new AmqpTcpEndpoint(protocol, address, -1);
215+
return new AmqpTcpEndpoint(address, -1);
266216
} else {
267217
string portStr = address.Substring(index + 1).Trim();
268218
int portNum = (portStr.Length == 0) ? -1 : int.Parse(portStr);
269-
return new AmqpTcpEndpoint(protocol,
270-
address.Substring(0, index),
219+
return new AmqpTcpEndpoint(address.Substring(0, index),
271220
portNum);
272221
}
273222
}
@@ -280,13 +229,13 @@ public static AmqpTcpEndpoint Parse(IProtocol protocol, string address) {
280229
/// optional, and returns a corresponding array of
281230
/// AmqpTcpEndpoints.
282231
///</remarks>
283-
public static AmqpTcpEndpoint[] ParseMultiple(IProtocol protocol, string addresses) {
232+
public static AmqpTcpEndpoint[] ParseMultiple(string addresses) {
284233
string[] partsArr = addresses.Split(new char[] { ',' });
285234
List<AmqpTcpEndpoint> results = new List<AmqpTcpEndpoint>();
286235
foreach (string partRaw in partsArr) {
287236
string part = partRaw.Trim();
288237
if (part.Length > 0) {
289-
results.Add(Parse(protocol, part));
238+
results.Add(Parse(part));
290239
}
291240
}
292241
return results.ToArray();

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ public AmqpTcpEndpoint Endpoint
172172
{
173173
get
174174
{
175-
return new AmqpTcpEndpoint(Protocol, HostName, Port, Ssl);
175+
return new AmqpTcpEndpoint(HostName, Port, Ssl);
176176
}
177177
set
178178
{
179-
Protocol = value.Protocol;
180179
Port = value.Port;
181180
HostName = value.HostName;
182181
Ssl = value.Ssl;
@@ -214,7 +213,7 @@ public virtual IConnection CreateConnection()
214213
IConnection conn = null;
215214
try
216215
{
217-
IProtocol p = Endpoint.Protocol;
216+
IProtocol p = Protocols.DefaultProtocol;
218217
IFrameHandler fh = p.CreateFrameHandler(Endpoint,
219218
SocketFactory,
220219
RequestedConnectionTimeout);

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ public virtual void Open(bool insist)
11601160
string knownHosts = m_model0.ConnectionOpen(m_factory.VirtualHost,
11611161
"", // FIXME: make configurable?
11621162
insist);
1163-
KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts);
1163+
KnownHosts = AmqpTcpEndpoint.ParseMultiple(knownHosts);
11641164
}
11651165

11661166
public override string ToString()

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ public string ConnectionOpen(string virtualHost,
14911491
// negotiation finishes
14921492
}
14931493
k.GetReply();
1494-
14951494
return k.m_knownHosts;
14961495
}
14971496

projects/client/RabbitMQ.Client/src/client/impl/RedirectException.cs

Lines changed: 0 additions & 104 deletions
This file was deleted.

projects/client/RabbitMQ.Client/src/client/impl/SocketFrameHandler.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,19 @@ public int Timeout
144144
{
145145
set
146146
{
147-
if (m_socket.Connected)
147+
try
148+
{
149+
if (m_socket.Connected)
150+
{
151+
m_socket.ReceiveTimeout = value;
152+
}
153+
}
154+
#pragma warning disable 0168
155+
catch (SocketException _)
148156
{
149-
m_socket.ReceiveTimeout = value;
157+
// means that the socket is already closed
150158
}
159+
#pragma warning restore 0168
151160
}
152161
}
153162

0 commit comments

Comments
 (0)