Give an unused socket to the cache.
@param sock  Socket not used by anyone.
196351
public void put(Socket sock) {
    Preconditions.checkNotNull(sock);
    
    SocketAddress remoteAddr = sock.getRemoteSocketAddress();
    if (remoteAddr == null) {
      LOG.warn("Cannot cache (unconnected) socket with no remote address: " + 
               sock);
      IOUtils.closeSocket(sock);
      return;
    }
   
    Socket oldestSock = null;
    synchronized(multimap) {
      if (capacity == multimap.size()) {
        oldestSock = evictOldest();
      }
      multimap.put(remoteAddr, sock);
    }
    
    if (oldestSock != null) {
      IOUtils.closeSocket(oldestSock);
    }
  }
632888
def remove_socket(self, socket):
        
        if socket in self._sockets:
            socket.on_closed.disconnect(self.remove_socket)
            self._sockets.remove(socket)
303702
private void transfer(Socket sourceSocket, Source source, Sink sink) {
    try {
      Buffer buffer = new Buffer();
      for (long byteCount; (byteCount = source.read(buffer, 8192L)) != -1; ) {
        sink.write(buffer, byteCount);
        sink.flush();
      }
    } catch (IOException e) {
      System.out.println("transfer failed from " + sourceSocket + ": " + e);
    } finally {
      closeQuietly(sink);
      closeQuietly(source);
      closeQuietly(sourceSocket);
      openSockets.remove(sourceSocket);
    }
  }
1101420
private void setSocketOptions() throws SocketException {
        if (DISABLE_NAGLES) {
            // Disable Nagle's algorithm (significant on Windows).
            m_socket.setTcpNoDelay(true);
            m_logger.debug("Nagle's algorithm disabled.");
        }
        if (USE_CUSTOM_BUFFER_SIZE) {
            // Improve default send/receive buffer sizes from default (often 8K).
            if (m_socket.getSendBufferSize() < NET_BUFFER_SIZE) {
                m_logger.debug("SendBufferSize increased from {} to {}",
                               m_socket.getSendBufferSize(), NET_BUFFER_SIZE);
                m_socket.setSendBufferSize(NET_BUFFER_SIZE);
            }
            if (m_socket.getReceiveBufferSize() < NET_BUFFER_SIZE) {
                m_logger.debug("ReceiveBufferSize increased from {} to {}",
                               m_socket.getReceiveBufferSize(), NET_BUFFER_SIZE);
                m_socket.setReceiveBufferSize(NET_BUFFER_SIZE);
            }
        }
    }
1234468
private void prepSocketChannel(SocketChannel sc) {
        try {
            sc.socket().setSendBufferSize(1024 * 1024 * 2);
            sc.socket().setReceiveBufferSize(1024 * 1024 * 2);
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
344754
public void destroy()
    {
        for (Socket socket : sockets) {
            destroySocket(socket);
        }
        sockets.clear();

        for (Selector selector : selectors) {
            context.close(selector);
        }
        selectors.clear();

        // Only terminate context if we are on the main thread
        if (isMain()) {
            context.term();
        }
    }
171012
@Override
	public synchronized void releaseThriftSocket(ThriftSocket thriftSocket, String host, int port) {
		if (thriftSocket == null || thriftSocket.getSocket() == null
				|| thriftSocket.getSocket().getInetAddress() == null) {
			log.debug("Release unsuccessful .");
			return;
		}
		if (!ServerUtil.checkHostAndPort(host, port)) {
			log.error("Server host or port is null ! Release unsuccessful .");
			return;
		}
		log.debug("Release socket , host is {} and port is {} .", host, port);
		SimpleSocketPoolImpl self = selfMap.get(ServerUtil.buildCacheKey(host, port));
		if (self == null)
			return;
		for (byte i = 0; i < size; i++)
			if (self.socketPool.get(new Byte(i)) == thriftSocket) {
				self.socketStatusArray[i] = Boolean.FALSE;
				return;
			}
		// 如果socket不在池中,就直接关闭
		thriftSocket.close();
	}
1288670
private void replaceSocket(Socket newSocket) {
        synchronized (m_socketLock) {
            closeSocket(m_socket);
            if (m_eos.get()) {
                closeSocket(newSocket);
                m_socket = null;
            } else {
                m_socket = newSocket;
            }
        }
    }
556762
static void offerLastTemporaryDirectBuffer(ByteBuffer buf) {
        assert buf != null;
        BufferCache cache = bufferCache.get();
        if (!cache.offerLast(buf)) {
            // cache is full
            free(buf);
        }
    }
1108798
public void connectionComplete(SocketAddress socket)
    {
        assert socket != null;
        activeSocketSessions.remove(socket);
        if (logger.isTraceEnabled())
            logger.trace("ClientState removed for socket addr {}", socket);
    }
622807
public synchronized void checkIn(SocketBox sb) {

        if (((ManagedSocketBox) sb).getStatus() != ManagedSocketBox.BUSY) {
            throw new IllegalArgumentException("The socket      is already marked free, cannot check it in twice.");
        }

        if (!busySockets.containsKey(sb)) {
            throw new IllegalArgumentException("This socket does not exist in the pool of busy sockets.");
        }

        if (freeSockets.containsKey(sb)) {
            throw new IllegalArgumentException("This socket already exists in the pool of free sockets.");
        }

        if (! ((ManagedSocketBox)sb).isReusable()) {

            throw new IllegalArgumentException("This socket is not reusable; cannot check in.");

        }

        ((ManagedSocketBox) sb).setStatus(ManagedSocketBox.FREE);
        busySockets.remove(sb);
        freeSockets.put(sb, sb);

    }
76295
private void closeServerSocket() {
       getLogger().debug("{} closing server socket", getName());

       try {
         if (serverSocket != null) {
           serverSocket.close();
         }
       } catch (Exception e) {
         // ignore for now
       }

       serverSocket = null;
     }
902390
def socket(self):
        """"""
        if self._ssl:
            if self._useSecuredWebsocket:
                return self._ssl.getSSLSocket()
            else:
                return self._ssl
        else:
            return self._sock
444461
def unpack_from_socket(sock)
      read  = ""
      total = ""
      parts = {}

      directives.each_with_index do |directive, i|
        total << directive.to_s(parts)
        read << sock.read(directive.bytesize parts)
        parts[directive.name] = read.unpack(total)[i]
      end

      parts.delete(:null) {}
      parts
    end
1090358
private void prepareStreams(Socket socket) throws IOException {

        // Close any open streams if I'm being called because a new socket was
        // set to handle this transport.
        try {
            if (dataInputStream != null) {
                dataInputStream.close();
            }
            if (dataOutputStream != null) {
                dataOutputStream.close();
            }
        }
        catch (IOException x) {
            // Do nothing.
        }

        dataInputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
        dataOutputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
    }
400231
def add_socket(self, socket):
        
        if socket not in self._sockets:
            self._sockets.add(socket)
            socket.on_closed.connect(self.remove_socket)
1146985
function Socket() {
  this.server = null;
  this.socks = [];
  this.settings = {};
  this.set('hwm', Infinity);
  this.set('identity', String(process.pid));
  this.retry = 0
  this.set('retry timeout', 100);
  this.set('retry max timeout', 5000);
  this.set('max retry', 100);
}