     Prepared.Cache.lookup(state.prepared_cache, prepared)
   end
 
-  defp connect(host, port) do
-    with {:error, reason} <- :gen_tcp.connect(host, port, @default_socket_options, @default_timeout),
-         do: {:error, Error.new("TCP connect", reason)}
-  end
-
   defp startup_connection(socket, supported_options, compressor) do
     %{"CQL_VERSION" => [cql_version | _],
       "COMPRESSION" => supported_compression_algorithms} = supported_options

    prepared_cache = Keyword.fetch!(options, :prepared_cache)
    compressor = Keyword.get(options, :compressor)

    with {:ok, socket} <- connect(host, port),
         {:ok, supported_options} <- Utils.request_options(socket),
         :ok <- startup_connection(socket, supported_options, compressor) do
      {:ok, %__MODULE__{socket: socket, prepared_cache: prepared_cache, compressor: compressor}}
    end
  end


  @default_timeout 5_000
  @default_socket_options [packet: :raw, mode: :binary, active: false]

  defstruct [:socket, :prepared_cache, :compressor]

  def connect(options) do
    host = Keyword.fetch!(options, :host)
