Permalink
Browse files

Project skeleton and simple bindings.

  • Loading branch information...
0 parents commit 80dd34530312f50cd5ecc4ee26e92faccb66c235 @hesselink committed Oct 10, 2010
Showing with 116 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +30 −0 LICENSE
  3. +2 −0 Setup.hs
  4. +35 −0 kqueue.cabal
  5. +48 −0 src/System/KQueue.chs
@@ -0,0 +1 @@
+dist/
30 LICENSE
@@ -0,0 +1,30 @@
+Copyright (c)2010, Erik Hesselink
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Erik Hesselink nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
@@ -0,0 +1,35 @@
+Name: kqueue
+Version: 0.1
+Synopsis: A binding to the kqueue event library.
+Description: A low-level binding to the kqueue library as
+ found in BSD and Mac OS X. It provides, among
+ other things, a way of monitoring files and
+ directories for changes.
+Homepage: http://github.com/hesselink/kqueue
+License: BSD3
+License-file: LICENSE
+Author: Erik Hesselink
+Maintainer: hesselink@gmail.com
+Category: System
+Build-type: Simple
+
+-- Extra files to be distributed with the package, such as examples or
+-- a README.
+-- Extra-source-files:
+
+-- Constraint on the version of Cabal needed to build this package.
+Cabal-version: >=1.2
+
+
+Library
+ Hs-Source-Dirs: src
+ Exposed-modules: System.KQueue
+ Build-depends: base == 4.*
+
+ -- Modules not exported by this package.
+ -- Other-modules:
+
+ Build-tools: c2hs
+ Extra-Libraries: c
+ Include-dirs: /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/
+ Includes: event.h
@@ -0,0 +1,48 @@
+{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls #-}
+module System.KQueue where
+
+#include <sys/event.h>
+
+import Control.Applicative
+import Foreign
+import Foreign.C
+
+-- | A kernel event queue.
+newtype KQueue = KQueue CInt -- The descriptor
+
+foreign import ccall "kqueue" kqueue_ :: IO CInt
+
+kqueue :: IO KQueue
+kqueue = KQueue <$> kqueue_
+
+data KEvent = KEvent
+ { ident :: CULong
+ , filter :: CShort
+ , flags :: CUShort
+ , fflags :: CUInt
+ , data_ :: CLong
+ , udata :: Ptr ()
+ }
+
+#c
+typedef struct kevent kevent_t;
+#endc
+
+instance Storable KEvent where
+ sizeOf _ = {#sizeof kevent_t #}
+ alignment _ = 24
+ peek e = KEvent <$> ({#get kevent_t->ident #} e)
+ <*> ({#get kevent_t->filter #} e)
+ <*> ({#get kevent_t->flags #} e)
+ <*> ({#get kevent_t->fflags #} e)
+ <*> ({#get kevent_t->data #} e)
+ <*> ({#get kevent_t->udata #} e)
+
+data TimeSpec
+
+foreign import ccall "kevent" kevent_ :: CInt -> Ptr KEvent -> CInt -> Ptr KEvent -> CInt -> Ptr TimeSpec -> IO CInt
+
+kevent :: KQueue -> [KEvent] -> [KEvent] -> TimeSpec -> IO ()
+kevent (KQueue kq) changelist eventlist timespec = do
+ kevent_ kq undefined undefined undefined undefined undefined
+ return ()

0 comments on commit 80dd345

Please sign in to comment.