You've already forked linux-packaging-mono
Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
@ -1,70 +0,0 @@
|
||||
// AddressFamily.cs
|
||||
//
|
||||
// This code was automatically generated from
|
||||
// ECMA CLI XML Library Specification.
|
||||
// Generator: libgen.xsl [1.0; (C) Sergey Chaban (serge@wildwestsoftware.com)]
|
||||
// Created: Wed, 5 Sep 2001 06:31:59 UTC
|
||||
// Source file: AllTypes.xml
|
||||
// URL: http://msdn.microsoft.com/net/ecma/AllTypes.xml
|
||||
//
|
||||
// (C) 2001 Ximian, Inc. http://www.ximian.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 AddressFamily {
|
||||
Unknown = -1,
|
||||
Unspecified = 0,
|
||||
Unix = 1,
|
||||
InterNetwork = 2,
|
||||
ImpLink = 3,
|
||||
Pup = 4,
|
||||
Chaos = 5,
|
||||
NS = 6,
|
||||
Ipx = 6,
|
||||
Iso = 7,
|
||||
Osi = 7,
|
||||
Ecma = 8,
|
||||
DataKit = 9,
|
||||
Ccitt = 10,
|
||||
Sna = 11,
|
||||
DecNet = 12,
|
||||
DataLink = 13,
|
||||
Lat = 14,
|
||||
HyperChannel = 15,
|
||||
AppleTalk = 16,
|
||||
NetBios = 17,
|
||||
VoiceView = 18,
|
||||
FireFox = 19,
|
||||
Banyan = 21,
|
||||
Atm = 22,
|
||||
InterNetworkV6 = 23,
|
||||
Cluster = 24,
|
||||
Ieee12844 = 25,
|
||||
Irda = 26,
|
||||
NetworkDesigners = 28,
|
||||
Max = 29,
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.IOControlCode.cs
|
||||
//
|
||||
// Author:
|
||||
// Dick Porter (dick@ximian.com)
|
||||
//
|
||||
// (C) Copyright 2006 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 IOControlCode: long
|
||||
{
|
||||
AbsorbRouterAlert = 0x98000005,
|
||||
AddMulticastGroupOnInterface = 0x9800000A,
|
||||
AddressListChange = 0x28000017,
|
||||
AddressListQuery = 0x48000016,
|
||||
AddressListSort = 0xC8000019,
|
||||
AssociateHandle = 0x88000001,
|
||||
AsyncIO = 0x8004667D,
|
||||
BindToInterface = 0x98000008,
|
||||
DataToRead = 0x4004667F,
|
||||
DeleteMulticastGroupFromInterface = 0x9800000B,
|
||||
EnableCircularQueuing = 0x28000002,
|
||||
Flush = 0x28000004,
|
||||
GetBroadcastAddress = 0x48000005,
|
||||
GetExtensionFunctionPointer = 0xC8000006,
|
||||
GetGroupQos = 0xC8000008,
|
||||
GetQos = 0xC8000007,
|
||||
KeepAliveValues = 0x98000004,
|
||||
LimitBroadcasts = 0x98000007,
|
||||
MulticastInterface = 0x98000009,
|
||||
MulticastScope = 0x8800000A,
|
||||
MultipointLoopback = 0x88000009,
|
||||
NamespaceChange = 0x88000019,
|
||||
NonBlockingIO = 0x8004667E,
|
||||
OobDataRead = 0x40047307,
|
||||
QueryTargetPnpHandle = 0x48000018,
|
||||
ReceiveAll = 0x98000001,
|
||||
ReceiveAllIgmpMulticast = 0x98000003,
|
||||
ReceiveAllMulticast = 0x98000002,
|
||||
RoutingInterfaceChange = 0x88000015,
|
||||
RoutingInterfaceQuery = 0xC8000014,
|
||||
SetGroupQos = 0x8800000C,
|
||||
SetQos = 0x8800000B,
|
||||
TranslateHandle = 0xC800000D,
|
||||
UnicastInterface = 0x98000006,
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.IPPacketInformation.cs
|
||||
//
|
||||
// Author:
|
||||
// Dick Porter (dick@ximian.com)
|
||||
//
|
||||
// Copyright (C) 2007 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;
|
||||
using System.Net;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public struct IPPacketInformation
|
||||
{
|
||||
IPAddress address;
|
||||
int iface;
|
||||
|
||||
internal IPPacketInformation (IPAddress address, int iface)
|
||||
{
|
||||
this.address = address;
|
||||
this.iface = iface;
|
||||
}
|
||||
|
||||
public IPAddress Address
|
||||
{
|
||||
get {
|
||||
return(address);
|
||||
}
|
||||
}
|
||||
|
||||
public int Interface
|
||||
{
|
||||
get {
|
||||
return(iface);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals (object comparand)
|
||||
{
|
||||
if (!(comparand is IPPacketInformation)) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
IPPacketInformation packet = (IPPacketInformation)comparand;
|
||||
|
||||
if (packet.iface != iface) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(packet.address.Equals (address));
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
/* FIXME: see if we can work out the MS algorithm */
|
||||
return(address.GetHashCode () + iface);
|
||||
}
|
||||
|
||||
public static bool operator== (IPPacketInformation p1,
|
||||
IPPacketInformation p2)
|
||||
{
|
||||
return(p1.Equals (p2));
|
||||
}
|
||||
|
||||
public static bool operator!= (IPPacketInformation p1,
|
||||
IPPacketInformation p2)
|
||||
{
|
||||
return(!p1.Equals (p2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.MulticastOption.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
// <remarks>
|
||||
// Encapsulates a multicast option
|
||||
// </remarks>
|
||||
public class IPv6MulticastOption
|
||||
{
|
||||
// Don't change the names of these fields without also
|
||||
// changing socket-io.c in the runtime
|
||||
private IPAddress group;
|
||||
private long ifIndex;
|
||||
|
||||
public IPv6MulticastOption (IPAddress group)
|
||||
: this (group, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public IPv6MulticastOption (IPAddress group, long ifindex)
|
||||
{
|
||||
if (group == null)
|
||||
throw new ArgumentNullException ("group");
|
||||
if (ifindex < 0 || ifindex > 0xffffffff)
|
||||
throw new ArgumentOutOfRangeException ("ifindex");
|
||||
|
||||
this.group = group;
|
||||
this.ifIndex = ifindex;
|
||||
}
|
||||
|
||||
public IPAddress Group
|
||||
{
|
||||
get { return group; }
|
||||
set {
|
||||
if (value == null)
|
||||
throw new ArgumentNullException ("value");
|
||||
group = value;
|
||||
}
|
||||
}
|
||||
|
||||
public long InterfaceIndex
|
||||
{
|
||||
get { return ifIndex; }
|
||||
set {
|
||||
if (value < 0 || value > 0xffffffff)
|
||||
throw new ArgumentOutOfRangeException ("value");
|
||||
ifIndex = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.LingerOption.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
//
|
||||
// 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
|
||||
{
|
||||
// <remarks>
|
||||
// Encapsulates a linger option.
|
||||
// </remarks>
|
||||
public class LingerOption
|
||||
{
|
||||
// Don't change the names of these fields without also
|
||||
// changing socket-io.c in the runtime
|
||||
private bool enabled;
|
||||
private int seconds;
|
||||
|
||||
public LingerOption (bool enable, int seconds)
|
||||
{
|
||||
enabled = enable;
|
||||
this.seconds = seconds;
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get { return enabled; }
|
||||
set { enabled = value; }
|
||||
}
|
||||
|
||||
public int LingerTime
|
||||
{
|
||||
get { return seconds; }
|
||||
set { seconds = value; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.MulticastOption.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
// <remarks>
|
||||
// Encapsulates a multicast option
|
||||
// </remarks>
|
||||
public class MulticastOption
|
||||
{
|
||||
// Don't change the names of these fields without also
|
||||
// changing socket-io.c in the runtime
|
||||
private IPAddress group;
|
||||
private IPAddress local;
|
||||
int iface_index;
|
||||
|
||||
public MulticastOption (IPAddress group)
|
||||
: this (group, IPAddress.Any)
|
||||
{
|
||||
}
|
||||
|
||||
public MulticastOption (IPAddress group, int interfaceIndex)
|
||||
{
|
||||
if (group == null)
|
||||
throw new ArgumentNullException ("group");
|
||||
if (interfaceIndex < 0 || interfaceIndex > 0xffffff)
|
||||
throw new ArgumentOutOfRangeException ("interfaceIndex");
|
||||
|
||||
this.group = group;
|
||||
this.iface_index = interfaceIndex;
|
||||
}
|
||||
|
||||
public MulticastOption (IPAddress group, IPAddress mcint)
|
||||
{
|
||||
if (group == null)
|
||||
throw new ArgumentNullException ("group");
|
||||
if (mcint == null)
|
||||
throw new ArgumentNullException ("mcint");
|
||||
|
||||
this.group = group;
|
||||
this.local = mcint;
|
||||
}
|
||||
|
||||
public IPAddress Group {
|
||||
get { return group; }
|
||||
set { group = value; }
|
||||
}
|
||||
|
||||
public IPAddress LocalAddress {
|
||||
get { return local; }
|
||||
set {
|
||||
local = value;
|
||||
iface_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int InterfaceIndex {
|
||||
get { return iface_index; }
|
||||
set {
|
||||
if (value < 0 || value > 0xffffff)
|
||||
throw new ArgumentOutOfRangeException ("value");
|
||||
iface_index = value;
|
||||
local = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,430 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.NetworkStream.cs
|
||||
//
|
||||
// Author:
|
||||
// Miguel de Icaza (miguel@ximian.com)
|
||||
// Sridhar Kulkarni <sridharkulkarni@gmail.com>
|
||||
//
|
||||
// (C) 2002 Ximian, Inc. http://www.ximian.com
|
||||
// Copyright (C) 2002-2006 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.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
#if !NET_2_1 || MOBILE
|
||||
using System.Timers;
|
||||
using System.Threading;
|
||||
#endif
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
public class NetworkStream : Stream, IDisposable {
|
||||
FileAccess access;
|
||||
Socket socket;
|
||||
bool owns_socket;
|
||||
bool readable, writeable;
|
||||
bool disposed = false;
|
||||
|
||||
public NetworkStream (Socket socket)
|
||||
: this (socket, FileAccess.ReadWrite, false)
|
||||
{
|
||||
}
|
||||
|
||||
public NetworkStream (Socket socket, bool ownsSocket)
|
||||
: this (socket, FileAccess.ReadWrite, ownsSocket)
|
||||
{
|
||||
}
|
||||
|
||||
public NetworkStream (Socket socket, FileAccess access)
|
||||
: this (socket, access, false)
|
||||
{
|
||||
}
|
||||
|
||||
public NetworkStream (Socket socket, FileAccess access, bool ownsSocket)
|
||||
{
|
||||
if (socket == null)
|
||||
throw new ArgumentNullException ("socket is null");
|
||||
if (socket.SocketType != SocketType.Stream)
|
||||
throw new ArgumentException ("Socket is not of type Stream", "socket");
|
||||
if (!socket.Connected)
|
||||
throw new IOException ("Not connected");
|
||||
if (!socket.Blocking)
|
||||
throw new IOException ("Operation not allowed on a non-blocking socket.");
|
||||
|
||||
this.socket = socket;
|
||||
this.owns_socket = ownsSocket;
|
||||
this.access = access;
|
||||
|
||||
readable = CanRead;
|
||||
writeable = CanWrite;
|
||||
}
|
||||
|
||||
public override bool CanRead {
|
||||
get {
|
||||
return access == FileAccess.ReadWrite || access == FileAccess.Read;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek {
|
||||
get {
|
||||
// network sockets cant seek.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanTimeout
|
||||
{
|
||||
get {
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite {
|
||||
get {
|
||||
return access == FileAccess.ReadWrite || access == FileAccess.Write;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool DataAvailable {
|
||||
get {
|
||||
CheckDisposed ();
|
||||
return socket.Available > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length {
|
||||
get {
|
||||
// Network sockets always throw an exception
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position {
|
||||
get {
|
||||
// Network sockets always throw an exception
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
set {
|
||||
// Network sockets always throw an exception
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
protected bool Readable {
|
||||
get {
|
||||
return readable;
|
||||
}
|
||||
|
||||
set {
|
||||
readable = value;
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET_2_1 || MOBILE
|
||||
public override int ReadTimeout
|
||||
{
|
||||
get {
|
||||
int r = socket.ReceiveTimeout;
|
||||
return (r <= 0) ? Timeout.Infinite : r;
|
||||
}
|
||||
set {
|
||||
if (value <= 0 && value != Timeout.Infinite) {
|
||||
throw new ArgumentOutOfRangeException ("value", "The value specified is less than or equal to zero and is not Infinite.");
|
||||
}
|
||||
|
||||
socket.ReceiveTimeout = value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected Socket Socket {
|
||||
get {
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
|
||||
protected bool Writeable {
|
||||
get {
|
||||
return writeable;
|
||||
}
|
||||
|
||||
set {
|
||||
writeable = value;
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET_2_1 || MOBILE
|
||||
public override int WriteTimeout
|
||||
{
|
||||
get {
|
||||
int r = socket.SendTimeout;
|
||||
return (r <= 0) ? Timeout.Infinite : r;
|
||||
}
|
||||
set {
|
||||
if (value <= 0 && value != Timeout.Infinite) {
|
||||
throw new ArgumentOutOfRangeException ("value", "The value specified is less than or equal to zero and is not Infinite");
|
||||
}
|
||||
|
||||
socket.SendTimeout = value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public override IAsyncResult BeginRead (byte [] buffer, int offset, int size,
|
||||
AsyncCallback callback, object state)
|
||||
{
|
||||
CheckDisposed ();
|
||||
IAsyncResult retval;
|
||||
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer is null");
|
||||
int len = buffer.Length;
|
||||
if(offset<0 || offset>len) {
|
||||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||||
}
|
||||
if(size<0 || offset+size>len) {
|
||||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||||
}
|
||||
|
||||
Socket s = socket;
|
||||
|
||||
if (s == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
|
||||
try {
|
||||
retval = s.BeginReceive (buffer, offset, size, 0, callback, state);
|
||||
} catch (Exception e) {
|
||||
throw new IOException ("BeginReceive failure", e);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
public override IAsyncResult BeginWrite (byte [] buffer, int offset, int size,
|
||||
AsyncCallback callback, object state)
|
||||
{
|
||||
CheckDisposed ();
|
||||
IAsyncResult retval;
|
||||
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer is null");
|
||||
|
||||
int len = buffer.Length;
|
||||
if(offset<0 || offset>len) {
|
||||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||||
}
|
||||
if(size<0 || offset+size>len) {
|
||||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||||
}
|
||||
|
||||
Socket s = socket;
|
||||
|
||||
if (s == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
|
||||
try {
|
||||
retval = s.BeginSend (buffer, offset, size, 0, callback, state);
|
||||
} catch (Exception e) {
|
||||
throw new IOException ("BeginWrite failure", e);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
~NetworkStream ()
|
||||
{
|
||||
Dispose (false);
|
||||
}
|
||||
|
||||
|
||||
#if !NET_2_1 || MOBILE
|
||||
public void Close (int timeout)
|
||||
{
|
||||
if (timeout < -1) {
|
||||
throw new ArgumentOutOfRangeException ("timeout", "timeout is less than -1");
|
||||
}
|
||||
|
||||
System.Timers.Timer close_timer = new System.Timers.Timer ();
|
||||
close_timer.Elapsed += new ElapsedEventHandler (OnTimeoutClose);
|
||||
/* NB timeout is in milliseconds here, cf
|
||||
* seconds in Socket.Close(int)
|
||||
*/
|
||||
close_timer.Interval = timeout;
|
||||
close_timer.AutoReset = false;
|
||||
close_timer.Enabled = true;
|
||||
}
|
||||
|
||||
private void OnTimeoutClose (object source, ElapsedEventArgs e)
|
||||
{
|
||||
this.Close ();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
disposed = true;
|
||||
|
||||
if (owns_socket) {
|
||||
Socket s = socket;
|
||||
if (s != null)
|
||||
s.Close ();
|
||||
}
|
||||
socket = null;
|
||||
access = 0;
|
||||
|
||||
if (disposing)
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
public override int EndRead (IAsyncResult ar)
|
||||
{
|
||||
CheckDisposed ();
|
||||
int res;
|
||||
|
||||
if (ar == null)
|
||||
throw new ArgumentNullException ("async result is null");
|
||||
|
||||
Socket s = socket;
|
||||
|
||||
if (s == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
|
||||
try {
|
||||
res = s.EndReceive (ar);
|
||||
} catch (Exception e) {
|
||||
throw new IOException ("EndRead failure", e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public override void EndWrite (IAsyncResult ar)
|
||||
{
|
||||
CheckDisposed ();
|
||||
if (ar == null)
|
||||
throw new ArgumentNullException ("async result is null");
|
||||
|
||||
Socket s = socket;
|
||||
|
||||
if (s == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
|
||||
try {
|
||||
s.EndSend (ar);
|
||||
} catch (Exception e) {
|
||||
throw new IOException ("EndWrite failure", e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush ()
|
||||
{
|
||||
// network streams are non-buffered, this is a no-op
|
||||
}
|
||||
|
||||
public override int Read ([In,Out] byte [] buffer, int offset, int size)
|
||||
{
|
||||
CheckDisposed ();
|
||||
int res;
|
||||
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer is null");
|
||||
if(offset<0 || offset>buffer.Length) {
|
||||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||||
}
|
||||
if(size < 0 || offset+size>buffer.Length) {
|
||||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||||
}
|
||||
|
||||
Socket s = socket;
|
||||
|
||||
if (s == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
|
||||
try {
|
||||
res = s.Receive (buffer, offset, size, 0);
|
||||
} catch (Exception e) {
|
||||
throw new IOException ("Read failure", e);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public override long Seek (long offset, SeekOrigin origin)
|
||||
{
|
||||
// NetworkStream objects do not support seeking.
|
||||
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override void SetLength (long value)
|
||||
{
|
||||
// NetworkStream objects do not support SetLength
|
||||
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public override void Write (byte [] buffer, int offset, int size)
|
||||
{
|
||||
CheckDisposed ();
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException ("buffer");
|
||||
|
||||
if (offset < 0 || offset > buffer.Length)
|
||||
throw new ArgumentOutOfRangeException("offset exceeds the size of buffer");
|
||||
|
||||
if (size < 0 || size > buffer.Length - offset)
|
||||
throw new ArgumentOutOfRangeException("offset+size exceeds the size of buffer");
|
||||
|
||||
Socket s = socket;
|
||||
|
||||
if (s == null) {
|
||||
throw new IOException("Connection closed");
|
||||
}
|
||||
|
||||
try {
|
||||
int count = 0;
|
||||
while (size - count > 0) {
|
||||
count += s.Send (buffer, offset + count, size - count, 0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IOException ("Write failure", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckDisposed ()
|
||||
{
|
||||
if (disposed)
|
||||
throw new ObjectDisposedException (GetType().FullName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.ProtocolFamily.cs
|
||||
//
|
||||
// Author:
|
||||
// Andrew Sutton
|
||||
//
|
||||
// (C) Andrew Sutton
|
||||
//
|
||||
|
||||
//
|
||||
// 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 ProtocolFamily
|
||||
{
|
||||
Unknown = -1,
|
||||
Unspecified = 0,
|
||||
Unix,
|
||||
InterNetwork,
|
||||
ImpLink,
|
||||
Pup,
|
||||
Chaos,
|
||||
Ipx,
|
||||
Iso,
|
||||
Ecma,
|
||||
DataKit,
|
||||
Ccitt,
|
||||
Sna,
|
||||
DecNet,
|
||||
DataLink,
|
||||
Lat,
|
||||
HyperChannel,
|
||||
AppleTalk,
|
||||
NetBios,
|
||||
VoiceView,
|
||||
FireFox,
|
||||
Banyan = 0x15,
|
||||
Atm,
|
||||
InterNetworkV6,
|
||||
Cluster,
|
||||
Ieee12844,
|
||||
Irda,
|
||||
NetworkDesigners = 0x1c,
|
||||
Max,
|
||||
|
||||
NS = Ipx,
|
||||
Osi = Iso,
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
// ProtocolType.cs
|
||||
//
|
||||
// This code was automatically generated from
|
||||
// ECMA CLI XML Library Specification.
|
||||
// Generator: libgen.xsl [1.0; (C) Sergey Chaban (serge@wildwestsoftware.com)]
|
||||
// Created: Wed, 5 Sep 2001 06:32:24 UTC
|
||||
// Source file: AllTypes.xml
|
||||
// URL: http://msdn.microsoft.com/net/ecma/AllTypes.xml
|
||||
//
|
||||
// (C) 2001 Ximian, Inc. http://www.ximian.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 {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public enum ProtocolType {
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
IP = 0,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Icmp = 1,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Igmp = 2,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Ggp = 3,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Tcp = 6,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Pup = 12,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Udp = 17,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Idp = 22,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
IPv6 = 41,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
ND = 77,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Raw = 255,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Unspecified = 0,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Ipx = 1000,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Spx = 1256,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
SpxII = 1257,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
Unknown = -1,
|
||||
|
||||
IPv4 = 4,
|
||||
IPv6RoutingHeader = 43,
|
||||
IPv6FragmentHeader = 44,
|
||||
IPSecEncapsulatingSecurityPayload = 50,
|
||||
IPSecAuthenticationHeader = 51,
|
||||
IcmpV6 = 58,
|
||||
IPv6NoNextHeader = 59,
|
||||
IPv6DestinationOptions = 60,
|
||||
IPv6HopByHopOptions = 0,
|
||||
} // ProtocolType
|
||||
|
||||
} // System.Net.Sockets
|
@ -37,6 +37,10 @@ namespace System.Net.Sockets {
|
||||
int error = 0;
|
||||
|
||||
Socket.Blocking_internal (handle, false, out error);
|
||||
#if MOBILE_STATIC
|
||||
/* It's only for platforms that do not have working syscall abort mechanism, like WatchOS and TvOS */
|
||||
Socket.Shutdown_internal (handle, SocketShutdown.Both, out error);
|
||||
#endif
|
||||
|
||||
if (blocking_threads != null) {
|
||||
int abort_attempts = 0;
|
||||
|
@ -1,54 +0,0 @@
|
||||
// SelectMode.cs
|
||||
//
|
||||
// This code was automatically generated from
|
||||
// ECMA CLI XML Library Specification.
|
||||
// Generator: libgen.xsl [1.0; (C) Sergey Chaban (serge@wildwestsoftware.com)]
|
||||
// Created: Wed, 5 Sep 2001 06:32:30 UTC
|
||||
// Source file: AllTypes.xml
|
||||
// URL: http://msdn.microsoft.com/net/ecma/AllTypes.xml
|
||||
//
|
||||
// (C) 2001 Ximian, Inc. http://www.ximian.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 {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
public enum SelectMode {
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
SelectRead = 0,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
SelectWrite = 1,
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
SelectError = 2,
|
||||
} // SelectMode
|
||||
|
||||
} // System.Net.Sockets
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
8d48b675ae8cf9ed8a03cab67569bb1c49d9033d
|
@ -1,32 +0,0 @@
|
||||
// System.Net.Sockets.SocketAsyncCallback.cs
|
||||
//
|
||||
// Authors:
|
||||
// Ludovic Henry <ludovic@xamarin.com>
|
||||
//
|
||||
// Copyright (C) 2015 Xamarin, Inc. (https://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.
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
internal delegate void SocketAsyncCallback (SocketAsyncResult sar);
|
||||
}
|
@ -39,18 +39,29 @@ namespace System.Net.Sockets
|
||||
public class SocketAsyncEventArgs : EventArgs, IDisposable
|
||||
{
|
||||
bool disposed;
|
||||
int in_progress;
|
||||
internal SocketAsyncWorker Worker;
|
||||
EndPoint remote_ep;
|
||||
public Exception ConnectByNameError { get; internal set; }
|
||||
|
||||
public event EventHandler<SocketAsyncEventArgs> Completed;
|
||||
internal volatile int in_progress;
|
||||
internal EndPoint remote_ep;
|
||||
internal Socket current_socket;
|
||||
|
||||
internal SocketAsyncResult socket_async_result = new SocketAsyncResult ();
|
||||
|
||||
public Exception ConnectByNameError {
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public Socket AcceptSocket {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public byte[] Buffer {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
IList <ArraySegment <byte>> _bufferList;
|
||||
|
||||
public Socket AcceptSocket { get; set; }
|
||||
public byte[] Buffer { get; private set; }
|
||||
|
||||
public IList<ArraySegment<byte>> BufferList {
|
||||
get { return _bufferList; }
|
||||
set {
|
||||
@ -60,65 +71,101 @@ namespace System.Net.Sockets
|
||||
}
|
||||
}
|
||||
|
||||
public int BytesTransferred { get; internal set; }
|
||||
public int Count { get; internal set; }
|
||||
public bool DisconnectReuseSocket { get; set; }
|
||||
public SocketAsyncOperation LastOperation { get; private set; }
|
||||
public int Offset { get; private set; }
|
||||
public int BytesTransferred {
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
public bool DisconnectReuseSocket {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public SocketAsyncOperation LastOperation {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int Offset {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public EndPoint RemoteEndPoint {
|
||||
get { return remote_ep; }
|
||||
set { remote_ep = value; }
|
||||
}
|
||||
|
||||
#if !NET_2_1
|
||||
public IPPacketInformation ReceiveMessageFromPacketInfo { get; private set; }
|
||||
public SendPacketsElement[] SendPacketsElements { get; set; }
|
||||
public TransmitFileOptions SendPacketsFlags { get; set; }
|
||||
public IPPacketInformation ReceiveMessageFromPacketInfo {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public SendPacketsElement[] SendPacketsElements {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public TransmitFileOptions SendPacketsFlags {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#endif
|
||||
|
||||
[MonoTODO ("unused property")]
|
||||
public int SendPacketsSendSize { get; set; }
|
||||
public SocketError SocketError { get; set; }
|
||||
public SocketFlags SocketFlags { get; set; }
|
||||
public object UserToken { get; set; }
|
||||
internal Socket curSocket;
|
||||
public int SendPacketsSendSize {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public SocketError SocketError {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public SocketFlags SocketFlags {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public object UserToken {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Socket ConnectSocket {
|
||||
get {
|
||||
switch (SocketError) {
|
||||
case SocketError.AccessDenied:
|
||||
return null;
|
||||
default:
|
||||
return curSocket;
|
||||
return current_socket;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal bool PolicyRestricted { get; private set; }
|
||||
internal bool PolicyRestricted {
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
internal SocketAsyncEventArgs (bool policy) :
|
||||
this ()
|
||||
public event EventHandler<SocketAsyncEventArgs> Completed;
|
||||
|
||||
internal SocketAsyncEventArgs (bool policy)
|
||||
: this ()
|
||||
{
|
||||
PolicyRestricted = policy;
|
||||
}
|
||||
|
||||
|
||||
public SocketAsyncEventArgs ()
|
||||
{
|
||||
Worker = new SocketAsyncWorker (this);
|
||||
AcceptSocket = null;
|
||||
Buffer = null;
|
||||
BufferList = null;
|
||||
BytesTransferred = 0;
|
||||
Count = 0;
|
||||
DisconnectReuseSocket = false;
|
||||
LastOperation = SocketAsyncOperation.None;
|
||||
Offset = 0;
|
||||
RemoteEndPoint = null;
|
||||
#if !NET_2_1
|
||||
SendPacketsElements = null;
|
||||
SendPacketsFlags = TransmitFileOptions.UseDefaultWorkerThread;
|
||||
#endif
|
||||
SendPacketsSendSize = -1;
|
||||
SocketError = SocketError.Success;
|
||||
SocketFlags = SocketFlags.None;
|
||||
UserToken = null;
|
||||
}
|
||||
|
||||
~SocketAsyncEventArgs ()
|
||||
@ -130,14 +177,9 @@ namespace System.Net.Sockets
|
||||
{
|
||||
disposed = true;
|
||||
|
||||
if (disposing) {
|
||||
if (disposed || Interlocked.CompareExchange (ref in_progress, 0, 0) != 0)
|
||||
return;
|
||||
if (Worker != null) {
|
||||
Worker.Dispose ();
|
||||
Worker = null;
|
||||
}
|
||||
}
|
||||
if (disposing && in_progress != 0)
|
||||
return;
|
||||
|
||||
AcceptSocket = null;
|
||||
Buffer = null;
|
||||
BufferList = null;
|
||||
@ -146,7 +188,7 @@ namespace System.Net.Sockets
|
||||
#if !NET_2_1
|
||||
SendPacketsElements = null;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
@ -160,9 +202,15 @@ namespace System.Net.Sockets
|
||||
throw new ObjectDisposedException ("System.Net.Sockets.SocketAsyncEventArgs");
|
||||
if (Interlocked.Exchange (ref in_progress, 1) != 0)
|
||||
throw new InvalidOperationException ("Operation already in progress");
|
||||
|
||||
LastOperation = op;
|
||||
}
|
||||
|
||||
internal void Complete ()
|
||||
{
|
||||
OnCompleted (this);
|
||||
}
|
||||
|
||||
protected virtual void OnCompleted (SocketAsyncEventArgs e)
|
||||
{
|
||||
if (e == null)
|
||||
@ -170,20 +218,15 @@ namespace System.Net.Sockets
|
||||
|
||||
EventHandler<SocketAsyncEventArgs> handler = e.Completed;
|
||||
if (handler != null)
|
||||
handler (e.curSocket, e);
|
||||
handler (e.current_socket, e);
|
||||
}
|
||||
|
||||
public void SetBuffer (int offset, int count)
|
||||
{
|
||||
SetBufferInternal (Buffer, offset, count);
|
||||
SetBuffer (Buffer, offset, count);
|
||||
}
|
||||
|
||||
public void SetBuffer (byte[] buffer, int offset, int count)
|
||||
{
|
||||
SetBufferInternal (buffer, offset, count);
|
||||
}
|
||||
|
||||
void SetBufferInternal (byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (buffer != null) {
|
||||
if (BufferList != null)
|
||||
@ -199,145 +242,8 @@ namespace System.Net.Sockets
|
||||
Count = count;
|
||||
Offset = offset;
|
||||
}
|
||||
|
||||
Buffer = buffer;
|
||||
}
|
||||
|
||||
#region Internals
|
||||
internal static AsyncCallback Dispatcher = new AsyncCallback (DispatcherCB);
|
||||
|
||||
static void DispatcherCB (IAsyncResult ares)
|
||||
{
|
||||
SocketAsyncEventArgs args = (SocketAsyncEventArgs) ares.AsyncState;
|
||||
|
||||
if (Interlocked.Exchange (ref args.in_progress, 0) != 1)
|
||||
throw new InvalidOperationException ("No operation in progress");
|
||||
|
||||
/* Notes;
|
||||
* -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
|
||||
* -SendPackets and ReceiveMessageFrom are not implemented yet */
|
||||
switch (args.LastOperation) {
|
||||
case SocketAsyncOperation.Receive:
|
||||
args.ReceiveCallback (ares);
|
||||
break;
|
||||
case SocketAsyncOperation.Send:
|
||||
args.SendCallback (ares);
|
||||
break;
|
||||
case SocketAsyncOperation.ReceiveFrom:
|
||||
args.ReceiveFromCallback (ares);
|
||||
break;
|
||||
case SocketAsyncOperation.SendTo:
|
||||
args.SendToCallback (ares);
|
||||
break;
|
||||
case SocketAsyncOperation.Accept:
|
||||
args.AcceptCallback (ares);
|
||||
break;
|
||||
case SocketAsyncOperation.Disconnect:
|
||||
args.DisconnectCallback (ares);
|
||||
break;
|
||||
case SocketAsyncOperation.Connect:
|
||||
args.ConnectCallback (ares);
|
||||
break;
|
||||
/*
|
||||
case SocketOperation.ReceiveMessageFrom:
|
||||
case SocketOperation.SendPackets:
|
||||
*/
|
||||
default:
|
||||
throw new NotImplementedException (String.Format ("Operation {0} is not implemented", args.LastOperation));
|
||||
}
|
||||
}
|
||||
|
||||
internal void ReceiveCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
BytesTransferred = curSocket.EndReceive (ares);
|
||||
} catch (SocketException se){
|
||||
SocketError = se.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
curSocket.EndConnect (ares);
|
||||
} catch (SocketException se) {
|
||||
SocketError = se.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SendCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
BytesTransferred = curSocket.EndSend (ares);
|
||||
} catch (SocketException se){
|
||||
SocketError = se.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AcceptCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
AcceptSocket = curSocket.EndAccept (ares);
|
||||
} catch (SocketException ex) {
|
||||
SocketError = ex.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
if (AcceptSocket == null)
|
||||
AcceptSocket = new Socket (curSocket.AddressFamily, curSocket.SocketType, curSocket.ProtocolType, null);
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void DisconnectCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
curSocket.EndDisconnect (ares);
|
||||
} catch (SocketException ex) {
|
||||
SocketError = ex.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void ReceiveFromCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
BytesTransferred = curSocket.EndReceiveFrom (ares, ref remote_ep);
|
||||
} catch (SocketException ex) {
|
||||
SocketError = ex.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SendToCallback (IAsyncResult ares)
|
||||
{
|
||||
try {
|
||||
BytesTransferred = curSocket.EndSendTo (ares);
|
||||
} catch (SocketException ex) {
|
||||
SocketError = ex.SocketErrorCode;
|
||||
} catch (ObjectDisposedException) {
|
||||
SocketError = SocketError.OperationAborted;
|
||||
} finally {
|
||||
OnCompleted (this);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -35,19 +35,12 @@ using System.Threading;
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
internal sealed class SocketAsyncResult: IAsyncResult, IThreadPoolWorkItem
|
||||
internal sealed class SocketAsyncResult: IOAsyncResult
|
||||
{
|
||||
/* Same structure in the runtime. Keep this in sync with
|
||||
* MonoSocketAsyncResult in metadata/socket-io.h and
|
||||
* ProcessAsyncReader in System.Diagnostics/Process.cs. */
|
||||
|
||||
public Socket socket;
|
||||
IntPtr handle;
|
||||
object state;
|
||||
AsyncCallback callback; // used from the runtime
|
||||
WaitHandle wait_handle;
|
||||
public SocketOperation operation;
|
||||
|
||||
Exception delayed_exception;
|
||||
Exception DelayedException;
|
||||
|
||||
public EndPoint EndPoint; // Connect,ReceiveFrom,SendTo
|
||||
public byte [] Buffer; // Receive,ReceiveFrom,Send,SendTo
|
||||
@ -59,108 +52,33 @@ namespace System.Net.Sockets
|
||||
public int Port; // Connect
|
||||
public IList<ArraySegment<byte>> Buffers; // Receive, Send
|
||||
public bool ReuseSocket; // Disconnect
|
||||
|
||||
// Return values
|
||||
Socket accept_socket;
|
||||
int total;
|
||||
|
||||
bool completed_synchronously;
|
||||
bool completed;
|
||||
bool is_blocking;
|
||||
internal int error;
|
||||
public SocketOperation operation;
|
||||
AsyncResult async_result;
|
||||
public int EndCalled;
|
||||
|
||||
/* These fields are not in MonoSocketAsyncResult */
|
||||
public SocketAsyncWorker Worker;
|
||||
public int CurrentAddress; // Connect
|
||||
|
||||
public Socket AcceptedSocket;
|
||||
public int Total;
|
||||
|
||||
internal int error;
|
||||
|
||||
public int EndCalled;
|
||||
|
||||
public IntPtr Handle {
|
||||
get { return socket != null ? socket.Handle : IntPtr.Zero; }
|
||||
}
|
||||
|
||||
/* Used by SocketAsyncEventArgs */
|
||||
public SocketAsyncResult ()
|
||||
: base ()
|
||||
{
|
||||
}
|
||||
|
||||
public SocketAsyncResult (Socket socket, object state, AsyncCallback callback, SocketOperation operation)
|
||||
public void Init (Socket socket, AsyncCallback callback, object state, SocketOperation operation)
|
||||
{
|
||||
Init (socket, state, callback, operation, new SocketAsyncWorker (this));
|
||||
}
|
||||
base.Init (callback, state);
|
||||
|
||||
public object AsyncState {
|
||||
get {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
public WaitHandle AsyncWaitHandle {
|
||||
get {
|
||||
lock (this) {
|
||||
if (wait_handle == null)
|
||||
wait_handle = new ManualResetEvent (completed);
|
||||
}
|
||||
|
||||
return wait_handle;
|
||||
}
|
||||
set {
|
||||
wait_handle = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CompletedSynchronously {
|
||||
get {
|
||||
return completed_synchronously;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsCompleted {
|
||||
get {
|
||||
return completed;
|
||||
}
|
||||
set {
|
||||
completed = value;
|
||||
lock (this) {
|
||||
if (wait_handle != null && value)
|
||||
((ManualResetEvent) wait_handle).Set ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Socket Socket {
|
||||
get {
|
||||
return accept_socket;
|
||||
}
|
||||
}
|
||||
|
||||
public int Total {
|
||||
get { return total; }
|
||||
set { total = value; }
|
||||
}
|
||||
|
||||
public SocketError ErrorCode {
|
||||
get {
|
||||
SocketException ex = delayed_exception as SocketException;
|
||||
if (ex != null)
|
||||
return ex.SocketErrorCode;
|
||||
|
||||
if (error != 0)
|
||||
return (SocketError) error;
|
||||
|
||||
return SocketError.Success;
|
||||
}
|
||||
}
|
||||
|
||||
public void Init (Socket socket, object state, AsyncCallback callback, SocketOperation operation, SocketAsyncWorker worker)
|
||||
{
|
||||
this.socket = socket;
|
||||
this.is_blocking = socket != null ? socket.is_blocking : true;
|
||||
this.handle = socket != null ? socket.Handle : IntPtr.Zero;
|
||||
this.state = state;
|
||||
this.callback = callback;
|
||||
this.operation = operation;
|
||||
|
||||
if (wait_handle != null)
|
||||
((ManualResetEvent) wait_handle).Reset ();
|
||||
|
||||
delayed_exception = null;
|
||||
DelayedException = null;
|
||||
|
||||
EndPoint = null;
|
||||
Buffer = null;
|
||||
@ -172,39 +90,41 @@ namespace System.Net.Sockets
|
||||
Port = 0;
|
||||
Buffers = null;
|
||||
ReuseSocket = false;
|
||||
accept_socket = null;
|
||||
total = 0;
|
||||
CurrentAddress = 0;
|
||||
|
||||
AcceptedSocket = null;
|
||||
Total = 0;
|
||||
|
||||
completed_synchronously = false;
|
||||
completed = false;
|
||||
is_blocking = false;
|
||||
error = 0;
|
||||
async_result = null;
|
||||
|
||||
EndCalled = 0;
|
||||
Worker = worker;
|
||||
}
|
||||
|
||||
public void DoMConnectCallback ()
|
||||
public SocketAsyncResult (Socket socket, AsyncCallback callback, object state, SocketOperation operation)
|
||||
: base (callback, state)
|
||||
{
|
||||
if (callback == null)
|
||||
return;
|
||||
ThreadPool.UnsafeQueueUserWorkItem (_ => callback (this), null);
|
||||
this.socket = socket;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Init (null, null, null, 0, Worker);
|
||||
if (wait_handle != null) {
|
||||
wait_handle.Close ();
|
||||
wait_handle = null;
|
||||
public SocketError ErrorCode {
|
||||
get {
|
||||
SocketException ex = DelayedException as SocketException;
|
||||
if (ex != null)
|
||||
return ex.SocketErrorCode;
|
||||
|
||||
if (error != 0)
|
||||
return (SocketError) error;
|
||||
|
||||
return SocketError.Success;
|
||||
}
|
||||
}
|
||||
|
||||
public void CheckIfThrowDelayedException ()
|
||||
{
|
||||
if (delayed_exception != null) {
|
||||
if (DelayedException != null) {
|
||||
socket.is_connected = false;
|
||||
throw delayed_exception;
|
||||
throw DelayedException;
|
||||
}
|
||||
|
||||
if (error != 0) {
|
||||
@ -213,7 +133,7 @@ namespace System.Net.Sockets
|
||||
}
|
||||
}
|
||||
|
||||
void CompleteDisposed (object unused)
|
||||
internal override void CompleteDisposed ()
|
||||
{
|
||||
Complete ();
|
||||
}
|
||||
@ -221,11 +141,16 @@ namespace System.Net.Sockets
|
||||
public void Complete ()
|
||||
{
|
||||
if (operation != SocketOperation.Receive && socket.is_disposed)
|
||||
delayed_exception = new ObjectDisposedException (socket.GetType ().ToString ());
|
||||
DelayedException = new ObjectDisposedException (socket.GetType ().ToString ());
|
||||
|
||||
IsCompleted = true;
|
||||
|
||||
Queue<SocketAsyncWorker> queue = null;
|
||||
AsyncCallback callback = AsyncCallback;
|
||||
if (callback != null) {
|
||||
ThreadPool.UnsafeQueueUserWorkItem (_ => callback (this), null);
|
||||
}
|
||||
|
||||
Queue<KeyValuePair<IntPtr, IOSelectorJob>> queue = null;
|
||||
switch (operation) {
|
||||
case SocketOperation.Receive:
|
||||
case SocketOperation.ReceiveFrom:
|
||||
@ -249,12 +174,12 @@ namespace System.Net.Sockets
|
||||
queue.Dequeue (); /* remove ourselves */
|
||||
if (queue.Count > 0) {
|
||||
if (!socket.is_disposed) {
|
||||
Socket.socket_pool_queue (SocketAsyncWorker.Dispatcher, (queue.Peek ()).result);
|
||||
IOSelector.Add (queue.Peek ().Key, queue.Peek ().Value);
|
||||
} else {
|
||||
/* CompleteAllOnDispose */
|
||||
SocketAsyncWorker [] workers = queue.ToArray ();
|
||||
for (int i = 0; i < workers.Length; i++)
|
||||
ThreadPool.UnsafeQueueUserWorkItem (workers [i].result.CompleteDisposed, null);
|
||||
KeyValuePair<IntPtr, IOSelectorJob> [] jobs = queue.ToArray ();
|
||||
for (int i = 0; i < jobs.Length; i++)
|
||||
ThreadPool.QueueUserWorkItem (j => ((IOSelectorJob) j).MarkDisposed (), jobs [i].Value);
|
||||
queue.Clear ();
|
||||
}
|
||||
}
|
||||
@ -266,53 +191,40 @@ namespace System.Net.Sockets
|
||||
|
||||
public void Complete (bool synch)
|
||||
{
|
||||
this.completed_synchronously = synch;
|
||||
CompletedSynchronously = synch;
|
||||
Complete ();
|
||||
}
|
||||
|
||||
public void Complete (int total)
|
||||
{
|
||||
this.total = total;
|
||||
Total = total;
|
||||
Complete ();
|
||||
}
|
||||
|
||||
public void Complete (Exception e, bool synch)
|
||||
{
|
||||
this.completed_synchronously = synch;
|
||||
this.delayed_exception = e;
|
||||
DelayedException = e;
|
||||
CompletedSynchronously = synch;
|
||||
Complete ();
|
||||
}
|
||||
|
||||
public void Complete (Exception e)
|
||||
{
|
||||
this.delayed_exception = e;
|
||||
DelayedException = e;
|
||||
Complete ();
|
||||
}
|
||||
|
||||
public void Complete (Socket s)
|
||||
{
|
||||
this.accept_socket = s;
|
||||
AcceptedSocket = s;
|
||||
Complete ();
|
||||
}
|
||||
|
||||
public void Complete (Socket s, int total)
|
||||
{
|
||||
this.accept_socket = s;
|
||||
this.total = total;
|
||||
AcceptedSocket = s;
|
||||
Total = total;
|
||||
Complete ();
|
||||
}
|
||||
|
||||
void IThreadPoolWorkItem.ExecuteWorkItem()
|
||||
{
|
||||
async_result.Invoke ();
|
||||
|
||||
if (completed && callback != null) {
|
||||
ThreadPool.UnsafeQueueCustomWorkItem (new AsyncResult (state => callback ((IAsyncResult) state), this, false), false);
|
||||
}
|
||||
}
|
||||
|
||||
void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,397 +0,0 @@
|
||||
// System.Net.Sockets.SocketAsyncWorker.cs
|
||||
//
|
||||
// Authors:
|
||||
// Ludovic Henry <ludovic@xamarin.com>
|
||||
//
|
||||
// Copyright (C) 2015 Xamarin, Inc. (https://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.
|
||||
//
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
internal sealed class SocketAsyncWorker
|
||||
{
|
||||
public SocketAsyncResult result;
|
||||
SocketAsyncEventArgs args;
|
||||
|
||||
public SocketAsyncWorker (SocketAsyncEventArgs args)
|
||||
{
|
||||
this.args = args;
|
||||
result = new SocketAsyncResult ();
|
||||
result.Worker = this;
|
||||
}
|
||||
|
||||
public SocketAsyncWorker (SocketAsyncResult ares)
|
||||
{
|
||||
this.result = ares;
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
if (result != null) {
|
||||
result.Dispose ();
|
||||
result = null;
|
||||
args = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static SocketAsyncCallback Dispatcher = new SocketAsyncCallback (DispatcherCB);
|
||||
|
||||
static void DispatcherCB (SocketAsyncResult sar)
|
||||
{
|
||||
/* SendPackets and ReceiveMessageFrom are not implemented yet */
|
||||
switch (sar.operation) {
|
||||
case SocketOperation.Receive:
|
||||
case SocketOperation.ReceiveGeneric:
|
||||
case SocketOperation.RecvJustCallback:
|
||||
sar.Worker.Receive ();
|
||||
break;
|
||||
case SocketOperation.Send:
|
||||
case SocketOperation.SendGeneric:
|
||||
case SocketOperation.SendJustCallback:
|
||||
sar.Worker.Send ();
|
||||
break;
|
||||
case SocketOperation.ReceiveFrom:
|
||||
sar.Worker.ReceiveFrom ();
|
||||
break;
|
||||
case SocketOperation.SendTo:
|
||||
sar.Worker.SendTo ();
|
||||
break;
|
||||
case SocketOperation.Connect:
|
||||
sar.Worker.Connect ();
|
||||
break;
|
||||
case SocketOperation.Accept:
|
||||
sar.Worker.Accept ();
|
||||
break;
|
||||
case SocketOperation.AcceptReceive:
|
||||
sar.Worker.AcceptReceive ();
|
||||
break;
|
||||
case SocketOperation.Disconnect:
|
||||
sar.Worker.Disconnect ();
|
||||
break;
|
||||
// case SocketOperation.ReceiveMessageFrom
|
||||
// sar.Worker.ReceiveMessageFrom ()
|
||||
// break;
|
||||
// case SocketOperation.SendPackets:
|
||||
// sar.Worker.SendPackets ();
|
||||
// break;
|
||||
default:
|
||||
throw new NotImplementedException (String.Format ("Operation {0} is not implemented", sar.operation));
|
||||
}
|
||||
}
|
||||
|
||||
/* This is called when reusing a SocketAsyncEventArgs */
|
||||
public void Init (Socket sock, SocketAsyncEventArgs args, SocketOperation op)
|
||||
{
|
||||
result.Init (sock, args, SocketAsyncEventArgs.Dispatcher, op, this);
|
||||
|
||||
SocketAsyncOperation async_op;
|
||||
|
||||
// Notes;
|
||||
// -SocketOperation.AcceptReceive not used in SocketAsyncEventArgs
|
||||
// -SendPackets and ReceiveMessageFrom are not implemented yet
|
||||
switch (op) {
|
||||
case SocketOperation.Connect:
|
||||
async_op = SocketAsyncOperation.Connect;
|
||||
break;
|
||||
case SocketOperation.Accept:
|
||||
async_op = SocketAsyncOperation.Accept;
|
||||
break;
|
||||
case SocketOperation.Disconnect:
|
||||
async_op = SocketAsyncOperation.Disconnect;
|
||||
break;
|
||||
case SocketOperation.Receive:
|
||||
case SocketOperation.ReceiveGeneric:
|
||||
async_op = SocketAsyncOperation.Receive;
|
||||
break;
|
||||
case SocketOperation.ReceiveFrom:
|
||||
async_op = SocketAsyncOperation.ReceiveFrom;
|
||||
break;
|
||||
// case SocketOperation.ReceiveMessageFrom:
|
||||
// async_op = SocketAsyncOperation.ReceiveMessageFrom;
|
||||
// break;
|
||||
case SocketOperation.Send:
|
||||
case SocketOperation.SendGeneric:
|
||||
async_op = SocketAsyncOperation.Send;
|
||||
break;
|
||||
// case SocketOperation.SendPackets:
|
||||
// async_op = SocketAsyncOperation.SendPackets;
|
||||
// break;
|
||||
case SocketOperation.SendTo:
|
||||
async_op = SocketAsyncOperation.SendTo;
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException (String.Format ("Operation {0} is not implemented", op));
|
||||
}
|
||||
|
||||
args.SetLastOperation (async_op);
|
||||
args.SocketError = SocketError.Success;
|
||||
args.BytesTransferred = 0;
|
||||
}
|
||||
|
||||
public void Accept ()
|
||||
{
|
||||
Socket acc_socket = null;
|
||||
try {
|
||||
if (args != null && args.AcceptSocket != null) {
|
||||
result.socket.Accept (args.AcceptSocket);
|
||||
acc_socket = args.AcceptSocket;
|
||||
} else {
|
||||
acc_socket = result.socket.Accept ();
|
||||
if (args != null)
|
||||
args.AcceptSocket = acc_socket;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
|
||||
result.Complete (acc_socket);
|
||||
}
|
||||
|
||||
/* only used in 2.0 profile and newer, but
|
||||
* leave in older profiles to keep interface
|
||||
* to runtime consistent
|
||||
*/
|
||||
public void AcceptReceive ()
|
||||
{
|
||||
Socket acc_socket = null;
|
||||
try {
|
||||
if (result.AcceptSocket == null) {
|
||||
acc_socket = result.socket.Accept ();
|
||||
} else {
|
||||
acc_socket = result.AcceptSocket;
|
||||
result.socket.Accept (acc_socket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
|
||||
/* It seems the MS runtime
|
||||
* special-cases 0-length requested
|
||||
* receive data. See bug 464201.
|
||||
*/
|
||||
int total = 0;
|
||||
if (result.Size > 0) {
|
||||
try {
|
||||
SocketError error;
|
||||
total = acc_socket.Receive_nochecks (result.Buffer, result.Offset, result.Size, result.SockFlags, out error);
|
||||
if (error != 0) {
|
||||
result.Complete (new SocketException ((int) error));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
result.Complete (acc_socket, total);
|
||||
}
|
||||
|
||||
public void Connect ()
|
||||
{
|
||||
if (result.EndPoint == null) {
|
||||
result.Complete (new SocketException ((int)SocketError.AddressNotAvailable));
|
||||
return;
|
||||
}
|
||||
|
||||
SocketAsyncResult mconnect = result.AsyncState as SocketAsyncResult;
|
||||
bool is_mconnect = (mconnect != null && mconnect.Addresses != null);
|
||||
try {
|
||||
int error_code;
|
||||
EndPoint ep = result.EndPoint;
|
||||
error_code = (int) result.socket.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error);
|
||||
if (error_code == 0) {
|
||||
if (is_mconnect)
|
||||
result = mconnect;
|
||||
result.socket.seed_endpoint = ep;
|
||||
result.socket.is_connected = true;
|
||||
result.socket.is_bound = true;
|
||||
result.socket.connect_in_progress = false;
|
||||
result.error = 0;
|
||||
result.Complete ();
|
||||
if (is_mconnect)
|
||||
result.DoMConnectCallback ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_mconnect) {
|
||||
result.socket.connect_in_progress = false;
|
||||
result.Complete (new SocketException (error_code));
|
||||
return;
|
||||
}
|
||||
|
||||
if (mconnect.CurrentAddress >= mconnect.Addresses.Length) {
|
||||
mconnect.Complete (new SocketException (error_code));
|
||||
if (is_mconnect)
|
||||
mconnect.DoMConnectCallback ();
|
||||
return;
|
||||
}
|
||||
mconnect.socket.BeginMConnect (mconnect);
|
||||
} catch (Exception e) {
|
||||
result.socket.connect_in_progress = false;
|
||||
if (is_mconnect)
|
||||
result = mconnect;
|
||||
result.Complete (e);
|
||||
if (is_mconnect)
|
||||
result.DoMConnectCallback ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Also only used in 2.0 profile and newer */
|
||||
public void Disconnect ()
|
||||
{
|
||||
try {
|
||||
if (args != null)
|
||||
result.ReuseSocket = args.DisconnectReuseSocket;
|
||||
result.socket.Disconnect (result.ReuseSocket);
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
result.Complete ();
|
||||
}
|
||||
|
||||
public void Receive ()
|
||||
{
|
||||
if (result.operation == SocketOperation.ReceiveGeneric) {
|
||||
ReceiveGeneric ();
|
||||
return;
|
||||
}
|
||||
|
||||
int total = 0;
|
||||
try {
|
||||
total = Socket.Receive_internal (result.socket.safe_handle, result.Buffer, result.Offset, result.Size, result.SockFlags, out result.error);
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
|
||||
result.Complete (total);
|
||||
}
|
||||
|
||||
public void ReceiveFrom ()
|
||||
{
|
||||
int total = 0;
|
||||
try {
|
||||
total = result.socket.ReceiveFrom_nochecks (result.Buffer, result.Offset, result.Size, result.SockFlags, ref result.EndPoint);
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
|
||||
result.Complete (total);
|
||||
}
|
||||
|
||||
public void ReceiveGeneric ()
|
||||
{
|
||||
int total = 0;
|
||||
try {
|
||||
total = result.socket.Receive (result.Buffers, result.SockFlags);
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
result.Complete (total);
|
||||
}
|
||||
|
||||
int send_so_far;
|
||||
|
||||
void UpdateSendValues (int last_sent)
|
||||
{
|
||||
if (result.error == 0) {
|
||||
send_so_far += last_sent;
|
||||
result.Offset += last_sent;
|
||||
result.Size -= last_sent;
|
||||
}
|
||||
}
|
||||
|
||||
public void Send ()
|
||||
{
|
||||
if (result.operation == SocketOperation.SendGeneric) {
|
||||
SendGeneric ();
|
||||
return;
|
||||
}
|
||||
|
||||
int total = 0;
|
||||
try {
|
||||
total = Socket.Send_internal (result.socket.safe_handle, result.Buffer, result.Offset, result.Size, result.SockFlags, out result.error);
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.error == 0) {
|
||||
UpdateSendValues (total);
|
||||
if (result.socket.is_disposed) {
|
||||
result.Complete (total);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.Size > 0) {
|
||||
Socket.socket_pool_queue (SocketAsyncWorker.Dispatcher, result);
|
||||
return; // Have to finish writing everything. See bug #74475.
|
||||
}
|
||||
result.Total = send_so_far;
|
||||
send_so_far = 0;
|
||||
}
|
||||
result.Complete (total);
|
||||
}
|
||||
|
||||
public void SendTo ()
|
||||
{
|
||||
int total = 0;
|
||||
try {
|
||||
total = result.socket.SendTo_nochecks (result.Buffer, result.Offset, result.Size, result.SockFlags, result.EndPoint);
|
||||
|
||||
UpdateSendValues (total);
|
||||
if (result.Size > 0) {
|
||||
Socket.socket_pool_queue (SocketAsyncWorker.Dispatcher, result);
|
||||
return; // Have to finish writing everything. See bug #74475.
|
||||
}
|
||||
result.Total = send_so_far;
|
||||
send_so_far = 0;
|
||||
} catch (Exception e) {
|
||||
send_so_far = 0;
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
|
||||
result.Complete ();
|
||||
}
|
||||
|
||||
public void SendGeneric ()
|
||||
{
|
||||
int total = 0;
|
||||
try {
|
||||
total = result.socket.Send (result.Buffers, result.SockFlags);
|
||||
} catch (Exception e) {
|
||||
result.Complete (e);
|
||||
return;
|
||||
}
|
||||
result.Complete (total);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.SocketError.cs
|
||||
//
|
||||
// Author:
|
||||
// Robert Jordan <robertj@gmx.net>
|
||||
//
|
||||
// Copyright (C) 2005 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 SocketError
|
||||
{
|
||||
AccessDenied = 10013,
|
||||
AddressAlreadyInUse = 10048,
|
||||
AddressFamilyNotSupported = 10047,
|
||||
AddressNotAvailable = 10049,
|
||||
AlreadyInProgress = 10037,
|
||||
ConnectionAborted = 10053,
|
||||
ConnectionRefused = 10061,
|
||||
ConnectionReset = 10054,
|
||||
DestinationAddressRequired = 10039,
|
||||
Disconnecting = 10101,
|
||||
Fault = 10014,
|
||||
HostDown = 10064,
|
||||
HostNotFound = 11001,
|
||||
HostUnreachable = 10065,
|
||||
InProgress = 10036,
|
||||
Interrupted = 10004,
|
||||
InvalidArgument = 10022,
|
||||
IOPending = 997,
|
||||
IsConnected = 10056,
|
||||
MessageSize = 10040,
|
||||
NetworkDown = 10050,
|
||||
NetworkReset = 10052,
|
||||
NetworkUnreachable = 10051,
|
||||
NoBufferSpaceAvailable = 10055,
|
||||
NoData = 11004,
|
||||
NoRecovery = 11003,
|
||||
NotConnected = 10057,
|
||||
NotInitialized = 10093,
|
||||
NotSocket = 10038,
|
||||
OperationAborted = 995,
|
||||
OperationNotSupported = 10045,
|
||||
ProcessLimit = 10067,
|
||||
ProtocolFamilyNotSupported = 10046,
|
||||
ProtocolNotSupported = 10043,
|
||||
ProtocolOption = 10042,
|
||||
ProtocolType = 10041,
|
||||
Shutdown = 10058,
|
||||
SocketError = -1,
|
||||
SocketNotSupported = 10044,
|
||||
Success = 0,
|
||||
SystemNotReady = 10091,
|
||||
TimedOut = 10060,
|
||||
TooManyOpenSockets = 10024,
|
||||
TryAgain = 11002,
|
||||
TypeNotFound = 10109,
|
||||
VersionNotSupported = 10092,
|
||||
WouldBlock = 10035
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
//
|
||||
// System.Net.Sockets.NetworkStream.cs
|
||||
//
|
||||
// Author:
|
||||
// Dick Porter <dick@ximian.com>
|
||||
//
|
||||
// (C) 2002 Ximian, 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.Runtime.Serialization;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System.Net.Sockets
|
||||
{
|
||||
[Serializable]
|
||||
public class SocketException : Win32Exception
|
||||
{
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
private static extern int WSAGetLastError_internal ();
|
||||
public SocketException ()
|
||||
: base (WSAGetLastError_internal ())
|
||||
{
|
||||
}
|
||||
|
||||
public SocketException (int error)
|
||||
: base (error) {
|
||||
}
|
||||
|
||||
protected SocketException (SerializationInfo info,
|
||||
StreamingContext context)
|
||||
: base (info, context) {
|
||||
}
|
||||
|
||||
|
||||
internal SocketException (int error, string message)
|
||||
: base (error, message)
|
||||
{
|
||||
}
|
||||
|
||||
public override int ErrorCode {
|
||||
get {
|
||||
return NativeErrorCode;
|
||||
}
|
||||
}
|
||||
|
||||
public SocketError SocketErrorCode {
|
||||
get {
|
||||
return (SocketError) NativeErrorCode;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Message {
|
||||
get {
|
||||
return base.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
// SocketFlags.cs
|
||||
//
|
||||
// This code was automatically generated from
|
||||
// ECMA CLI XML Library Specification.
|
||||
// Generator: libgen.xsl [1.0; (C) Sergey Chaban (serge@wildwestsoftware.com)]
|
||||
// Created: Wed, 5 Sep 2001 06:32:49 UTC
|
||||
// Source file: AllTypes.xml
|
||||
// URL: http://msdn.microsoft.com/net/ecma/AllTypes.xml
|
||||
//
|
||||
// (C) 2001 Ximian, Inc. http://www.ximian.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 {
|
||||
[Flags]
|
||||
public enum SocketFlags {
|
||||
None = 0x00000000,
|
||||
OutOfBand = 0x00000001,
|
||||
Peek = 0x00000002,
|
||||
DontRoute = 0x00000004,
|
||||
MaxIOVectorLength = 0x00000010,
|
||||
Truncated = 0x00000100,
|
||||
ControlDataTruncated = 0x00000200,
|
||||
Broadcast = 0x00000400,
|
||||
Multicast = 0x00000800,
|
||||
Partial = 0x00008000,
|
||||
} // SocketFlags
|
||||
|
||||
} // System.Net.Sockets
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user