   :block-start          Wait for the pool's initial connections to open
                         before returning.
 
-  :protocol             Protocol to use. Either :tcp (default) or :udp."
+  :protocol             Protocol to use. Either :tcp (default) or :udp.
+
+  TLS options:
+  :tls?             Whether to enable TLS
+  :key              A PKCS8-encoded private key file
+  :cert             The corresponding public certificate
+  :ca-cert          The certificate of the CA which signed this key"
+
   [opts]
+
   (let [opts (merge {:host "127.0.0.1"
                      :port 9999
                      :protocol :tcp
+                     :tls false
                      :claim-timeout 0.1
                      :pool-size 4} opts)
+
         pool (fixed-pool
                (fn []
-                 (info "Connecting to " (select-keys opts [:host :port]))
-                 (let [host (:host opts)
+                 (info "Connecting to " (select-keys opts [:host :port :security.protocol :tls]))
+                 (let [
+                       host (:host opts)
                        port (:port opts)
                        client (open (condp = (:protocol opts)
-                                      :tcp (LogStashTCPClient. host port)
+                                      :tcp (LogStashTCPClient. host port opts)
                                       :udp (LogStashUDPClient. host port)))]
                    (info "Connected")
                    client))

  (close [client]
         "Cleans up (closes sockets etc.)"))

(defrecord LogStashTCPClient [^String host ^int port]
  LogStashClient
  (open [this]
    (let [sock (Socket. host port)]
      (assoc this 
             :socket sock
             :out (OutputStreamWriter. (.getOutputStream sock)))))
  (send-line [this line]
    (let [out (:out this)]
      (.write ^OutputStreamWriter out ^String line)
      (.flush ^OutputStreamWriter out)))
  (close [this]
    (.close ^OutputStreamWriter (:out this))
    (.close ^Socket (:socket this))))

(defrecord LogStashUDPClient [^String host ^int port]
  LogStashClient

  (:use [clojure.string :only [split join replace]]
        clojure.tools.logging
        riemann.pool
        riemann.common
        less.awful.ssl))

(defprotocol LogStashClient
  (open [client]
