Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@@ -1 +1 @@
999ca900d5443337a86927d0d2ef2add4422f2b4
64363911e4072d3b513ab012ba99c8b2a99ce860

View File

@@ -61,13 +61,13 @@ namespace System.Net.Sockets
private set;
}
IList <ArraySegment <byte>> _bufferList;
internal IList<ArraySegment<byte>> m_BufferList;
public IList<ArraySegment<byte>> BufferList {
get { return _bufferList; }
get { return m_BufferList; }
set {
if (Buffer != null && value != null)
throw new ArgumentException ("Buffer and BufferList properties cannot both be non-null.");
_bufferList = value;
m_BufferList = value;
}
}
@@ -111,12 +111,10 @@ namespace System.Net.Sockets
set;
}
#if !NET_2_1
public TransmitFileOptions SendPacketsFlags {
get;
set;
}
#endif
[MonoTODO ("unused property")]
public int SendPacketsSendSize {
@@ -236,5 +234,43 @@ namespace System.Net.Sockets
Buffer = buffer;
}
internal void StartOperationCommon (Socket socket)
{
current_socket = socket;
}
internal void StartOperationWrapperConnect (MultipleConnectAsync args)
{
SetLastOperation (SocketAsyncOperation.Connect);
//m_MultipleConnect = args;
}
internal void FinishConnectByNameSyncFailure (Exception exception, int bytesTransferred, SocketFlags flags)
{
throw new NotImplementedException ();
}
internal void FinishOperationAsyncFailure (Exception exception, int bytesTransferred, SocketFlags flags)
{
throw new NotImplementedException ();
}
internal void FinishWrapperConnectSuccess (Socket connectSocket, int bytesTransferred, SocketFlags flags)
{
SetResults(SocketError.Success, bytesTransferred, flags);
current_socket = connectSocket;
Complete ();
OnCompleted (this);
}
internal void SetResults (SocketError socketError, int bytesTransferred, SocketFlags flags)
{
SocketError = socketError;
BytesTransferred = bytesTransferred;
SocketFlags = flags;
}
}
}

View File

@@ -0,0 +1,40 @@
//
// SocketReceiveFromResult.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.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.
//
#if NETSTANDARD
namespace System.Net.Sockets
{
public struct SocketReceiveFromResult
{
public int ReceivedBytes;
public EndPoint RemoteEndPoint;
}
}
#endif

View File

@@ -0,0 +1,42 @@
//
// SocketReceiveMessageFromResult.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.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.
//
#if NETSTANDARD
namespace System.Net.Sockets
{
public struct SocketReceiveMessageFromResult
{
public int ReceivedBytes;
public SocketFlags SocketFlags;
public EndPoint RemoteEndPoint;
public IPPacketInformation PacketInformation;
}
}
#endif

View File

@@ -0,0 +1,254 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if NETSTANDARD
using System.Collections.Generic;
using System.Threading.Tasks;
namespace System.Net.Sockets
{
public static class SocketTaskExtensions
{
public static Task<Socket> AcceptAsync(this Socket socket)
{
return Task<Socket>.Factory.FromAsync(
(callback, state) => ((Socket)state).BeginAccept(callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndAccept(asyncResult),
state: socket);
}
public static Task<Socket> AcceptAsync(this Socket socket, Socket acceptSocket)
{
const int ReceiveSize = 0;
return Task<Socket>.Factory.FromAsync(
(socketForAccept, receiveSize, callback, state) => ((Socket)state).BeginAccept(socketForAccept, receiveSize, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndAccept(asyncResult),
acceptSocket,
ReceiveSize,
state: socket);
}
public static Task ConnectAsync(this Socket socket, EndPoint remoteEP)
{
return Task.Factory.FromAsync(
(targetEndPoint, callback, state) => ((Socket)state).BeginConnect(targetEndPoint, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndConnect(asyncResult),
remoteEP,
state: socket);
}
public static Task ConnectAsync(this Socket socket, IPAddress address, int port)
{
return Task.Factory.FromAsync(
(targetAddress, targetPort, callback, state) => ((Socket)state).BeginConnect(targetAddress, targetPort, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndConnect(asyncResult),
address,
port,
state: socket);
}
public static Task ConnectAsync(this Socket socket, IPAddress[] addresses, int port)
{
return Task.Factory.FromAsync(
(targetAddresses, targetPort, callback, state) => ((Socket)state).BeginConnect(targetAddresses, targetPort, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndConnect(asyncResult),
addresses,
port,
state: socket);
}
public static Task ConnectAsync(this Socket socket, string host, int port)
{
return Task.Factory.FromAsync(
(targetHost, targetPort, callback, state) => ((Socket)state).BeginConnect(targetHost, targetPort, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndConnect(asyncResult),
host,
port,
state: socket);
}
public static Task<int> ReceiveAsync(this Socket socket, ArraySegment<byte> buffer, SocketFlags socketFlags)
{
return Task<int>.Factory.FromAsync(
(targetBuffer, flags, callback, state) => ((Socket)state).BeginReceive(
targetBuffer.Array,
targetBuffer.Offset,
targetBuffer.Count,
flags,
callback,
state),
asyncResult => ((Socket)asyncResult.AsyncState).EndReceive(asyncResult),
buffer,
socketFlags,
state: socket);
}
public static Task<int> ReceiveAsync(
this Socket socket,
IList<ArraySegment<byte>> buffers,
SocketFlags socketFlags)
{
return Task<int>.Factory.FromAsync(
(targetBuffers, flags, callback, state) => ((Socket)state).BeginReceive(targetBuffers, flags, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndReceive(asyncResult),
buffers,
socketFlags,
state: socket);
}
public static Task<SocketReceiveFromResult> ReceiveFromAsync(
this Socket socket,
ArraySegment<byte> buffer,
SocketFlags socketFlags,
EndPoint remoteEndPoint)
{
object[] packedArguments = new object[] { socket, remoteEndPoint };
return Task<SocketReceiveFromResult>.Factory.FromAsync(
(targetBuffer, flags, callback, state) =>
{
var arguments = (object[])state;
var s = (Socket)arguments[0];
var e = (EndPoint)arguments[1];
IAsyncResult result = s.BeginReceiveFrom(
targetBuffer.Array,
targetBuffer.Offset,
targetBuffer.Count,
flags,
ref e,
callback,
state);
arguments[1] = e;
return result;
},
asyncResult =>
{
var arguments = (object[])asyncResult.AsyncState;
var s = (Socket)arguments[0];
var e = (EndPoint)arguments[1];
int bytesReceived = s.EndReceiveFrom(asyncResult, ref e);
return new SocketReceiveFromResult()
{
ReceivedBytes = bytesReceived,
RemoteEndPoint = e
};
},
buffer,
socketFlags,
state: packedArguments);
}
public static Task<SocketReceiveMessageFromResult> ReceiveMessageFromAsync(
this Socket socket,
ArraySegment<byte> buffer,
SocketFlags socketFlags,
EndPoint remoteEndPoint)
{
object[] packedArguments = new object[] { socket, socketFlags, remoteEndPoint };
return Task<SocketReceiveMessageFromResult>.Factory.FromAsync(
(targetBuffer, callback, state) =>
{
var arguments = (object[])state;
var s = (Socket)arguments[0];
var f = (SocketFlags)arguments[1];
var e = (EndPoint)arguments[2];
IAsyncResult result = s.BeginReceiveMessageFrom(
targetBuffer.Array,
targetBuffer.Offset,
targetBuffer.Count,
f,
ref e,
callback,
state);
arguments[2] = e;
return result;
},
asyncResult =>
{
var arguments = (object[])asyncResult.AsyncState;
var s = (Socket)arguments[0];
var f = (SocketFlags)arguments[1];
var e = (EndPoint)arguments[2];
IPPacketInformation ipPacket;
int bytesReceived = s.EndReceiveMessageFrom(
asyncResult,
ref f,
ref e,
out ipPacket);
return new SocketReceiveMessageFromResult()
{
PacketInformation = ipPacket,
ReceivedBytes = bytesReceived,
RemoteEndPoint = e,
SocketFlags = f
};
},
buffer,
state: packedArguments);
}
public static Task<int> SendAsync(this Socket socket, ArraySegment<byte> buffer, SocketFlags socketFlags)
{
return Task<int>.Factory.FromAsync(
(targetBuffer, flags, callback, state) => ((Socket)state).BeginSend(
targetBuffer.Array,
targetBuffer.Offset,
targetBuffer.Count,
flags,
callback,
state),
asyncResult => ((Socket)asyncResult.AsyncState).EndSend(asyncResult),
buffer,
socketFlags,
state: socket);
}
public static Task<int> SendAsync(
this Socket socket,
IList<ArraySegment<byte>> buffers,
SocketFlags socketFlags)
{
return Task<int>.Factory.FromAsync(
(targetBuffers, flags, callback, state) => ((Socket)state).BeginSend(targetBuffers, flags, callback, state),
asyncResult => ((Socket)asyncResult.AsyncState).EndSend(asyncResult),
buffers,
socketFlags,
state: socket);
}
public static Task<int> SendToAsync(
this Socket socket,
ArraySegment<byte> buffer,
SocketFlags socketFlags,
EndPoint remoteEP)
{
return Task<int>.Factory.FromAsync(
(targetBuffer, flags, endPoint, callback, state) => ((Socket)state).BeginSendTo(
targetBuffer.Array,
targetBuffer.Offset,
targetBuffer.Count,
flags,
endPoint,
callback,
state),
asyncResult => ((Socket)asyncResult.AsyncState).EndSendTo(asyncResult),
buffer,
socketFlags,
remoteEP,
state: socket);
}
}
}
#endif

View File

@@ -0,0 +1,191 @@
//
// System.Net.Sockets.TcpClient.cs
//
// Author:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.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;
using System.Net;
using System.Threading.Tasks;
namespace System.Net.Sockets
{
public class TcpClient : IDisposable
{
const string EXCEPTION_MESSAGE = "System.Net.Sockets.TcpClient is not supported on the current platform.";
public TcpClient ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpClient (AddressFamily family)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpClient (IPEndPoint localEP)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpClient (string hostname, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
protected bool Active {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public Socket Client {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int Available {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool Connected {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool ExclusiveAddressUse {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public LingerOption LingerState {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool NoDelay {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int ReceiveBufferSize {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int ReceiveTimeout {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int SendBufferSize {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int SendTimeout {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public void Close ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (IPEndPoint remoteEP)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (IPAddress address, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (string hostname, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (IPAddress[] ipAddresses, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void EndConnect (IAsyncResult asyncResult)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginConnect (IPAddress address, int port, AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginConnect (IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginConnect (string host, int port, AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Dispose ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
protected virtual void Dispose (bool disposing)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
~TcpClient ()
{
}
public NetworkStream GetStream()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task ConnectAsync (IPAddress address, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task ConnectAsync (IPAddress[] addresses, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task ConnectAsync (string host, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
}
}

View File

@@ -200,7 +200,29 @@ namespace System.Net.Sockets
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;
}
/// <summary>
/// Destructor - stops the listener listening
/// </summary>

View File

@@ -0,0 +1,135 @@
//
// System.Net.Sockets.TcpListener.cs
//
// Author:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.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;
using System.Net;
using System.Threading.Tasks;
namespace System.Net.Sockets
{
public class TcpListener
{
const string EXCEPTION_MESSAGE = "System.Net.Sockets.TcpListener is not supported on the current platform.";
public TcpListener (int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpListener (IPEndPoint localEP)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpListener (IPAddress localaddr, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
protected bool Active {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public EndPoint LocalEndpoint {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public Socket Server {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool ExclusiveAddressUse {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public Socket AcceptSocket ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpClient AcceptTcpClient ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
~TcpListener ()
{
}
public bool Pending ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Start ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Start (int backlog)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginAcceptSocket (AsyncCallback callback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginAcceptTcpClient (AsyncCallback callback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Socket EndAcceptSocket (IAsyncResult asyncResult)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public TcpClient EndAcceptTcpClient (IAsyncResult asyncResult)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Stop ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task<Socket> AcceptSocketAsync ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task<TcpClient> AcceptTcpClientAsync ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
}
}

View File

@@ -125,6 +125,14 @@ namespace System.Net.Sockets
socket.Bind (localEP);
}
public void AllowNatTraversal (bool allowed)
{
if (allowed)
socket.SetIPProtectionLevel (IPProtectionLevel.Unrestricted);
else
socket.SetIPProtectionLevel (IPProtectionLevel.EdgeRestricted);
}
public void Close ()
{
Dispose ();

View File

@@ -0,0 +1,241 @@
//
// System.Net.Sockets.UdpClient.cs
//
// Author:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.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;
using System.Threading.Tasks;
namespace System.Net.Sockets
{
public class UdpClient : IDisposable
{
const string EXCEPTION_MESSAGE = "System.Net.Sockets.UdpClient is not supported on the current platform.";
public UdpClient ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public UdpClient(AddressFamily family)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public UdpClient (int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public UdpClient (IPEndPoint localEP)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public UdpClient (int port, AddressFamily family)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public UdpClient (string hostname, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Close ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (IPEndPoint endPoint)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (IPAddress addr, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void Connect (string hostname, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void DropMulticastGroup (IPAddress multicastAddr)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void DropMulticastGroup (IPAddress multicastAddr, int ifindex)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void JoinMulticastGroup (IPAddress multicastAddr)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void JoinMulticastGroup (int ifindex, IPAddress multicastAddr)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void JoinMulticastGroup (IPAddress multicastAddr, int timeToLive)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public void JoinMulticastGroup (IPAddress multicastAddr, IPAddress localAddress)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public byte [] Receive (ref IPEndPoint remoteEP)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public int Send (byte [] dgram, int bytes)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public int Send (byte [] dgram, int bytes, IPEndPoint endPoint)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public int Send (byte [] dgram, int bytes, string hostname, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginSend (byte[] datagram, int bytes, AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginSend (byte[] datagram, int bytes, IPEndPoint endPoint, AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginSend (byte[] datagram, int bytes, string hostname, int port, AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public int EndSend (IAsyncResult asyncResult)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public IAsyncResult BeginReceive (AsyncCallback requestCallback, object state)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public byte[] EndReceive (IAsyncResult asyncResult, ref IPEndPoint remoteEP)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
protected bool Active {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public Socket Client {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public int Available {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool DontFragment {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool EnableBroadcast {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool ExclusiveAddressUse {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public bool MulticastLoopback {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public short Ttl {
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
public void Dispose ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
protected virtual void Dispose (bool disposing)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
~UdpClient ()
{
}
public Task<UdpReceiveResult> ReceiveAsync ()
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task<int> SendAsync (byte[] datagram, int bytes)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task<int> SendAsync (byte[] datagram, int bytes, IPEndPoint endPoint)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
public Task<int> SendAsync (byte[] datagram, int bytes, string hostname, int port)
{
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
}
}