public override void run() { TcpClient newsock = null; OtpCookedConnection conn = null; node.localStatus(node.Node, true, null); accept_loop: while (!done) { conn = null; try { newsock = sock.AcceptTcpClient(); } catch (Exception e) { // Problem in java1.2.2: accept throws SocketException // when socket is closed. This will happen when // acceptor.quit() // is called. acceptor.quit() will call localStatus(...), so // we have to check if that's where we come from. if (!done) { node.localStatus(node.Node, false, e); } goto accept_loop; } try { lock (node.Connections) { conn = new OtpCookedConnection(node, new BufferedTcpClient(newsock)); conn.setFlags(node.Flags); node.addConnection(conn); } } catch (OtpAuthException e) { if (conn != null && conn.Name != null) { node.connAttempt(conn.Name, true, e); } else { node.connAttempt("unknown", true, e); } closeSock(newsock); } catch (IOException e) { if (conn != null && conn.Name != null) { node.connAttempt(conn.Name, true, e); } else { node.connAttempt("unknown", true, e); } closeSock(newsock); } catch (Exception e) { closeSock(newsock); closeSock(sock); node.localStatus(node.Node, false, e); goto accept_loop; } } // while // if we have exited loop we must do this too unPublishPort(); }
private void removeConnection(OtpCookedConnection conn) { if (conn != null && conn.Name != null) { connections.Remove(conn.Name); } }
void addConnection(OtpCookedConnection conn) { if (conn != null && conn.Name != null) { connections.Add(conn.Name, conn); remoteStatus(conn.Name, true, null); } }
/* * find or create a connection to the given node */ public OtpCookedConnection getConnection(String node) { OtpPeer peer = null; OtpCookedConnection conn = null; lock (connections) { // first just try looking up the name as-is if (connections.ContainsKey(node)) { conn = connections[node]; } else { // in case node had no '@' add localhost info and try again peer = new OtpPeer(node); if (connections.ContainsKey(peer.Node)) { conn = connections[peer.Node]; } else { try { conn = new OtpCookedConnection(this, peer); conn.setFlags(flags); addConnection(conn); } catch (Exception e) { /* false = outgoing */ connAttempt(peer.Node, false, e); } } } return conn; } }
/* * OtpCookedConnection delivers errors here, we send them on to the handler * specified by the application */ public void deliverError(OtpCookedConnection conn, Exception e) { removeConnection(conn); remoteStatus(conn.Name, false, e); }
/** * Close the node. Unpublish the node from Epmd (preventing new connections) * and close all existing connections. */ public void close() { lock (this) { acceptor.quit(); mboxes.clear(); lock (connections) { OtpCookedConnection[] conns = new OtpCookedConnection[connections.Count]; int i = 0; foreach (OtpCookedConnection conn in connections.Values) { conns[i++] = conn; } connections.Clear(); foreach (OtpCookedConnection conn in conns) { conn.close(); } initDone = false; } } }