code: def prepare_socket(bind_addr, family, type, proto, nodelay, ssl_adapter):
          
          sock = socket.socket(family, type, proto)
          prevent_socket_inheritance(sock)
  
          host, port = bind_addr[:2]
          IS_EPHEMERAL_PORT = port == 0
  
          if not (IS_WINDOWS or IS_EPHEMERAL_PORT):
              """Enable SO_REUSEADDR for the current socket.
  
              Skip for Windows (has different semantics)
              or ephemeral ports (can steal ports from others).
  
              Refs:
              * https://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx
              * https://github.com/cherrypy/cheroot/issues/114
              * https://gavv.github.io/blog/ephemeral-port-reuse/
              """
              sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
          if nodelay and not isinstance(bind_addr, str):
              sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
  
          if ssl_adapter is not None:
              sock = ssl_adapter.bind(sock)
  
          # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
          # activate dual-stack. See
          # https://github.com/cherrypy/cherrypy/issues/871.
          listening_ipv6 = (
              hasattr(socket, 'AF_INET6')
              and family == socket.AF_INET6
              and host in ('::', '::0', '::0.0.0.0')
          )
          if listening_ipv6:
              try:
                  sock.setsockopt(
                      socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0,
                  )
              except (AttributeError, socket.error):
                  # Apparently, the socket option is not available in
                  # this machine's TCP stack
                  pass
  
          return sock
docs: Create and prepare the socket object.