Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDick Porter <dick@acm.org>2007-01-24 00:08:28 +0300
committerDick Porter <dick@acm.org>2007-01-24 00:08:28 +0300
commitf75e3a4aac5f605084b2f24fe030d46f15dd7f11 (patch)
tree61fdd228121cf84b7ef83a501eb6d0d5e79e4f7f
parenta5fe9ebd585656c034470e73f610fda1011d07ba (diff)
2007-01-23 Dick Porter <dick@ximian.com>
* TcpClient.cs: 2.0 profile updates, based on a patch by Sridhar Kulkarni (sridharkulkarni@gmail.com) 2007-01-23 Dick Porter <dick@ximian.com> * TcpClientTest.cs: Test 2.0 Connect(IPAddress[], port) overload svn path=/trunk/mcs/; revision=71557
-rw-r--r--mcs/class/System/System.Net.Sockets/ChangeLog5
-rw-r--r--mcs/class/System/System.Net.Sockets/TcpClient.cs98
-rw-r--r--mcs/class/System/Test/System.Net.Sockets/ChangeLog4
-rw-r--r--mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs50
4 files changed, 139 insertions, 18 deletions
diff --git a/mcs/class/System/System.Net.Sockets/ChangeLog b/mcs/class/System/System.Net.Sockets/ChangeLog
index 81f14673137..128f68c15a0 100644
--- a/mcs/class/System/System.Net.Sockets/ChangeLog
+++ b/mcs/class/System/System.Net.Sockets/ChangeLog
@@ -1,3 +1,8 @@
+2007-01-23 Dick Porter <dick@ximian.com>
+
+ * TcpClient.cs: 2.0 profile updates, based on a patch by Sridhar
+ Kulkarni (sridharkulkarni@gmail.com)
+
2007-01-22 Miguel de Icaza <miguel@novell.com>
* Socket.cs: Move the throw new NotImplementedException ()
diff --git a/mcs/class/System/System.Net.Sockets/TcpClient.cs b/mcs/class/System/System.Net.Sockets/TcpClient.cs
index 78177dc2521..c899c9d9c82 100644
--- a/mcs/class/System/System.Net.Sockets/TcpClient.cs
+++ b/mcs/class/System/System.Net.Sockets/TcpClient.cs
@@ -3,6 +3,7 @@
// Author:
// Phillip Pearson (pp@myelin.co.nz)
// Gonzalo Paniagua Javier (gonzalo@novell.com)
+// Sridhar Kulkarni (sridharkulkarni@gmail.com)
//
// Copyright (C) 2001, Phillip Pearson
// http://www.myelin.co.nz
@@ -126,12 +127,10 @@ namespace System.Net.Sockets
public bool ExclusiveAddressUse {
get {
- return !((bool) client.GetSocketOption (SocketOptionLevel.Socket,
- SocketOptionName.ReuseAddress));
+ return(client.ExclusiveAddressUse);
}
set {
- client.SetSocketOption (SocketOptionLevel.Socket,
- SocketOptionName.ReuseAddress, !value);
+ client.ExclusiveAddressUse = value;
}
}
#endif
@@ -310,38 +309,101 @@ namespace System.Net.Sockets
public void Connect (string hostname, int port)
{
- CheckDisposed ();
-
IPHostEntry host = Dns.GetHostByName(hostname);
- for(int i=0; i<host.AddressList.Length; i++) {
+ Connect (host.AddressList, port);
+ }
+
+#if NET_2_0
+ public
+#else
+ private
+#endif
+ void Connect (IPAddress[] ipAddresses, int port)
+ {
+ CheckDisposed ();
+
+ if (ipAddresses == null) {
+ throw new ArgumentNullException ("ipAddresses");
+ }
+
+ for(int i = 0; i < ipAddresses.Length; i++) {
try {
- Init(host.AddressList[i].AddressFamily);
+ IPAddress address = ipAddresses[i];
- if(host.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
- client.Bind(new IPEndPoint(IPAddress.Any, 0));
+ if (address.Equals (IPAddress.Any) ||
+ address.Equals (IPAddress.IPv6Any)) {
+ throw new SocketException ((int)SocketError.AddressNotAvailable);
+ }
+
+ Init (address.AddressFamily);
+
+ if (address.AddressFamily == AddressFamily.InterNetwork) {
+ client.Bind (new IPEndPoint (IPAddress.Any, 0));
#if NET_1_1
- else if(host.AddressList[i].AddressFamily == AddressFamily.InterNetworkV6)
- client.Bind(new IPEndPoint(IPAddress.IPv6Any, 0));
+ } else if (address.AddressFamily == AddressFamily.InterNetworkV6) {
+ client.Bind (new IPEndPoint (IPAddress.IPv6Any, 0));
#endif
+ } else {
+ throw new NotSupportedException ("This method is only valid for sockets in the InterNetwork and InterNetworkV6 families");
+ }
- Connect(new IPEndPoint(host.AddressList[i], port));
- if (values != 0)
+ Connect (new IPEndPoint (address, port));
+
+ if (values != 0) {
SetOptions ();
+ }
+
break;
} catch (Exception e) {
- if(client != null) {
- client.Close();
+ if (client != null) {
+ client.Close ();
client = null;
}
- /// This is the last known address, re-throw the exception
- if(i == host.AddressList.Length-1)
+ /* This is the last known
+ * address, so re-throw the
+ * exception
+ */
+ if (i == ipAddresses.Length - 1) {
throw e;
+ }
}
}
}
+#if NET_2_0
+ public void EndConnect (IAsyncResult asyncResult)
+ {
+ client.EndConnect (asyncResult);
+ }
+
+ public IAsyncResult BeginConnect (IPAddress address, int port,
+ AsyncCallback callback,
+ object state)
+ {
+ return(client.BeginConnect (address, port, callback,
+ state));
+ }
+
+ public IAsyncResult BeginConnect (IPAddress[] addresses,
+ int port,
+ AsyncCallback callback,
+ object state)
+ {
+ return(client.BeginConnect (addresses, port, callback,
+ state));
+ }
+
+ public IAsyncResult BeginConnect (string host, int port,
+ AsyncCallback callback,
+ object state)
+ {
+ return(client.BeginConnect (host, port, callback,
+ state));
+ }
+#endif
+
void IDisposable.Dispose ()
{
Dispose (true);
diff --git a/mcs/class/System/Test/System.Net.Sockets/ChangeLog b/mcs/class/System/Test/System.Net.Sockets/ChangeLog
index 0cc7827de99..41844b14271 100644
--- a/mcs/class/System/Test/System.Net.Sockets/ChangeLog
+++ b/mcs/class/System/Test/System.Net.Sockets/ChangeLog
@@ -1,3 +1,7 @@
+2007-01-23 Dick Porter <dick@ximian.com>
+
+ * TcpClientTest.cs: Test 2.0 Connect(IPAddress[], port) overload
+
2007-01-11 Dick Porter <dick@ximian.com>
* SocketTest.cs:
diff --git a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs
index 8b6aac55a8e..295804b193c 100644
--- a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs
+++ b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs
@@ -71,6 +71,56 @@ namespace MonoTests.System.Net.Sockets {
lSock.Close();
}
+
+#if NET_2_0
+ [Test]
+ [ExpectedException (typeof(ArgumentNullException))]
+ public void ConnectMultiNull ()
+ {
+ TcpClient client = new TcpClient ();
+ IPAddress[] ipAddresses = null;
+
+ client.Connect (ipAddresses, 1234);
+ }
+
+ [Test]
+ public void ConnectMultiAny ()
+ {
+ TcpClient client = new TcpClient ();
+ IPAddress[] ipAddresses = new IPAddress[1];
+
+ ipAddresses[0] = IPAddress.Any;
+
+ try {
+ client.Connect (ipAddresses, 1234);
+ Assert.Fail ("ConnectMultiAny #1");
+ } catch (SocketException ex) {
+ Assertion.AssertEquals ("ConnectMultiAny #2",
+ 10049, ex.ErrorCode);
+ } catch {
+ Assert.Fail ("ConnectMultiAny #3");
+ }
+ }
+
+ [Test]
+ public void ConnectMultiRefused ()
+ {
+ TcpClient client = new TcpClient ();
+ IPAddress[] ipAddresses = new IPAddress[1];
+
+ ipAddresses[0] = IPAddress.Loopback;
+
+ try {
+ client.Connect (ipAddresses, 1234);
+ Assert.Fail ("ConnectMultiRefused #1");
+ } catch (SocketException ex) {
+ Assertion.AssertEquals ("ConnectMultiRefused #2", 10061, ex.ErrorCode);
+ } catch {
+ Assert.Fail ("ConnectMultiRefused #3");
+ }
+ }
+
+#endif
}