5

sendfile我在 Haskell包中找到了这段代码:

http://patch-tag.com/r/mae/sendfile/snapshot/current/content/pretty/src/Network/Socket/SendFile/Linux.hsc

-- 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)

4

1 回答 1

5

正如 scdvvc 所指出的,这使用了hsc2hs定义的 C 预处理宏来专门针对正在编译的系统定制代码。您需要使用hsc2hs来获取为您的代码定义的适当宏。

于 2012-04-09T16:39:21.453 回答