From 3e364247caed8c0bbe0e81531473b6c6b86506c4 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 17 Oct 2012 10:28:45 +0900 Subject: Using conduit. --- Network/DNS/Decode.hs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'Network/DNS/Decode.hs') diff --git a/Network/DNS/Decode.hs b/Network/DNS/Decode.hs index b598d97..b99fc44 100644 --- a/Network/DNS/Decode.hs +++ b/Network/DNS/Decode.hs @@ -11,23 +11,21 @@ import Data.Bits import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy as BL -import Data.Enumerator (Enumerator, run_, ($$)) +import Data.Conduit +import Data.Conduit.Network import Data.IP import Data.Maybe import Network import Network.DNS.Internal import Network.DNS.StateBinary -import Network.Socket.Enumerator ---------------------------------------------------------------- {-| Receiving DNS data from 'Socket' and parse it. The second argument is a buffer size for the socket. -} -receive :: Socket -> Integer -> IO DNSFormat -receive sock bufsize = receiveDNSFormat responseEnum - where - responseEnum = enumSocket bufsize sock +receive :: Socket -> IO DNSFormat +receive sock = receiveDNSFormat $ sourceSocket sock ---------------------------------------------------------------- @@ -37,12 +35,10 @@ decode :: BL.ByteString -> Either String DNSFormat decode bs = fst <$> runSGet decodeResponse bs ---------------------------------------------------------------- - -receiveDNSFormat :: Enumerator ByteString IO (DNSFormat, PState) - -> IO DNSFormat -receiveDNSFormat enum = fst <$> run_ (enum $$ iter) +receiveDNSFormat :: Source (ResourceT IO) ByteString -> IO DNSFormat +receiveDNSFormat src = fst <$> runResourceT (src $$ sink) where - iter = iterSGet decodeResponse + sink = sinkSGet decodeResponse ---------------------------------------------------------------- -- cgit v1.2.3