summaryrefslogtreecommitdiff
path: root/Network/StreamSocket.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Network/StreamSocket.hs')
-rw-r--r--Network/StreamSocket.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/Network/StreamSocket.hs b/Network/StreamSocket.hs
index f619e4d..42bdaf5 100644
--- a/Network/StreamSocket.hs
+++ b/Network/StreamSocket.hs
@@ -29,11 +29,15 @@ import Network.Stream
( Stream(..), ConnError(ErrorReset, ErrorMisc), Result
)
import Network.Socket
- ( Socket, getSocketOption, shutdown, send, recv, sClose
+ ( Socket, getSocketOption, shutdown
, ShutdownCmd(ShutdownBoth), SocketOption(SoError)
)
+import Network.Socket.ByteString (send, recv)
+import qualified Network.Socket
+ ( close )
import Network.HTTP.Base ( catchIO )
+import Network.HTTP.Utils ( fromUTF8BS, toUTF8BS )
import Control.Monad (liftM)
import Control.Exception as Exception (IOException)
import System.IO.Error (isEOFError)
@@ -50,7 +54,7 @@ handleSocketError sk e =
myrecv :: Socket -> Int -> IO String
myrecv sock len =
let handler e = if isEOFError e then return [] else ioError e
- in catchIO (recv sock len) handler
+ in catchIO (fmap fromUTF8BS (recv sock len)) handler
instance Stream Socket where
readBlock sk n = readBlockSocket sk n
@@ -59,7 +63,7 @@ instance Stream Socket where
close sk = do
-- This slams closed the connection (which is considered rude for TCP\/IP)
shutdown sk ShutdownBoth
- sClose sk
+ Network.Socket.close sk
closeOnEnd _sk _ = return () -- can't really deal with this, so do run the risk of leaking sockets here.
readBlockSocket :: Socket -> Int -> IO (Result String)
@@ -89,5 +93,5 @@ writeBlockSocket :: Socket -> String -> IO (Result ())
writeBlockSocket sk str = (liftM Right $ fn str) `catchIO` (handleSocketError sk)
where
fn [] = return ()
- fn x = send sk x >>= \i -> fn (drop i x)
+ fn x = send sk (toUTF8BS x) >>= \i -> fn (drop i x)