tcp-streams-0.2.0.0: One stop solution for tcp client and server with tls support.

Safe HaskellNone
LanguageHaskell2010

System.IO.Streams.TLS

Contents

Description

This module provides convenience functions for interfacing io-streams with tls. the default receive buffer size is decided by tls. sending is unbuffered, anything write into OutputStream will be immediately send to underlying socket.

You should handle IOError when you read/write these streams for safety.

Synopsis

client

connect Source #

Arguments

:: ClientParams

check Data.TLSSetting.

-> Maybe String

Optional certificate subject name, if set to Nothing then we will try to verify HostName as subject name.

-> HostName

hostname to connect to

-> PortNumber

port number to connect to

-> IO (InputStream ByteString, OutputStream ByteString, Context) 

Convenience function for initiating an TLS connection to the given (HostName, PortNumber) combination.

Note that sending an end-of-file to the returned OutputStream will not close the underlying TLS connection; to do that, call closeTLS

this operation will throw TLSException on failure.

withConnection Source #

Arguments

:: ClientParams 
-> Maybe HostName 
-> HostName 
-> PortNumber 
-> (InputStream ByteString -> OutputStream ByteString -> Context -> IO a)

Action to run with the new connection

-> IO a 

Convenience function for initiating an TLS connection to the given (HostName, PortNumber) combination. The socket and TLS connection are closed and deleted after the user handler runs.

server

accept Source #

accept a new connection from remote client, return a InputStream / OutputStream pair and remote SockAddr, you should call bindAndListen first.

this operation will throw TLSException on failure.

helpers

tlsToStreams Source #

Arguments

:: Context

TLS connection object

-> IO (InputStream ByteString, OutputStream ByteString) 

Given an existing TLS Context connection, produces an InputStream / OutputStream pair.

closeTLS :: Context -> IO () Source #

close a TLS Context and its underlying socket.