我發現這段代碼在哈斯克爾sendfile
包:'#type'在Haskell外部函數接口中的含義是什麼?
-- sendfile64 gives LFS support
foreign import ccall unsafe "sendfile64" c_sendfile
:: Fd -> Fd -> Ptr (#type off64_t) -> (#type size_t) -> IO (#type ssize_t)
1)什麼#type
意思和2)爲什麼我得到這個錯誤,
[1 of 1] Compiling Linux.Splice (splice.hs, splice.o)
splice.hs:40:12: parse error on input `type'
當我自己嘗試使用它如下?:
ghc --make splice.hs
個
splice.hs:
{-# LANGUAGE ForeignFunctionInterface #-}
module Linux.Splice where
import Data.Word
import System.Posix.Types
-- SPLICE
-- fcntl.h
-- ssize_t splice(
-- int fd_in,
-- loff_t* off_in,
-- int fd_out,
-- loff_t* off_out,
-- size_t len,
-- unsigned int flags
--);
foreign import ccall unsafe "fnctl.h splice" c_splice
:: Fd
-> Ptr (#type {- < parse error -} loff_t)
-> Fd
-> Ptr (#type loff_t)
-> (#type size_t)
-> Word
-> IO (#type ssize_t)
(使用GHC 7.4.x)
http://www.haskell.org/ghc/docs/latest/html/users_guide/hsc2hs.html – sdcvvc 2012-04-09 16:39:12
我應該指出,這個外國進口應該不**標記爲「不安全」。當一個外部函數標記爲'unsafe'時,它可以阻止其他線程運行(在用''thread''編譯的GHC程序中)。 – 2012-04-09 17:46:32
@JoeyAdams哦,非常感謝你指出了這一點!我正在研究我的代理服務器的管道拼接網絡套接字的優化實現。我希望在Linux上使用而不是讀/寫循環我仍然會繼續在其他操作系統上使用。 – 2012-04-09 18:46:26