Inheritance: java.nio.channels.spi.AbstractSelectableChannel
Exemple #1
0
        public void Listen_internal(int backlog, out int error)
        {
            error = 0;

            if (jSocket == null || !jSocket.isBound())
            {
                error = 10022;                 //WSAEINVAL (Invalid argument)
                return;
            }

            if (jSocket.isConnected() || jSocketChannel.isConnectionPending())
            {
                error = 10056;                 //WSAEISCONN (Socket is already connected)
                return;
            }

            bool blockMode = jSocketChannel.isBlocking();
            bool reuseAddr = jSocket.getReuseAddress();

            try
            {
                jSocket.close();
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine("Caught exception during Listen_internal close old jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }

            try
            {
                jSocketChannel.close();
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine("Caught exception during Listen_internal close old jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }

            jSocket        = null;
            jSocketChannel = null;

            try
            {
                jServerSocketChannel = java.nio.channels.ServerSocketChannel.open();
                jServerSocket        = jServerSocketChannel.socket();
                jServerSocket.bind(jTempLocalSocketAddress, backlog);
                jServerSocketChannel.configureBlocking(blockMode);
                jServerSocket.setReuseAddress(reuseAddr);
            }
            catch (Exception e)
            {
                error = 10048;                 //WSAEADDRINUSE (Address already in use)
#if DEBUG
                Console.WriteLine("Caught exception during Listen_internal create server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
            }
        }
Exemple #2
0
        public void Close_internal(out int error)
        {
            error = 0;

            if (jServerSocket != null)
            {
                try
                {
                    jServerSocket.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jServerSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                try
                {
                    jServerSocketChannel.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jServerSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                jServerSocket        = null;
                jServerSocketChannel = null;
            }
            else if (jSocket != null)
            {
                try
                {
                    jSocket.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                try
                {
                    jSocketChannel.close();
                }
                catch (Exception e)
                {
                    error = 10022;                     //WSAEINVAL (Invalid argument)
#if DEBUG
                    Console.WriteLine("Caught exception during Close_internal jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
                }
                jSocket        = null;
                jSocketChannel = null;
            }
        }
Exemple #3
0
		public void Listen_internal(int backlog, out int error)
		{
			error = 0;

			if (jSocket == null || !jSocket.isBound())
			{
				error = 10022; //WSAEINVAL (Invalid argument)
				return;
			}

			if (jSocket.isConnected() || jSocketChannel.isConnectionPending())
			{
				error = 10056; //WSAEISCONN (Socket is already connected)
				return;
			}

			bool blockMode = jSocketChannel.isBlocking();
			bool reuseAddr = jSocket.getReuseAddress();

			try
			{
				jSocket.close();
			}
			catch (Exception e)
			{
#if DEBUG
				Console.WriteLine("Caught exception during Listen_internal close old jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}

			try
			{
				jSocketChannel.close();
			}
			catch (Exception e)
			{
#if DEBUG
				Console.WriteLine("Caught exception during Listen_internal close old jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}

			jSocket = null;
			jSocketChannel = null;

			try
			{
				jServerSocketChannel = java.nio.channels.ServerSocketChannel.open();
				jServerSocket = jServerSocketChannel.socket();
				jServerSocket.bind(jTempLocalSocketAddress, backlog);
				jServerSocketChannel.configureBlocking(blockMode);
				jServerSocket.setReuseAddress(reuseAddr);
			}
			catch (Exception e)
			{
				error = 10048; //WSAEADDRINUSE (Address already in use)
#if DEBUG
				Console.WriteLine("Caught exception during Listen_internal create server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
			}
		}
Exemple #4
0
		public void Close_internal(out int error)
		{
			error = 0;

			if (jServerSocket != null)
			{
				try
				{
					jServerSocket.close();
				}
				catch (Exception e)
				{
					error = 10022; //WSAEINVAL (Invalid argument)
#if DEBUG
					Console.WriteLine("Caught exception during Close_internal jServerSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
				}
				try
				{
					jServerSocketChannel.close();
				}
				catch (Exception e)
				{
					error = 10022; //WSAEINVAL (Invalid argument)
#if DEBUG
					Console.WriteLine("Caught exception during Close_internal jServerSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
				}
				jServerSocket = null;
				jServerSocketChannel = null;
			}
			else if (jSocket != null)
			{
				try
				{
					jSocket.close();
				}
				catch (Exception e)
				{
					error = 10022; //WSAEINVAL (Invalid argument)
#if DEBUG
					Console.WriteLine("Caught exception during Close_internal jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
				}
				try
				{
					jSocketChannel.close();
				}
				catch (Exception e)
				{
					error = 10022; //WSAEINVAL (Invalid argument)
#if DEBUG
					Console.WriteLine("Caught exception during Close_internal jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
#endif
				}
				jSocket = null;
				jSocketChannel = null;
			}
		}