【发布时间】:2012-04-22 00:23:51
【问题描述】:
我在 Haskell sendfile 包中找到了这段代码:
-- 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
拼接.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)
【问题讨论】:
-
我应该指出,这个外国进口应该不被标记为
unsafe。当标记为unsafe的外部函数阻塞时,它可以阻止其他线程运行(在使用-threaded的GHC 编译的程序中)。 -
@JoeyAdams 哦,非常感谢您指出这一点!我正在为我的代理服务器进行网络套接字的管道拼接的完美实现。我希望在 Linux 上使用它而不是读/写循环,我暂时仍会继续在其他操作系统上使用。
标签: c haskell types ffi preprocessor-directive