From c79b08d83c0c577b72b7240505d5815c569ebcf2 Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 11 Oct 2016 18:27:03 +0200 Subject: [PATCH] [System] More Socket types from referencesource --- mcs/class/System/ReferenceSources/Logging.cs | 8 + .../System.Net.Sockets/SendPacketsElement.cs | 89 ---- .../System.Net.Sockets/SocketAsyncOperation.cs | 44 -- mcs/class/System/System.Net.Sockets/TcpClient.cs | 450 --------------------- mcs/class/System/System.Net.Sockets/TcpListener.cs | 335 --------------- mcs/class/System/System.dll.sources | 46 +-- .../Test/System.Net.Sockets/TcpClientTest.cs | 2 +- mcs/class/System/mobile_System.dll.sources | 46 +-- .../monotouch_watch_System.dll.exclude.sources | 2 + .../System/net/System/Net/Sockets/Socket.cs | 31 +- 10 files changed, 83 insertions(+), 970 deletions(-) delete mode 100644 mcs/class/System/System.Net.Sockets/SendPacketsElement.cs delete mode 100644 mcs/class/System/System.Net.Sockets/SocketAsyncOperation.cs delete mode 100644 mcs/class/System/System.Net.Sockets/TcpClient.cs delete mode 100644 mcs/class/System/System.Net.Sockets/TcpListener.cs diff --git a/mcs/class/System/ReferenceSources/Logging.cs b/mcs/class/System/ReferenceSources/Logging.cs index 39f628a2af6..8eb5e066d02 100644 --- a/mcs/class/System/ReferenceSources/Logging.cs +++ b/mcs/class/System/ReferenceSources/Logging.cs @@ -32,6 +32,10 @@ namespace System.Net { } [Conditional ("TRACE")] + internal static void Enter(TraceSource traceSource, string msg, string parameters) { + } + + [Conditional ("TRACE")] internal static void Exception(TraceSource traceSource, object obj, string method, Exception e) { } @@ -44,6 +48,10 @@ namespace System.Net { } [Conditional ("TRACE")] + internal static void Exit(TraceSource traceSource, string msg, string parameters) { + } + + [Conditional ("TRACE")] internal static void PrintInfo(TraceSource traceSource, object obj, string method, string msg) { } diff --git a/mcs/class/System/System.Net.Sockets/SendPacketsElement.cs b/mcs/class/System/System.Net.Sockets/SendPacketsElement.cs deleted file mode 100644 index 983faa98047..00000000000 --- a/mcs/class/System/System.Net.Sockets/SendPacketsElement.cs +++ /dev/null @@ -1,89 +0,0 @@ -// System.Net.Sockets.SocketAsyncEventArgs.cs -// -// Authors: -// Marek Habersack (mhabersack@novell.com) -// -// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System; - -namespace System.Net.Sockets -{ - public class SendPacketsElement - { - public byte[] Buffer { get; private set; } - public int Count { get; private set; } - public bool EndOfPacket { get; private set; } - public string FilePath { get; private set; } - public int Offset { get; private set; } - - public SendPacketsElement (byte[] buffer) : this (buffer, 0, buffer != null ? buffer.Length : 0) - { - } - - public SendPacketsElement (byte[] buffer, int offset, int count) : this (buffer, offset, count, false) - { - } - - public SendPacketsElement (byte[] buffer, int offset, int count, bool endOfPacket) - { - if (buffer == null) - throw new ArgumentNullException ("buffer"); - - int buflen = buffer.Length; - if (offset < 0 || offset >= buflen) - throw new ArgumentOutOfRangeException ("offset"); - - if (count < 0 || offset + count >= buflen) - throw new ArgumentOutOfRangeException ("count"); - - Buffer = buffer; - Offset = offset; - Count = count; - EndOfPacket = endOfPacket; - FilePath = null; - } - - public SendPacketsElement (string filepath) : this (filepath, 0, 0, false) - { - } - - public SendPacketsElement (string filepath, int offset, int count) : this (filepath, offset, count, false) - { - } - - // LAME SPEC: only ArgumentNullException for filepath is thrown - public SendPacketsElement (string filepath, int offset, int count, bool endOfPacket) - { - if (filepath == null) - throw new ArgumentNullException ("filepath"); - - Buffer = null; - Offset = offset; - Count = count; - EndOfPacket = endOfPacket; - FilePath = filepath; - } - } -} diff --git a/mcs/class/System/System.Net.Sockets/SocketAsyncOperation.cs b/mcs/class/System/System.Net.Sockets/SocketAsyncOperation.cs deleted file mode 100644 index 87d6de568cb..00000000000 --- a/mcs/class/System/System.Net.Sockets/SocketAsyncOperation.cs +++ /dev/null @@ -1,44 +0,0 @@ -// System.Net.Sockets.SocketAsyncOperation.cs -// -// Authors: -// Marek Habersack (mhabersack@novell.com) -// -// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -namespace System.Net.Sockets -{ - public enum SocketAsyncOperation - { - None, - Accept, - Connect, - Disconnect, - Receive, - ReceiveFrom, - ReceiveMessageFrom, - Send, - SendPackets, - SendTo - } -} diff --git a/mcs/class/System/System.Net.Sockets/TcpClient.cs b/mcs/class/System/System.Net.Sockets/TcpClient.cs deleted file mode 100644 index bbdb034aa15..00000000000 --- a/mcs/class/System/System.Net.Sockets/TcpClient.cs +++ /dev/null @@ -1,450 +0,0 @@ -// TcpClient.cs -// -// Author: -// Phillip Pearson (pp@myelin.co.nz) -// Gonzalo Paniagua Javier (gonzalo@novell.com) -// Sridhar Kulkarni (sridharkulkarni@gmail.com) -// Marek Safar (marek.safar@gmail.com) -// -// Copyright (C) 2001, Phillip Pearson http://www.myelin.co.nz -// Copyright (c) 2006 Novell, Inc. (http://www.novell.com) -// Copyright 2011 Xamarin Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Net; -using System.Threading.Tasks; - -namespace System.Net.Sockets -{ - public class TcpClient : IDisposable { - enum Properties : uint { - LingerState = 1, - NoDelay = 2, - ReceiveBufferSize = 4, - ReceiveTimeout = 8, - SendBufferSize = 16, - SendTimeout = 32 - } - - // private data - NetworkStream stream; - bool active; - Socket client; - bool disposed; - Properties values; - int recv_timeout, send_timeout; - int recv_buffer_size, send_buffer_size; - LingerOption linger_state; - bool no_delay; - - private void Init (AddressFamily family) - { - active = false; - - if(client != null) { - client.Close(); - client = null; - } - - client = new Socket(family, SocketType.Stream, ProtocolType.Tcp); - } - - public TcpClient () - { - Init(AddressFamily.InterNetwork); - client.Bind(new IPEndPoint(IPAddress.Any, 0)); - } - - internal TcpClient (Socket s) - { - client = s; - } - - public TcpClient (AddressFamily family) - { - if (family != AddressFamily.InterNetwork && - family != AddressFamily.InterNetworkV6) { - throw new ArgumentException ("Family must be InterNetwork or InterNetworkV6", "family"); - } - - Init (family); - IPAddress any = IPAddress.Any; - if (family == AddressFamily.InterNetworkV6) - any = IPAddress.IPv6Any; - client.Bind (new IPEndPoint (any, 0)); - } - - public TcpClient (IPEndPoint localEP) - { - Init (localEP.AddressFamily); - client.Bind (localEP); - } - - public TcpClient (string hostname, int port) - { - Connect(hostname, port); - } - - protected bool Active { - get { return active; } - set { active = value; } - } - - public Socket Client { - get { return client; } - set { - client = value; - stream = null; - } - } - - public int Available { - get { return client.Available; } - } - - public bool Connected { - get { return client.Connected; } - } - - public bool ExclusiveAddressUse { - get { - return(client.ExclusiveAddressUse); - } - set { - client.ExclusiveAddressUse = value; - } - } - - public LingerOption LingerState { - get { - if ((values & Properties.LingerState) != 0) - return linger_state; - - return (LingerOption) client.GetSocketOption (SocketOptionLevel.Socket, - SocketOptionName.Linger); - } - set { - if (!client.Connected) { - linger_state = value; - values |= Properties.LingerState; - return; - } - client.SetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.Linger, value); - } - } - - public bool NoDelay { - get { - if ((values & Properties.NoDelay) != 0) - return no_delay; - - return (bool)client.GetSocketOption( - SocketOptionLevel.Tcp, - SocketOptionName.NoDelay); - } - set { - if (!client.Connected) { - no_delay = value; - values |= Properties.NoDelay; - return; - } - client.SetSocketOption( - SocketOptionLevel.Tcp, - SocketOptionName.NoDelay, value ? 1 : 0); - } - } - - public int ReceiveBufferSize { - get { - if ((values & Properties.ReceiveBufferSize) != 0) - return recv_buffer_size; - - return (int)client.GetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.ReceiveBuffer); - } - set { - if (!client.Connected) { - recv_buffer_size = value; - values |= Properties.ReceiveBufferSize; - return; - } - client.SetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.ReceiveBuffer, value); - } - } - - public int ReceiveTimeout { - get { - if ((values & Properties.ReceiveTimeout) != 0) - return recv_timeout; - - return (int)client.GetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.ReceiveTimeout); - } - set { - if (!client.Connected) { - recv_timeout = value; - values |= Properties.ReceiveTimeout; - return; - } - client.SetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.ReceiveTimeout, value); - } - } - - public int SendBufferSize { - get { - if ((values & Properties.SendBufferSize) != 0) - return send_buffer_size; - - return (int)client.GetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.SendBuffer); - } - set { - if (!client.Connected) { - send_buffer_size = value; - values |= Properties.SendBufferSize; - return; - } - client.SetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.SendBuffer, value); - } - } - - public int SendTimeout { - get { - if ((values & Properties.SendTimeout) != 0) - return send_timeout; - - return (int)client.GetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.SendTimeout); - } - set { - if (!client.Connected) { - send_timeout = value; - values |= Properties.SendTimeout; - return; - } - client.SetSocketOption( - SocketOptionLevel.Socket, - SocketOptionName.SendTimeout, value); - } - } - - - // methods - - public void Close () - { - Dispose (); - } - - public void Connect (IPEndPoint remoteEP) - { - try { - client.Connect (remoteEP); - active = true; - } finally { - CheckDisposed (); - } - } - - public void Connect (IPAddress address, int port) - { - Connect(new IPEndPoint(address, port)); - } - - void SetOptions () - { - Properties props = values; - values = 0; - - if ((props & Properties.LingerState) != 0) - LingerState = linger_state; - if ((props & Properties.NoDelay) != 0) - NoDelay = no_delay; - if ((props & Properties.ReceiveBufferSize) != 0) - ReceiveBufferSize = recv_buffer_size; - if ((props & Properties.ReceiveTimeout) != 0) - ReceiveTimeout = recv_timeout; - if ((props & Properties.SendBufferSize) != 0) - SendBufferSize = send_buffer_size; - if ((props & Properties.SendTimeout) != 0) - SendTimeout = send_timeout; - } - - public void Connect (string hostname, int port) - { - IPAddress [] addresses = Dns.GetHostAddresses (hostname); - Connect (addresses, port); - } - - public void Connect (IPAddress[] ipAddresses, int port) - { - CheckDisposed (); - - if (ipAddresses == null) { - throw new ArgumentNullException ("ipAddresses"); - } - - for(int i = 0; i < ipAddresses.Length; i++) { - try { - IPAddress address = ipAddresses[i]; - - 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)); - } else if (address.AddressFamily == AddressFamily.InterNetworkV6) { - client.Bind (new IPEndPoint (IPAddress.IPv6Any, 0)); - } else { - throw new NotSupportedException ("This method is only valid for sockets in the InterNetwork and InterNetworkV6 families"); - } - - Connect (new IPEndPoint (address, port)); - - if (values != 0) { - SetOptions (); - } - - break; - } catch (Exception e) { - /* Reinitialise the socket so - * other properties still work - * (see no-arg constructor) - */ - Init (AddressFamily.InterNetwork); - - /* This is the last known - * address, so re-throw the - * exception - */ - if (i == ipAddresses.Length - 1) { - throw e; - } - } - } - } - - public void EndConnect (IAsyncResult asyncResult) - { - client.EndConnect (asyncResult); - } - - public IAsyncResult BeginConnect (IPAddress address, int port, AsyncCallback requestCallback, object state) - { - return client.BeginConnect (address, port, requestCallback, state); - } - - public IAsyncResult BeginConnect (IPAddress[] addresses, int port, AsyncCallback requestCallback, object state) - { - return client.BeginConnect (addresses, port, requestCallback, state); - } - - public IAsyncResult BeginConnect (string host, int port, AsyncCallback requestCallback, object state) - { - return client.BeginConnect (host, port, requestCallback, state); - } - - public void Dispose () - { - Dispose (true); - GC.SuppressFinalize (this); - } - - protected virtual void Dispose (bool disposing) - { - if (disposed) - return; - disposed = true; - - if (disposing) { - // release managed resources - NetworkStream s = stream; - stream = null; - if (s != null) { - // This closes the socket as well, as the NetworkStream - // owns the socket. - s.Close(); - active = false; - s = null; - } else if (client != null){ - client.Close (); - client = null; - } - } - } - - ~TcpClient () - { - Dispose (false); - } - - public NetworkStream GetStream() - { - try { - if (stream == null) - stream = new NetworkStream (client, true); - return stream; - } - finally { CheckDisposed (); } - } - - public Task ConnectAsync (IPAddress address, int port) - { - return Task.Factory.FromAsync (BeginConnect, EndConnect, address, port, null); - } - - public Task ConnectAsync (IPAddress[] addresses, int port) - { - return Task.Factory.FromAsync (BeginConnect, EndConnect, addresses, port, null); - } - - public Task ConnectAsync (string host, int port) - { - return Task.Factory.FromAsync (BeginConnect, EndConnect, host, port, null); - } - private void CheckDisposed () - { - if (disposed) - throw new ObjectDisposedException (GetType().FullName); - } - } -} - diff --git a/mcs/class/System/System.Net.Sockets/TcpListener.cs b/mcs/class/System/System.Net.Sockets/TcpListener.cs deleted file mode 100644 index e8b8ec40e0e..00000000000 --- a/mcs/class/System/System.Net.Sockets/TcpListener.cs +++ /dev/null @@ -1,335 +0,0 @@ -// TcpListener.cs -// -// Authors: -// Phillip Pearson (pp@myelin.co.nz) -// Gonzalo Paniagua Javier (gonzalo@ximian.com) -// Patrik Torstensson -// Sridhar Kulkarni (sridharkulkarni@gmail.com) -// Marek Safar (marek.safar@gmail.com) - -// -// Copyright (C) 2001, Phillip Pearson http://www.myelin.co.nz -// -// (c) 2003 Ximian, Inc. (http://www.ximian.com) -// (c) 2004-2006 Novell, Inc. -// Copyright 2011 Xamarin Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Net; -using System.Threading.Tasks; - -namespace System.Net.Sockets -{ - /// - /// A slightly more abstracted way to listen for incoming - /// network connections than a Socket. - /// - public class TcpListener - { - // private data - - bool active; - Socket server; - EndPoint savedEP; - - // constructor - - /// - /// Some code that is shared between the constructors. - /// - private void Init (AddressFamily family, EndPoint ep) - { - active = false; - server = new Socket(family, SocketType.Stream, ProtocolType.Tcp); - savedEP = ep; - } - - /// - /// Constructs a new TcpListener to listen on a specified port - /// - /// The port to listen on, e.g. 80 if you - /// are a web server - [Obsolete ("Use TcpListener (IPAddress address, int port) instead")] - public TcpListener (int port) - { - if (port < 0 || port > 65535) - throw new ArgumentOutOfRangeException ("port"); - - Init (AddressFamily.InterNetwork, new IPEndPoint (IPAddress.Any, port)); - } - - /// - /// Constructs a new TcpListener with a specified local endpoint - /// - /// The endpoint - public TcpListener (IPEndPoint localEP) - { - if (localEP == null) - throw new ArgumentNullException ("localEP"); - - Init (localEP.AddressFamily, localEP); - } - - /// - /// Constructs a new TcpListener, listening on a specified port - /// and IP (for use on a multi-homed machine) - /// - /// The IP to listen on - /// The port to listen on - public TcpListener (IPAddress localaddr, int port) - { - if (localaddr == null) - throw new ArgumentNullException ("localaddr"); - - if (port < 0 || port > 65535) - throw new ArgumentOutOfRangeException ("port"); - - Init (localaddr.AddressFamily, new IPEndPoint (localaddr, port)); - } - - - // properties - - /// - /// A flag that is 'true' if the TcpListener is listening, - /// or 'false' if it is not listening - /// - protected bool Active - { - get { return active; } - } - - /// - /// The local end point - /// - public EndPoint LocalEndpoint - { - get { - if (active) - return server.LocalEndPoint; - - return savedEP; - } - } - - /// - /// The listening socket - /// - public Socket Server - { - get { return server; } - } - - /// - /// Specifies whether the TcpListener allows only one - /// underlying socket to listen to a specific port - /// - public bool ExclusiveAddressUse - { - get { - if (server == null) { - throw new ObjectDisposedException (GetType ().ToString ()); - } - if (active) { - throw new InvalidOperationException ("The TcpListener has been started"); - } - - return(server.ExclusiveAddressUse); - } - set { - if (server == null) { - throw new ObjectDisposedException (GetType ().ToString ()); - } - if (active) { - throw new InvalidOperationException ("The TcpListener has been started"); - } - - server.ExclusiveAddressUse = value; - } - } - - // methods - - /// - /// Accepts a pending connection - /// - /// A Socket object for the new connection - public Socket AcceptSocket () - { - if (!active) - throw new InvalidOperationException ("Socket is not listening"); - - return server.Accept(); - } - - /// - /// Accepts a pending connection - /// - /// A TcpClient - /// object made from the new socket. - public TcpClient AcceptTcpClient () - { - if (!active) - throw new InvalidOperationException ("Socket is not listening"); - - Socket clientSocket = server.Accept (); - - TcpClient client = new TcpClient(clientSocket); - - return client; - } - - public void AllowNatTraversal (bool allowed) - { - if (active) - throw new InvalidOperationException (SR.GetString (SR.net_tcplistener_mustbestopped)); - - if (allowed) - server.SetIPProtectionLevel (IPProtectionLevel.Unrestricted); - else - server.SetIPProtectionLevel (IPProtectionLevel.EdgeRestricted); - } - - public static TcpListener Create (int port) - { - if (port < 0 || port > 65535) - throw new ArgumentOutOfRangeException ("port"); - - TcpListener listener = new TcpListener (IPAddress.IPv6Any, port); - listener.Server.DualMode = true; - - return listener; - } - - /// - /// Destructor - stops the listener listening - /// - ~TcpListener () - { - if (active) - Stop(); - } - - /// - /// Returns 'true' if there is a connection waiting to be accepted - /// with AcceptSocket() or AcceptTcpClient(). - /// - public bool Pending () - { - if (!active) - throw new InvalidOperationException ("Socket is not listening"); - - return server.Poll(0, SelectMode.SelectRead); - } - - /// - /// Tells the TcpListener to start listening. - /// - public void Start () - { - // MS: sets Listen to Int32.MaxValue - this.Start (5); - // According to the man page some BSD and BSD-derived - // systems limit the backlog to 5. This should really be - // configurable though - } - - /// - /// Tells the TcpListener to start listening for max number - /// of pending connections. - /// - - public void Start (int backlog) - { - if (active) { - return; - } - if (server == null) { - throw new InvalidOperationException ("Invalid server socket"); - } - - server.Bind (savedEP); - server.Listen (backlog); - active = true; - } - - public IAsyncResult BeginAcceptSocket (AsyncCallback callback, - object state) - { - if (server == null) { - throw new ObjectDisposedException (GetType ().ToString ()); - } - - return(server.BeginAccept (callback, state)); - } - - public IAsyncResult BeginAcceptTcpClient (AsyncCallback callback, object state) - { - if (server == null) { - throw new ObjectDisposedException (GetType ().ToString ()); - } - - return(server.BeginAccept (callback, state)); - } - - public Socket EndAcceptSocket (IAsyncResult asyncResult) - { - return(server.EndAccept (asyncResult)); - } - - public TcpClient EndAcceptTcpClient (IAsyncResult asyncResult) - { - Socket clientSocket = server.EndAccept (asyncResult); - TcpClient client = new TcpClient (clientSocket); - - return(client); - } - - /// - /// Tells the TcpListener to stop listening and dispose - /// of all managed resources. - /// - public void Stop () - { - if (active) - { - server.Close (); - server = null; - } - - Init (AddressFamily.InterNetwork, savedEP); - } - - public Task AcceptSocketAsync () - { - return Task.Factory.FromAsync (BeginAcceptSocket, EndAcceptSocket, null); - } - - public Task AcceptTcpClientAsync () - { - return Task.Factory.FromAsync (BeginAcceptTcpClient, EndAcceptTcpClient, null); - } - } -} diff --git a/mcs/class/System/System.dll.sources b/mcs/class/System/System.dll.sources index 59dea65742c..eaa0616d8c9 100644 --- a/mcs/class/System/System.dll.sources +++ b/mcs/class/System/System.dll.sources @@ -375,35 +375,11 @@ System.Net/ServicePointManager.extra.cs System.Net/SimpleAsyncResult.cs System.Net/SocketPermissionAttribute.cs System.Net/SocketPermission.cs -../referencesource/System/net/System/Net/Sockets/AddressFamily.cs -../referencesource/System/net/System/Net/Sockets/IOControlCode.cs -../referencesource/System/net/System/Net/Sockets/IPPacketInformation.cs -../referencesource/System/net/System/Net/Sockets/LingerOption.cs -../referencesource/System/net/System/Net/Sockets/MulticastOption.cs -../referencesource/System/net/System/Net/Sockets/ProtocolFamily.cs -../referencesource/System/net/System/Net/Sockets/ProtocolType.cs System.Net.Sockets/SafeSocketHandle.cs -../referencesource/System/net/System/Net/Sockets/SelectMode.cs -System.Net.Sockets/SendPacketsElement.cs System.Net.Sockets/Socket.cs -../referencesource/System/net/System/Net/Sockets/Socket.cs System.Net.Sockets/SocketAsyncEventArgs.cs -System.Net.Sockets/SocketAsyncOperation.cs System.Net.Sockets/SocketAsyncResult.cs -../referencesource/System/net/System/Net/Sockets/SocketErrors.cs -../referencesource/System/net/System/Net/SocketException.cs -../referencesource/System/net/System/Net/Sockets/SocketFlags.cs -../referencesource/System/net/System/Net/Sockets/SocketInformation.cs -../referencesource/System/net/System/Net/Sockets/SocketInformationOptions.cs System.Net.Sockets/SocketOperation.cs -../referencesource/System/net/System/Net/Sockets/SocketOptionLevel.cs -../referencesource/System/net/System/Net/Sockets/SocketOptionName.cs -../referencesource/System/net/System/Net/Sockets/SocketShutdown.cs -../referencesource/System/net/System/Net/Sockets/SocketType.cs -System.Net.Sockets/TcpClient.cs -System.Net.Sockets/TcpListener.cs -../referencesource/System/net/System/Net/Sockets/TransmitFileFlags.cs -../referencesource/System/net/System/Net/Sockets/UdpReceiveResult.cs System.Net/WebAsyncResult.cs System.Net/WebConnection.cs System.Net/WebConnectionData.cs @@ -1052,6 +1028,7 @@ ReferenceSources/Win32Exception.cs ../referencesource/System/net/System/Net/UnicodeEncodingConformance.cs ../referencesource/System/net/System/Net/ServicePointManager.cs ../referencesource/System/net/System/Net/SocketAddress.cs +../referencesource/System/net/System/Net/SocketException.cs ../referencesource/System/net/System/Net/webclient.cs ../referencesource/System/net/System/Net/WebException.cs ../referencesource/System/net/System/Net/WebExceptionStatus.cs @@ -1071,8 +1048,29 @@ ReferenceSources/Win32Exception.cs ../referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs +../referencesource/System/net/System/Net/Sockets/AddressFamily.cs +../referencesource/System/net/System/Net/Sockets/IOControlCode.cs +../referencesource/System/net/System/Net/Sockets/IPPacketInformation.cs ../referencesource/System/net/System/Net/Sockets/IPProtectionLevel.cs +../referencesource/System/net/System/Net/Sockets/LingerOption.cs +../referencesource/System/net/System/Net/Sockets/MulticastOption.cs ../referencesource/System/net/System/Net/Sockets/NetworkStream.cs +../referencesource/System/net/System/Net/Sockets/ProtocolFamily.cs +../referencesource/System/net/System/Net/Sockets/ProtocolType.cs +../referencesource/System/net/System/Net/Sockets/SelectMode.cs +../referencesource/System/net/System/Net/Sockets/Socket.cs +../referencesource/System/net/System/Net/Sockets/SocketErrors.cs +../referencesource/System/net/System/Net/Sockets/SocketFlags.cs +../referencesource/System/net/System/Net/Sockets/SocketInformation.cs +../referencesource/System/net/System/Net/Sockets/SocketInformationOptions.cs +../referencesource/System/net/System/Net/Sockets/SocketOptionLevel.cs +../referencesource/System/net/System/Net/Sockets/SocketOptionName.cs +../referencesource/System/net/System/Net/Sockets/SocketShutdown.cs +../referencesource/System/net/System/Net/Sockets/SocketType.cs +../referencesource/System/net/System/Net/Sockets/TCPClient.cs +../referencesource/System/net/System/Net/Sockets/TCPListener.cs +../referencesource/System/net/System/Net/Sockets/TransmitFileFlags.cs +../referencesource/System/net/System/Net/Sockets/UdpReceiveResult.cs ../referencesource/System/net/System/Net/Sockets/UDPClient.cs ../referencesource/System/net/System/Net/NetworkInformation/DuplicateAddressDetectionState.cs diff --git a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs index 5db3aadbc87..a9e849fc1e7 100644 --- a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs @@ -173,7 +173,7 @@ namespace MonoTests.System.Net.Sockets client.Connect (ipAddresses, 1234); Assert.Fail ("ConnectMultiAny #1"); } catch (SocketException ex) { - Assert.AreEqual (10049, ex.ErrorCode, "ConnectMultiAny #2"); + Assert.AreEqual (10061, ex.ErrorCode, "ConnectMultiAny #2"); } catch { Assert.Fail ("ConnectMultiAny #3"); } diff --git a/mcs/class/System/mobile_System.dll.sources b/mcs/class/System/mobile_System.dll.sources index 0f60935840b..5a7d8a3480e 100644 --- a/mcs/class/System/mobile_System.dll.sources +++ b/mcs/class/System/mobile_System.dll.sources @@ -118,35 +118,11 @@ System.Net.Security/SslPolicyErrors.cs System.Net.Security/SslStream.cs System.Net/SocketPermissionAttribute.cs System.Net/SocketPermission.cs -../referencesource/System/net/System/Net/Sockets/AddressFamily.cs -../referencesource/System/net/System/Net/Sockets/IOControlCode.cs -../referencesource/System/net/System/Net/Sockets/IPPacketInformation.cs -../referencesource/System/net/System/Net/Sockets/LingerOption.cs -../referencesource/System/net/System/Net/Sockets/MulticastOption.cs -../referencesource/System/net/System/Net/Sockets/ProtocolFamily.cs -../referencesource/System/net/System/Net/Sockets/ProtocolType.cs System.Net.Sockets/SafeSocketHandle.cs -../referencesource/System/net/System/Net/Sockets/SelectMode.cs -System.Net.Sockets/SendPacketsElement.cs System.Net.Sockets/Socket.cs -../referencesource/System/net/System/Net/Sockets/Socket.cs System.Net.Sockets/SocketAsyncEventArgs.cs -System.Net.Sockets/SocketAsyncOperation.cs System.Net.Sockets/SocketAsyncResult.cs -../referencesource/System/net/System/Net/Sockets/SocketErrors.cs -../referencesource/System/net/System/Net/SocketException.cs -../referencesource/System/net/System/Net/Sockets/SocketFlags.cs -../referencesource/System/net/System/Net/Sockets/SocketInformation.cs -../referencesource/System/net/System/Net/Sockets/SocketInformationOptions.cs System.Net.Sockets/SocketOperation.cs -../referencesource/System/net/System/Net/Sockets/SocketOptionLevel.cs -../referencesource/System/net/System/Net/Sockets/SocketOptionName.cs -../referencesource/System/net/System/Net/Sockets/SocketShutdown.cs -../referencesource/System/net/System/Net/Sockets/SocketType.cs -System.Net.Sockets/TcpClient.cs -System.Net.Sockets/TcpListener.cs -../referencesource/System/net/System/Net/Sockets/TransmitFileFlags.cs -../referencesource/System/net/System/Net/Sockets/UdpReceiveResult.cs System.Net/AuthenticationManager.cs System.Net/BasicClient.cs System.Net/BindIPEndPoint.cs @@ -785,6 +761,7 @@ ReferenceSources/Win32Exception.cs ../referencesource/System/net/System/Net/UnicodeEncodingConformance.cs ../referencesource/System/net/System/Net/ServicePointManager.cs ../referencesource/System/net/System/Net/SocketAddress.cs +../referencesource/System/net/System/Net/SocketException.cs ../referencesource/System/net/System/Net/webclient.cs ../referencesource/System/net/System/Net/WebException.cs ../referencesource/System/net/System/Net/WebExceptionStatus.cs @@ -804,8 +781,29 @@ ReferenceSources/Win32Exception.cs ../referencesource/System/net/System/Net/Configuration/DefaultProxySection.cs +../referencesource/System/net/System/Net/Sockets/AddressFamily.cs +../referencesource/System/net/System/Net/Sockets/IOControlCode.cs +../referencesource/System/net/System/Net/Sockets/IPPacketInformation.cs ../referencesource/System/net/System/Net/Sockets/IPProtectionLevel.cs +../referencesource/System/net/System/Net/Sockets/LingerOption.cs +../referencesource/System/net/System/Net/Sockets/MulticastOption.cs ../referencesource/System/net/System/Net/Sockets/NetworkStream.cs +../referencesource/System/net/System/Net/Sockets/ProtocolFamily.cs +../referencesource/System/net/System/Net/Sockets/ProtocolType.cs +../referencesource/System/net/System/Net/Sockets/SelectMode.cs +../referencesource/System/net/System/Net/Sockets/Socket.cs +../referencesource/System/net/System/Net/Sockets/SocketErrors.cs +../referencesource/System/net/System/Net/Sockets/SocketFlags.cs +../referencesource/System/net/System/Net/Sockets/SocketInformation.cs +../referencesource/System/net/System/Net/Sockets/SocketInformationOptions.cs +../referencesource/System/net/System/Net/Sockets/SocketOptionLevel.cs +../referencesource/System/net/System/Net/Sockets/SocketOptionName.cs +../referencesource/System/net/System/Net/Sockets/SocketShutdown.cs +../referencesource/System/net/System/Net/Sockets/SocketType.cs +../referencesource/System/net/System/Net/Sockets/TCPClient.cs +../referencesource/System/net/System/Net/Sockets/TCPListener.cs +../referencesource/System/net/System/Net/Sockets/TransmitFileFlags.cs +../referencesource/System/net/System/Net/Sockets/UdpReceiveResult.cs ../referencesource/System/net/System/Net/Sockets/UDPClient.cs ../referencesource/System/net/System/Net/NetworkInformation/DuplicateAddressDetectionState.cs diff --git a/mcs/class/System/monotouch_watch_System.dll.exclude.sources b/mcs/class/System/monotouch_watch_System.dll.exclude.sources index 83678267a4c..1f1f61233b0 100644 --- a/mcs/class/System/monotouch_watch_System.dll.exclude.sources +++ b/mcs/class/System/monotouch_watch_System.dll.exclude.sources @@ -179,4 +179,6 @@ Mono.Btls/MonoBtlsX509VerifyFlags.cs Mono.Btls/MonoBtlsX509VerifyParam.cs Mono.Btls/X509CertificateImplBtls.cs Mono.Btls/X509ChainImplBtls.cs +../referencesource/System/net/System/Net/Sockets/TCPClient.cs +../referencesource/System/net/System/Net/Sockets/TCPListener.cs ../referencesource/System/net/System/Net/Sockets/UDPClient.cs diff --git a/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs b/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs index 7d5b89f6f3c..26248db1547 100644 --- a/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs +++ b/mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs @@ -8427,7 +8427,7 @@ namespace System.Net.Sockets { internal AcceptAsyncResult(object myObject, object myState, AsyncCallback myCallBack):base(myObject, myState, myCallBack) { } } - +#endif public enum SocketAsyncOperation { None = 0, @@ -8448,7 +8448,11 @@ namespace System.Net.Sockets { internal byte [] m_Buffer; internal int m_Offset; internal int m_Count; +#if MONO + bool m_endOfPacket; +#else internal UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags m_Flags; +#endif // hide default constructor private SendPacketsElement() {} @@ -8474,8 +8478,13 @@ namespace System.Net.Sockets { } Contract.EndContractBlock(); +#if MONO + Initialize(filepath, null, offset, count, /*UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.File,*/ + endOfPacket); +#else Initialize(filepath, null, offset, count, UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.File, endOfPacket); +#endif } // constructors for buffer elements @@ -8497,21 +8506,30 @@ namespace System.Net.Sockets { } Contract.EndContractBlock(); +#if MONO + Initialize(null, buffer, offset, count, /*UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.Memory,*/ + endOfPacket); +#else Initialize(null, buffer, offset, count, UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.Memory, endOfPacket); +#endif } private void Initialize(string filePath, byte[] buffer, int offset, int count, - UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags flags, bool endOfPacket) { + /*UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags flags,*/ bool endOfPacket) { m_FilePath = filePath; m_Buffer = buffer; m_Offset = offset; m_Count = count; +#if MONO + m_endOfPacket = endOfPacket; +#else m_Flags = flags; if (endOfPacket) { m_Flags |= UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.EndOfPacket; } +#endif } // Filename property @@ -8536,7 +8554,13 @@ namespace System.Net.Sockets { // EndOfPacket property public bool EndOfPacket { - get { return (m_Flags & UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.EndOfPacket) != 0; } + get { +#if MONO + return m_endOfPacket; +#else + return (m_Flags & UnsafeNclNativeMethods.OSSOCK.TransmitPacketsElementFlags.EndOfPacket) != 0; +#endif + } } } @@ -8551,6 +8575,7 @@ namespace System.Net.Sockets { } #endregion +#if !MONO public class SocketAsyncEventArgs : EventArgs, IDisposable { // Struct sizes needed for some custom marshalling. -- 2.11.4.GIT