Esempio n. 1
0
        public static bool ConnectAsync(SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
        {
            // exception ordering requires to check before creating the socket (good thing resource wise too)
            CheckConnect(e);

            Socket s = new Socket(AddressFamily.InterNetwork, socketType, protocolType);

            e.DoOperation(SocketAsyncOperation.Connect, s);

            // We always return true for now
            return(true);
        }
Esempio n. 2
0
        public bool ConnectAsync(SocketAsyncEventArgs e)
        {
            if (disposed && closed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            CheckConnect(e);

            e.DoOperation(SocketAsyncOperation.Connect, this);

            // We always return true for now
            return(true);
        }
Esempio n. 3
0
        public bool SendAsync(SocketAsyncEventArgs e)
        {
            // NO check is made whether e != null in MS.NET (NRE is thrown in such case)

            if (disposed && closed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }
            if (e.Buffer == null && e.BufferList == null)
            {
                throw new ArgumentException("Either e.Buffer or e.BufferList must be valid buffers.");
            }

            e.DoOperation(SocketAsyncOperation.Send, this);

            // We always return true for now
            return(true);
        }
Esempio n. 4
0
        public bool ReceiveAsync(SocketAsyncEventArgs e)
        {
            // NO check is made whether e != null in MS.NET (NRE is thrown in such case)
            //
            // LAME SPEC: the ArgumentException is never thrown, instead an NRE is
            // thrown when e.Buffer and e.BufferList are null (works fine when one is
            // set to a valid object)
            if (disposed && closed)
            {
                throw new ObjectDisposedException(GetType().ToString());
            }

            // We do not support recv into multiple buffers yet
            if (e.BufferList != null)
            {
                throw new NotSupportedException("Mono doesn't support using BufferList at this point.");
            }

            e.DoOperation(SocketAsyncOperation.Receive, this);

            // We always return true for now
            return(true);
        }
Esempio n. 5
0
		public static bool ConnectAsync (SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
		{
			// exception ordering requires to check before creating the socket (good thing resource wise too)
			CheckConnect (e);

			// create socket based on the endpoint address family (if specified), otherwise default fo IPv4
			AddressFamily raf = e.RemoteEndPoint.AddressFamily;
			if (raf == AddressFamily.Unspecified)
				raf = AddressFamily.InterNetwork;
			Socket s = new Socket (raf, socketType, protocolType);
			e.DoOperation (SocketAsyncOperation.Connect, s);

			// We always return true for now
			return true;
		}
Esempio n. 6
0
		public bool ConnectAsync (SocketAsyncEventArgs e)
		{
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());

			CheckConnect (e);
			// if an address family is specified then they must match
			AddressFamily raf = e.RemoteEndPoint.AddressFamily;
			if ((raf != AddressFamily.Unspecified) && (raf != AddressFamily))
				throw new NotSupportedException ("AddressFamily mismatch between socket and endpoint");

			e.DoOperation (SocketAsyncOperation.Connect, this);

			// We always return true for now
			return true;
		}
Esempio n. 7
0
		public bool SendToAsync (SocketAsyncEventArgs e)
		{
			// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
			
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());
			if (e.RemoteEndPoint == null)
				throw new ArgumentNullException ("remoteEP", "Value cannot be null.");
			
			e.DoOperation (SocketAsyncOperation.SendTo, this);

			// We always return true for now
			return true;
		}
Esempio n. 8
0
		public bool ReceiveFromAsync (SocketAsyncEventArgs e)
		{
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());

			// We do not support recv into multiple buffers yet
			if (e.BufferList != null)
				throw new NotSupportedException ("Mono doesn't support using BufferList at this point.");
			if (e.RemoteEndPoint == null)
				throw new ArgumentNullException ("remoteEP", "Value cannot be null.");

			e.DoOperation (SocketAsyncOperation.ReceiveFrom, this);

			// We always return true for now
			return true;
		}
Esempio n. 9
0
		public bool DisconnectAsync (SocketAsyncEventArgs e)
		{
			// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());

			e.DoOperation (SocketAsyncOperation.Disconnect, this);

			return true;
		}
Esempio n. 10
0
		public bool ConnectAsync (SocketAsyncEventArgs e)
		{
			// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
			
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());
			if (islistening)
				throw new InvalidOperationException ("You may not perform this operation after calling the Listen method.");
			if (e.RemoteEndPoint == null)
				throw new ArgumentNullException ("remoteEP", "Value cannot be null.");
			if (e.BufferList != null)
				throw new ArgumentException ("Multiple buffers cannot be used with this method.");

			e.DoOperation (SocketAsyncOperation.Connect, this);

			// We always return true for now
			return true;
		}
Esempio n. 11
0
		public bool AcceptAsync (SocketAsyncEventArgs e)
		{
			// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
			
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());
			if (!IsBound)
				throw new InvalidOperationException ("You must call the Bind method before performing this operation.");
			if (!islistening)
				throw new InvalidOperationException ("You must call the Listen method before performing this operation.");
			if (e.BufferList != null)
				throw new ArgumentException ("Multiple buffers cannot be used with this method.");
			if (e.Count < 0)
				throw new ArgumentOutOfRangeException ("e.Count");
			
			Socket acceptSocket = e.AcceptSocket;
			if (acceptSocket != null) {
				if (acceptSocket.IsBound || acceptSocket.Connected)
					throw new InvalidOperationException ("AcceptSocket: The socket must not be bound or connected.");
			} else
				e.AcceptSocket = new Socket (AddressFamily, SocketType, ProtocolType);

			try {
				e.DoOperation (SocketAsyncOperation.Accept, this);
			} catch {
				((IDisposable)e).Dispose ();
				throw;
			}

			// We always return true for now
			return true;
		}
Esempio n. 12
0
		public bool SendAsync (SocketAsyncEventArgs e)
		{
			// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
			
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());
			if (e.Buffer == null && e.BufferList == null)
				throw new ArgumentException ("Either e.Buffer or e.BufferList must be valid buffers.");

			e.DoOperation (SocketAsyncOperation.Send, this);

			// We always return true for now
			return true;
		}
Esempio n. 13
0
		public bool ReceiveAsync (SocketAsyncEventArgs e)
		{
			// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
			//
			// LAME SPEC: the ArgumentException is never thrown, instead an NRE is
			// thrown when e.Buffer and e.BufferList are null (works fine when one is
			// set to a valid object)
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());

			// We do not support recv into multiple buffers yet
			if (e.BufferList != null)
				throw new NotSupportedException ("Mono doesn't support using BufferList at this point.");
			
			e.DoOperation (SocketAsyncOperation.Receive, this);

			// We always return true for now
			return true;
		}
Esempio n. 14
0
		public static bool ConnectAsync (SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e)
		{
			// exception ordering requires to check before creating the socket (good thing resource wise too)
			CheckConnect (e);

			Socket s = new Socket (AddressFamily.InterNetwork, socketType, protocolType);
			e.DoOperation (SocketAsyncOperation.Connect, s);

			// We always return true for now
			return true;
		}
Esempio n. 15
0
		public bool ConnectAsync (SocketAsyncEventArgs e)
		{
			if (disposed && closed)
				throw new ObjectDisposedException (GetType ().ToString ());

			CheckConnect (e);

			e.DoOperation (SocketAsyncOperation.Connect, this);

			// We always return true for now
			return true;
		}