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 } }
public void Listen(Int32 backlog) { #if cooper fServerHandle.bind(fSocketAddress, backlog); #else if (rtl.listen(fHandle, backlog) != 0) { throw new Exception("Error calling to listen function"); } #endif }