ioctl (empty) → 0.0.1
raw patch · 6 files changed
+189/−0 lines, 6 filesdep +basedep +networkdep +unixsetup-changed
Dependencies added: base, network, unix
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- ioctl.cabal +27/−0
- src-unix/Network/Socket/IOCtl.hs +55/−0
- src-unix/System/Posix/IOCtl.hs +55/−0
- src/System/IOControl.hs +28/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2009 Maciej Piechotka, John Lato++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ ioctl.cabal view
@@ -0,0 +1,27 @@+Name: ioctl+Version: 0.0.1+Synopsis: Type-safe I/O control package+Description: Package allowing type-safe I/O control+Category: Data, System+License: MIT+License-file: LICENSE+Author: Maciej Piechotka+Maintainer: uzytkownik2@gmail.com+Build-Type: Simple+Cabal-Version: >=1.4++Library+ Build-Depends: base >= 3 && < 5,+ network+ Exposed-Modules: Network.Socket.IOCtl+ Other-Modules: System.IOControl+ Extensions: FunctionalDependencies,+ MultiParamTypeClasses+ HS-Source-Dirs: src+ GHC-Options: -Wall++ if !os(windows)+ Build-Depends: unix+ Exposed-Modules: System.Posix.IOCtl+ Extensions: ForeignFunctionInterface+ HS-Source-Dirs: src-unix
+ src-unix/Network/Socket/IOCtl.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{- |+Module : $Header$+Description : ioctl wrapping+Copyright : (c) Maciej Piechotka+License : BSD3++Stability : none+Portability : portable++The module wrapps the ioctl system call for sockets.+-}+module Network.Socket.IOCtl+ (+ IOControl(..),+ ioctlsocket,+ ioctlsocket_,+ ioctlsocket',+ )+where++import Foreign+import Foreign.C+import Network.Socket+import System.IOControl++foreign import ccall "ioctl" c_ioctl :: CInt -> CInt -> Ptr () -> IO CInt++c_ioctl' :: IOControl req d => Socket -> req -> Ptr d -> IO ()+c_ioctl' f req p =+ throwErrnoIfMinus1_ "ioctl" $+ c_ioctl (fdSocket f) (ioctlReq req) (castPtr p)++-- | Calls a ioctl reading the structure after the call+ioctlsocket :: IOControl req d+ => Socket -- ^ The socket+ -> req -- ^ The request+ -> d -- ^ The data+ -> IO d -- ^ The data after the call+ioctlsocket f req d = with d $ \p -> c_ioctl' f req p >> peek p++-- | Call a ioctl ignoring the result+ioctlsocket_ :: IOControl req d+ => Socket -- ^ The socket+ -> req -- ^ The request+ -> d -- ^ The data+ -> IO ()+ioctlsocket_ f req d = with d $ \p -> c_ioctl' f req p++-- | Call a ioctl with uninitialized data+ioctlsocket' :: IOControl req d+ => Socket -- ^ The socket+ -> req -- ^ The request+ -> IO d -- ^ The data+ioctlsocket' f req = alloca $ \p -> c_ioctl' f req p >> peek p
+ src-unix/System/Posix/IOCtl.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE ForeignFunctionInterface #-}+{- |+Module : $Header$+Description : ioctl wrapping+Copyright : (c) Maciej Piechotka+License : BSD3++Stability : none+Portability : POSIX++The module wrapps the ioctl system call.+-}+module System.Posix.IOCtl+ (+ IOControl(..),+ ioctl,+ ioctl_,+ ioctl',+ )+where++import Foreign+import Foreign.C+import System.IOControl+import System.Posix++foreign import ccall "ioctl" c_ioctl :: CInt -> CInt -> Ptr () -> IO CInt++c_ioctl' :: IOControl req d => Fd -> req -> Ptr d -> IO ()+c_ioctl' f req p =+ throwErrnoIfMinus1_ "ioctl" $+ c_ioctl (fromIntegral f) (ioctlReq req) (castPtr p)++-- | Calls a ioctl reading the structure after the call+ioctl :: IOControl req d+ => Fd -- ^ The file descriptor + -> req -- ^ The request+ -> d -- ^ The data+ -> IO d -- ^ The data after the call+ioctl f req d = with d $ \p -> c_ioctl' f req p >> peek p++-- | Call a ioctl ignoring the result+ioctl_ :: IOControl req d+ => Fd -- ^ The file descriptor+ -> req -- ^ The request+ -> d -- ^ The data+ -> IO ()+ioctl_ f req d = with d $ \p -> c_ioctl' f req p++-- | Call a ioctl with uninitialized data+ioctl' :: IOControl req d+ => Fd -- ^ The file descriptor+ -> req -- ^ The request+ -> IO d -- ^ The data+ioctl' f req = alloca $ \p -> c_ioctl' f req p >> peek p
+ src/System/IOControl.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{- |+Module : $Header$+Description : ioctl wrapping+Copyright : (c) Maciej Piechotka+License : BSD3++Stability : none+Portability : portable++The module provides a type-safe mechanism for ioctl calls.+-}+module System.IOControl+ (+ IOControl(..),+ )+where++import Foreign+import Foreign.C++-- | Combines the request with data.+class Storable d => IOControl req d | req -> d where+ -- | Converts request to integer+ ioctlReq :: req -- ^ The request. Should be lazy in argument.+ -> CInt -- ^ The request code.+