module Main where import Network.Socket import System.Posix import System.IO import Foreign.C.Types import Foreign.Ptr import Control.Concurrent foreign import ccall unsafe "sendfile" c_sendfile :: Fd -> Fd -> COff -> CSize -> Ptr a -> Ptr COff -> CInt -> IO CInt processConnection h = do fd1 <- openFd name ReadOnly Nothing defaultFileFlags c_sendfile fd1 (Fd $ fdSocket h) (fromIntegral 0) (fromIntegral size) nullPtr nullPtr 0 closeFd fd1 sClose h where name = "/home/refugee/public_html/woo.c" size = 7020 mainLoop sock = do (h, addr) <- accept sock forkOS $ processConnection h mainLoop sock main = do sock <- socket AF_INET Stream 6 bindSocket sock $ SockAddrInet (fromIntegral 1234) (fromIntegral 0) listen sock 50 mainLoop sock