@caption Response socket to slave entry

@readme
Reponse socket for link entry requests. Is registered in `entry.slaves`.

@class ose.lib.entry.slave
@type class
@internal
 Public {{{1
499010
function init(entry) {  // {{{2
/**
 * Class constructor
 *
 * @param entry {Object} Entry instance
 *
 * @method constructor
 */

//  console.log('ENTRY SLAVE CONSTRUCTOR', entry.id);

  this.entry = entry;

  if (entry.slaves) {
    this.slaveId = ++entry.slaveId;
  } else {
    entry.slaves = {};
    this.slaveId = entry.slaveId = 1;
  }

  entry.slaves[this.slaveId] = this;
}
638704
public SSLSocket getSSLSocket() throws KeystoreException, CommunicationException {
		SSLSocketFactory socketFactory = getSSLSocketFactory();
		logger.debug("Creating SSLSocket to " + getServerHost() + ":" + getServerPort());

		try {
			if (ProxyManager.isUsingProxy(server)) {
				return tunnelThroughProxy(socketFactory);
			} else {
				return (SSLSocket) socketFactory.createSocket(getServerHost(), getServerPort());
			}
		} catch (Exception e) {
			throw new CommunicationException("Communication exception: " + e, e);
		}
	}
1258154
def open
      begin
        begin
          with_timeout do
            @socket = TCPSocket.new(@host, @port)
            @socket.sync = true
            welcome = @socket.gets
            unless welcome =~ /^# munin node at/
              raise Munin::AccessDenied
            end
            @connected = true
          end
        rescue Timeout::Error
          raise Munin::ConnectionError, "Timed out talking to #{@host}"
        end
      rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::ECONNRESET => ex
        raise Munin::ConnectionError, ex.message
      rescue EOFError
        raise Munin::AccessDenied
      rescue Exception => ex
        raise Munin::ConnectionError, ex.message
      end
    end
1317076
@Override
  public ClientSocket openWarm()
  {
    State state = _state;

    if (! state.isEnabled()) {
      return null;
    }
    
    /*
    long now = CurrentTime.getCurrentTime();
    
    if (isFailed(now)) {
      return null;
    }
    */

    ClientSocket stream = openRecycle();

    if (stream != null) {
      return stream;
    }

    if (canOpenWarm()) {
      return connect();
    }
    else {
      return null;
    }
  }
476260
def write(s)
      begin
        retry_id ||= 0
        @socket.send(:write, s)
      rescue => e
        if (retry_id += 1) < @retries
          connect
          retry
        else
          raise e
        end
      end
    end
269343
Connection registerChannel(
            final SocketChannel channel,
            final InputHandler handler,
            final int interestOps,
            final ReverseDNSPolicy dns,
            final CipherExecutor cipherService,
            final SSLEngine sslEngine) throws IOException {

        synchronized(channel.blockingLock()) {
            channel.configureBlocking (false);
            channel.socket().setKeepAlive(true);
        }

        Callable<Connection> registerTask = new Callable<Connection>() {
            @Override
            public Connection call() throws Exception {
                final VoltPort port = VoltPortFactory.createVoltPort(
                                channel,
                                VoltNetwork.this,
                                handler,
                                (InetSocketAddress)channel.socket().getRemoteSocketAddress(),
                                m_pool,
                                cipherService,
                                sslEngine);
                port.registering();

                /*
                 * This means we are used by a client. No need to wait then, trigger
                 * the reverse DNS lookup now.
                 */
                if (dns != ReverseDNSPolicy.NONE) {
                    port.resolveHostname(dns == ReverseDNSPolicy.SYNCHRONOUS);
                }

                try {
                    SelectionKey key = channel.register (m_selector, interestOps, null);

                    port.setKey (key);
                    port.registered();

                    //Fix a bug witnessed on the mini where the registration lock and the selector wakeup contained
                    //within was not enough to prevent the selector from returning the port after it was registered,
                    //but before setKey was called. Suspect a bug in the selector.wakeup() or register() implementation
                    //on the mac.
                    //The null check in invokeCallbacks will catch the null attachment, continue, and do the work
                    //next time through the selection loop
                    key.attach(port);

                    return port;
                } finally {
                    m_ports.add(port);
                    m_numPorts.incrementAndGet();
                }
            }
        };

        FutureTask<Connection> ft = new FutureTask<Connection>(registerTask);
        m_tasks.offer(ft);
        m_selector.wakeup();

        try {
            return ft.get();
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
854591
protected SocketBox openSocket() throws Exception {
        SocketBox sBox = new SimpleSocketBox();

        SocketFactory factory = SocketFactory.getDefault();
        Socket mySocket = factory.createSocket(this.hostPort.getHost(),
                                               this.hostPort.getPort());
        sBox.setSocket(mySocket);

        return sBox;
    }
1000427
private void sendMasterAnswer(Address target) {
        Address masterAddress = clusterService.getMasterAddress();
        if (masterAddress == null) {
            logger.info(format("Cannot send master answer to %s since master node is not known yet", target));
            return;
        }

        if (masterAddress.equals(node.getThisAddress())
                && node.getNodeExtension().getInternalHotRestartService()
                    .isMemberExcluded(masterAddress, clusterService.getThisUuid())) {
            // I already know that I will do a force-start so I will not allow target to join me
            logger.info("Cannot send master answer because " + target + " should not join to this master node.");
            return;
        }

        if (masterAddress.equals(target)) {
            logger.fine("Cannot send master answer to " + target + " since it is the known master");
            return;
        }

        MasterResponseOp op = new MasterResponseOp(masterAddress);
        nodeEngine.getOperationService().send(op, target);
    }
323389
public void dhtPutItem(byte[] publicKey, byte[] privateKey, Entry entry, byte[] salt) {
        s.dht_put_item(Vectors.bytes2byte_vector(publicKey),
                Vectors.bytes2byte_vector(privateKey),
                entry.swig(),
                Vectors.bytes2byte_vector(salt));
    }
777908
void registerAndConnect(SocketChannel sock, InetSocketAddress addr)
            throws IOException {
        selectionKey = sock.register(selector, SelectionKey.OP_CONNECT);

        boolean immediateConnect = sock.connect(addr);
        if(LOGGER.isTraceEnabled()){
            LOGGER.trace("Connect to host=" + addr.getHostName() + ", hostString=" + addr.getHostString() + ", port=" + addr.getPort() + ", all=" + addr.getAddress() + ", local=" + sock.socket().getLocalSocketAddress());
        }
        if (immediateConnect) {
            onConnectSucceeded();
        }


    }
513399
protected Proxy copy(){
       Socks4Proxy copy = new Socks4Proxy(proxyIP,proxyPort,user);
       copy.directHosts = this.directHosts;
       copy.chainProxy = chainProxy;
       return copy;
    }
442596
private void doSocketConnect(InetSocketAddress addr) throws IOException{
        SocketChannel sock = createSock();
        registerAndConnect(sock, addr);
    }
1304616
@Override
	public ServerSocket createServerSocket(int port) throws IOException
    {
    	ServerSocket socket = getSocketFactory().createServerSocket(port,backLog,getListenAddress());
    	if (manageSockets)
    		createdSockets.add(socket);
    	return socket;
    }
726472
@Override
  public InetAddress addressRemote()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        InetSocketAddress addr = (InetSocketAddress) s.getRemoteAddress();
        
        return addr.getAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }
1173427
synchronized void link(final OtpErlangPid from, final OtpErlangPid to)
            throws OtpErlangExit {
        try {
            super.sendLink(from, to);
            links.addLink(from, to);
        } catch (final IOException e) {
            throw new OtpErlangExit("noproc", to);
        }
    }
1264155
public Socket connect() throws IOException {
        final Socket socket = this.createSocket();
        final InetAddress destinationAddress = this.getResolvedDestinationAddress();
        final int destinationPort = this.getDestinationPort();
        final SocketAddress destination = new InetSocketAddress(destinationAddress, destinationPort);
        socket.connect(destination);

        return socket;
    }
503787
@SuppressWarnings("unchecked")
    @Override
    public T newChannel() {
        switch (kind) {
            case ACCEPTOR:
                switch (type) {
                    case DATAGRAM:
                        return (T) new NioUdtMessageAcceptorChannel();
                    case STREAM:
                        return (T) new NioUdtByteAcceptorChannel();
                    default:
                        throw new IllegalStateException("wrong type=" + type);
                }
            case CONNECTOR:
                switch (type) {
                    case DATAGRAM:
                        return (T) new NioUdtMessageConnectorChannel();
                    case STREAM:
                        return (T) new NioUdtByteConnectorChannel();
                    default:
                        throw new IllegalStateException("wrong type=" + type);
                }
            case RENDEZVOUS:
                switch (type) {
                    case DATAGRAM:
                        return (T) new NioUdtMessageRendezvousChannel();
                    case STREAM:
                        return (T) new NioUdtByteRendezvousChannel();
                    default:
                        throw new IllegalStateException("wrong type=" + type);
                }
            default:
                throw new IllegalStateException("wrong kind=" + kind);
        }
    }