diff options
author | Patrik Torstensson <totte@mono-cvs.ximian.com> | 2004-05-21 21:05:32 +0400 |
---|---|---|
committer | Patrik Torstensson <totte@mono-cvs.ximian.com> | 2004-05-21 21:05:32 +0400 |
commit | ef50c1b2e1dd09e527840e38355b6e906275872c (patch) | |
tree | 9f9ca13701ff6757f4d4313368522f4f591cad25 /mcs/class/System/System.Net.Sockets | |
parent | f773ee528af20d6db55b37a3a95212f8bcff66df (diff) |
2004-05-21 Patrik Torstensson <totte@hiddenpeaks.com>
* TcpListener.cs: Fixes a lot of the problems with remoting nunit tests.
(AcceptTcpClient): Don't create TcpClient before a
connection is accepted.
(LocalEndPoint): Use Server LocalEndPoint if connected
otherwise use endpoint from ctor.
(Init): Save end point, not server endpoint. This did
cause TcpListener to ignore port sent via constructor.
(Pending): Fixed wait time (method should return directly)
(Start): Moved Bind here instead of Init method; old method
caused us to bind ports even if the listener was stopped.
(Stop): Null server when stopping
svn path=/trunk/mcs/; revision=27837
Diffstat (limited to 'mcs/class/System/System.Net.Sockets')
-rw-r--r-- | mcs/class/System/System.Net.Sockets/ChangeLog | 20 | ||||
-rwxr-xr-x | mcs/class/System/System.Net.Sockets/TcpListener.cs | 43 |
2 files changed, 49 insertions, 14 deletions
diff --git a/mcs/class/System/System.Net.Sockets/ChangeLog b/mcs/class/System/System.Net.Sockets/ChangeLog index 3c81b6f5d07..08373b44c9d 100644 --- a/mcs/class/System/System.Net.Sockets/ChangeLog +++ b/mcs/class/System/System.Net.Sockets/ChangeLog @@ -1,3 +1,23 @@ +2004-05-21 Patrik Torstensson <totte@hiddenpeaks.com> + + * TcpListener.cs: Fixes a lot of the problems with remoting nunit tests. + + (AcceptTcpClient): Don't create TcpClient before a + connection is accepted. + + (LocalEndPoint): Use Server LocalEndPoint if connected + otherwise use endpoint from ctor. + + (Init): Save end point, not server endpoint. This did + cause TcpListener to ignore port sent via constructor. + + (Pending): Fixed wait time (method should return directly) + + (Start): Moved Bind here instead of Init method; old method + caused us to bind ports even if the listener was stopped. + + (Stop): Null server when stopping + 2004-05-13 Dick Porter <dick@ximian.com> * UdpClient.cs: diff --git a/mcs/class/System/System.Net.Sockets/TcpListener.cs b/mcs/class/System/System.Net.Sockets/TcpListener.cs index a9fc6434782..834ea219b51 100755 --- a/mcs/class/System/System.Net.Sockets/TcpListener.cs +++ b/mcs/class/System/System.Net.Sockets/TcpListener.cs @@ -3,11 +3,13 @@ // Authors: // Phillip Pearson (pp@myelin.co.nz) // Gonzalo Paniagua Javier (gonzalo@ximian.com) +// Patrik Torstensson // // Copyright (C) 2001, Phillip Pearson // http://www.myelin.co.nz // // (c) 2003 Ximian, Inc. (http://www.ximian.com) +// (c) 2004 Novell, Inc. // using System; @@ -36,8 +38,7 @@ namespace System.Net.Sockets { active = false; server = new Socket(family, SocketType.Stream, ProtocolType.Tcp); - server.Bind (ep); - savedEP = server.LocalEndPoint; + savedEP = ep; } /// <summary> @@ -102,7 +103,12 @@ namespace System.Net.Sockets /// </summary> public EndPoint LocalEndpoint { - get { return savedEP; } + get { + if (active) + return server.LocalEndPoint; + + return savedEP; + } } /// <summary> @@ -138,10 +144,13 @@ namespace System.Net.Sockets if (!active) throw new InvalidOperationException ("Socket is not listening"); + Socket clientSocket = server.Accept (); + TcpClient client = new TcpClient(); // use internal method SetTcpClient to make a // client with the specified socket - client.SetTcpClient(AcceptSocket()); + client.SetTcpClient (clientSocket); + return client; } @@ -163,25 +172,28 @@ namespace System.Net.Sockets if (!active) throw new InvalidOperationException ("Socket is not listening"); - return server.Poll(1000, SelectMode.SelectRead); + return server.Poll(0, SelectMode.SelectRead); } /// <summary> /// Tells the TcpListener to start listening. /// </summary> - [MonoTODO] public void Start () { if (active) return; - server.Listen(5); // According to the - // man page some BSD - // and BSD-derived - // systems limit the - // backlog to 5. This - // should really be - // configurable though + if (server == null) + throw new InvalidOperationException("Invalid server socket"); + + server.Bind (savedEP); + + // MS: sets Listen to Int32.MaxValue + server.Listen(5); + // According to the man page some BSD and BSD-derived + // systems limit the backlog to 5. This should really be + // configurable though + active = true; } @@ -191,8 +203,11 @@ namespace System.Net.Sockets /// </summary> public void Stop () { - if (active) + if (active)
+ {
server.Close (); + server = null; + } Init (AddressFamily.InterNetwork, savedEP); } |