Commit e59277de authored by Michael Hanus 's avatar Michael Hanus
Browse files

tools updated

parent 68d6230a
......@@ -14,6 +14,7 @@ optimize/.cpm/packages/flatcurry-2.0.0
optimize/.cpm/packages/frontend-exec-0.0.1
optimize/.cpm/packages/propertyfile-0.0.1
optimize/.cpm/packages/scc-0.0.1
optimize/.cpm/packages/socket-0.0.1
optimize/.cpm/packages/xml-2.0.0
# executables
......
......@@ -13,6 +13,7 @@
"flatcurry" : ">= 2.0.0",
"propertyfile" : ">= 0.0.1",
"scc" : ">= 0.0.1",
"socket" : ">= 0.0.1",
"xml" : ">= 2.0.0"
},
"compilerCompatibility": {
......
......@@ -5,7 +5,7 @@
--- by other Curry applications.
---
--- @author Heiko Hoffmann, Michael Hanus
--- @version January 2017
--- @version December 2018
--------------------------------------------------------------------------
module CASS.Server
......@@ -18,15 +18,17 @@ import ReadNumeric (readNat)
import Char (isSpace)
import Directory
import FileGoodies (splitDirectoryBaseName)
import FlatCurry.Types(QName)
import IO
import ReadShowTerm (readQTerm, showQTerm)
import Socket (Socket(..),listenOn,listenOnFresh,sClose,waitForSocketAccept)
import System (system, sleep, setEnviron, getArgs)
import Analysis.Logging (debugMessage)
import Analysis.Logging ( debugMessage )
import Analysis.ProgInfo
import Analysis.Types(Analysis,AOutFormat(..))
import Analysis.Types ( Analysis, AOutFormat(..) )
import FlatCurry.Types ( QName )
import Network.Socket ( Socket(..), listenOn, listenOnFresh
, close, waitForSocketAccept )
import CASS.Configuration
import CASS.Registry
import CASS.ServerFormats
......@@ -63,7 +65,7 @@ mainServer mbport = do
debugMessage 2 ("SERVER: port to workers: "++show workerport)
handles <- startWorkers numworkers workersocket serveraddress workerport []
serverLoop socket1 handles
sClose workersocket
close workersocket
else
serverLoop socket1 []
......@@ -122,7 +124,7 @@ analyzeModule ananame moduleName enforce aoutformat = do
handles <- startWorkers numworkers socket serveraddress port []
result <- runAnalysisWithWorkers ananame aoutformat enforce handles mname
stopWorkers handles
sClose socket
close socket
return result
else runAnalysisWithWorkers ananame aoutformat enforce [] mname
setCurrentDirectory curdir
......@@ -149,7 +151,7 @@ analyzeGeneric analysis moduleName = do
handles <- startWorkers numworkers socket serveraddress port []
result <- analyzeMain analysis mname handles False True
stopWorkers handles
sClose socket
close socket
return result
else
analyzeMain analysis mname [] False True
......@@ -269,7 +271,7 @@ serverLoopOnHandle socket1 whandles handle = do
stopWorkers whandles
sendServerResult handle ""
hClose handle
sClose socket1
close socket1
putStrLn "Stop Server"
removeServerPortNumber
where
......
......@@ -2,7 +2,7 @@
--- Implementation of the analysis computations on the server side
---
--- @author Heiko Hoffmann, Michael Hanus
--- @version January 2015
--- @version December 2018
------------------------------------------------------------------------
-- analysis computations on the server side
......@@ -11,7 +11,6 @@ module CASS.ServerFunctions where
import FlatCurry.Types (QName)
import FlatCurry.Goodies (progImports)
import Socket(Socket(..),listenOnFresh,sClose,waitForSocketAccept)
import IO(Handle(..),hClose,hFlush,hGetLine,hPutStrLn,hWaitForInput,hWaitForInputs)
import ReadShowTerm(readQTerm,showQTerm)
import System(system,sleep)
......
......@@ -2,17 +2,18 @@
--- Implementation of a worker client to analyze a module
---
--- @author Heiko Hoffmann, Michael Hanus
--- @version March 2013
--- @version December 2018
------------------------------------------------------------------------
module CASS.Worker(main, startWorker) where
import IO(Handle,hClose,hFlush,hWaitForInput,hPutStrLn,hGetLine)
import ReadShowTerm(readQTerm)
import Socket(connectToSocket)
import System(getArgs,setEnviron)
import Analysis.Logging ( debugMessage )
import Network.Socket ( connectToSocket )
import CASS.Configuration ( waitTime, getDefaultPath )
import CASS.Registry ( lookupRegAnaWorker )
import CASS.ServerFunctions ( WorkerMessage(..) )
......
Copyright (c) 2018, Michael Hanus
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. 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.
3. Neither the names of the copyright holders nor the names of its
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
HOLDER 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.
socket
======
This package contains the library `Network.Socket`
to support network programming with sockets.
{
"name": "socket",
"version": "0.0.1",
"author": "Michael Hanus <mh@informatik.uni-kiel.de>",
"synopsis": "Library for programming with sockets",
"category": [ "Network" ],
"license": "BSD-3-Clause",
"licenseFile": "LICENSE",
"dependencies": {
"base" : ">= 1.0.0, < 2.0.0"
},
"compilerCompatibility": {
"pakcs": ">= 2.0.0",
"kics2": ">= 2.0.0"
},
"exportedModules": [ "Network.Socket" ],
"source": {
"git": "https://git.ps.informatik.uni-kiel.de/curry-packages/socket.git",
"tag": "$version"
}
}
------------------------------------------------------------------------------
--- Library to support network programming with sockets.
--- In standard applications, the server side uses the operations
--- `listenOn` and `socketAccept` to provide some service
--- on a socket, and the client side uses the operation
--- `connectToSocket` to request a service.
---
--- @author Michael Hanus
--- @version December 2018
------------------------------------------------------------------------------
module Network.Socket
(Socket, listenOn, listenOnFresh,
accept, waitForSocketAccept, close, connectToSocket)
where
import IO (Handle)
--- The abstract type of sockets.
external data Socket
---------------------------------------------------------------------
-- Server side operations:
--- Creates a server side socket bound to a given port number.
listenOn :: Int -> IO Socket
listenOn port = prim_listenOn $# port
prim_listenOn :: Int -> IO Socket
prim_listenOn external
--- Creates a server side socket bound to a free port.
--- The port number and the socket is returned.
listenOnFresh :: IO (Int,Socket)
listenOnFresh external
--- Returns a connection of a client to a socket.
--- The connection is returned as a pair consisting of a string identifying
--- the client (the format of this string is implementation-dependent)
--- and a handle to a stream communication with the client.
--- The handle is both readable and writable.
accept :: Socket -> IO (String,Handle)
accept s = prim_socketAccept $## s
prim_socketAccept :: Socket -> IO (String,Handle)
prim_socketAccept external
--- Waits until a connection of a client to a socket is available.
--- If no connection is available within the time limit, it returns Nothing,
--- otherwise the connection is returned as a pair consisting
--- of a string identifying the client
--- (the format of this string is implementation-dependent)
--- and a handle to a stream communication with the client.
--- @param socket - a socket
--- @param timeout - milliseconds to wait for input (< 0 : no time out)
waitForSocketAccept :: Socket -> Int -> IO (Maybe (String,Handle))
waitForSocketAccept s timeout = (prim_waitForSocketAccept $## s) $# timeout
prim_waitForSocketAccept :: Socket -> Int -> IO (Maybe (String,Handle))
prim_waitForSocketAccept external
--- Closes a server socket.
close :: Socket -> IO ()
close s = prim_sClose $## s
prim_sClose :: Socket -> IO ()
prim_sClose external
---------------------------------------------------------------------
-- Client side operations:
--- Creates a new connection to a Unix socket.
--- @param host - the host name of the connection
--- @param port - the port number of the connection
--- @return the handle of the stream (connected to the port port@host)
--- which is both readable and writable
connectToSocket :: String -> Int -> IO Handle
connectToSocket host port = (prim_connectToSocket $## host) $# port
prim_connectToSocket :: String -> Int -> IO Handle
prim_connectToSocket external
---------------------------------------------------------------------
{-# LANGUAGE MultiParamTypeClasses #-}
import Control.Concurrent
import Control.Monad (when)
import Network
import Network.Socket hiding (sClose)
type C_Socket = PrimData Socket
instance ConvertCurryHaskell Curry_Prelude.C_Int PortID where
toCurry (PortNumber i) = toCurry (toInteger i)
fromCurry i = PortNumber (fromInteger (fromCurry i))
external_d_C_prim_listenOn :: Curry_Prelude.C_Int -> Cover -> ConstStore -> Curry_Prelude.C_IO C_Socket
external_d_C_prim_listenOn i _ _ = toCurry listenOn i
external_d_C_listenOnFresh :: Cover -> ConstStore -> Curry_Prelude.C_IO (Curry_Prelude.OP_Tuple2 Curry_Prelude.C_Int C_Socket)
external_d_C_listenOnFresh _ _ = toCurry listenOnFreshPort
where
listenOnFreshPort :: IO (PortID,Socket)
listenOnFreshPort = do
s <- listenOn (PortNumber aNY_PORT)
p <- Network.socketPort s
return (p,s)
external_d_C_prim_socketAccept :: C_Socket
-> Cover -> ConstStore -> Curry_Prelude.C_IO (Curry_Prelude.OP_Tuple2 Curry_Prelude.C_String Curry_IO.C_Handle)
external_d_C_prim_socketAccept socket _ _ =
toCurry (\s -> Network.accept s >>= \ (h,s,_) -> return (s,OneHandle h)) socket
external_d_C_prim_waitForSocketAccept :: C_Socket -> Curry_Prelude.C_Int
-> Cover -> ConstStore -> Curry_Prelude.C_IO (Curry_Prelude.C_Maybe (Curry_Prelude.OP_Tuple2 (Curry_Prelude.OP_List Curry_Prelude.C_Char) Curry_IO.C_Handle))
external_d_C_prim_waitForSocketAccept s i _ _ = toCurry wait s i
wait :: Socket -> Int -> IO (Maybe (String, CurryHandle))
wait s t =
if t < 0
then Network.accept s >>= \ (h, s, _) -> return (Just (s, OneHandle h))
else do
mv <- newEmptyMVar
tacc <- forkIO (Network.accept s >>= \ (h, s, _) ->
putMVar mv (Just (s, OneHandle h)))
ttim <- forkIO (delay ((fromIntegral t :: Integer) * 1000)
>> putMVar mv Nothing)
res <- takeMVar mv
maybe (killThread tacc) (\_ -> killThread ttim) res
return res
-- Like 'threadDelay', but not bounded by an 'Int'
delay :: Integer -> IO ()
delay time = do
let maxWait = min time $ toInteger (maxBound :: Int)
threadDelay $ fromInteger maxWait
when (maxWait /= time) $ delay (time - maxWait)
external_d_C_prim_sClose :: C_Socket -> Cover -> ConstStore -> Curry_Prelude.C_IO Curry_Prelude.OP_Unit
external_d_C_prim_sClose s _ _ = toCurry sClose s
external_d_C_prim_connectToSocket :: Curry_Prelude.C_String -> Curry_Prelude.C_Int
-> Cover -> ConstStore -> Curry_Prelude.C_IO Curry_IO.C_Handle
external_d_C_prim_connectToSocket str i _ _ =
toCurry (\ s i -> connectTo s i >>= return . OneHandle) str i
<?xml version="1.0" standalone="no"?>
<!DOCTYPE primitives SYSTEM "http://www.informatik.uni-kiel.de/~pakcs/primitives.dtd">
<primitives>
<primitive name="prim_listenOn" arity="1">
<library>prim_socket</library>
<entry>prim_listenOn</entry>
</primitive>
<primitive name="listenOnFresh" arity="0">
<library>prim_socket</library>
<entry>prim_listenOnFresh</entry>
</primitive>
<primitive name="prim_socketAccept" arity="1">
<library>prim_socket</library>
<entry>prim_socketAccept</entry>
</primitive>
<primitive name="prim_waitForSocketAccept" arity="2">
<library>prim_socket</library>
<entry>prim_waitForSocketAccept</entry>
</primitive>
<primitive name="prim_sClose" arity="1">
<library>prim_socket</library>
<entry>prim_sClose</entry>
</primitive>
<primitive name="prim_connectToSocket" arity="2">
<library>prim_socket</library>
<entry>prim_connectToSocket</entry>
</primitive>
</primitives>
......@@ -67,6 +67,9 @@ cd .cpm/packages
PKGV=`ls -d scc-*`
mv $PKGV scc
ln -s scc $PKGV
PKGV=`ls -d socket-*`
mv $PKGV socket
ln -s socket $PKGV
PKGV=`ls -d frontend-exec-*`
mv $PKGV frontend-exec
ln -s frontend-exec $PKGV
......
......@@ -13,6 +13,7 @@
"flatcurry" : ">= 2.0.0",
"propertyfile" : ">= 0.0.1",
"scc" : ">= 0.0.1",
"socket" : ">= 0.0.1",
"xml" : ">= 2.0.0"
},
"compilerCompatibility": {
......
......@@ -5,7 +5,7 @@
--- by other Curry applications.
---
--- @author Heiko Hoffmann, Michael Hanus
--- @version January 2017
--- @version December 2018
--------------------------------------------------------------------------
module CASS.Server
......@@ -18,15 +18,17 @@ import ReadNumeric (readNat)
import Char (isSpace)
import Directory
import FileGoodies (splitDirectoryBaseName)
import FlatCurry.Types(QName)
import IO
import ReadShowTerm (readQTerm, showQTerm)
import Socket (Socket(..),listenOn,listenOnFresh,sClose,waitForSocketAccept)
import System (system, sleep, setEnviron, getArgs)
import Analysis.Logging (debugMessage)
import Analysis.Logging ( debugMessage )
import Analysis.ProgInfo
import Analysis.Types(Analysis,AOutFormat(..))
import Analysis.Types ( Analysis, AOutFormat(..) )
import FlatCurry.Types ( QName )
import Network.Socket ( Socket(..), listenOn, listenOnFresh
, close, waitForSocketAccept )
import CASS.Configuration
import CASS.Registry
import CASS.ServerFormats
......@@ -63,7 +65,7 @@ mainServer mbport = do
debugMessage 2 ("SERVER: port to workers: "++show workerport)
handles <- startWorkers numworkers workersocket serveraddress workerport []
serverLoop socket1 handles
sClose workersocket
close workersocket
else
serverLoop socket1 []
......@@ -122,7 +124,7 @@ analyzeModule ananame moduleName enforce aoutformat = do
handles <- startWorkers numworkers socket serveraddress port []
result <- runAnalysisWithWorkers ananame aoutformat enforce handles mname
stopWorkers handles
sClose socket
close socket
return result
else runAnalysisWithWorkers ananame aoutformat enforce [] mname
setCurrentDirectory curdir
......@@ -149,7 +151,7 @@ analyzeGeneric analysis moduleName = do
handles <- startWorkers numworkers socket serveraddress port []
result <- analyzeMain analysis mname handles False True
stopWorkers handles
sClose socket
close socket
return result
else
analyzeMain analysis mname [] False True
......@@ -269,7 +271,7 @@ serverLoopOnHandle socket1 whandles handle = do
stopWorkers whandles
sendServerResult handle ""
hClose handle
sClose socket1
close socket1
putStrLn "Stop Server"
removeServerPortNumber
where
......
......@@ -2,7 +2,7 @@
--- Implementation of the analysis computations on the server side
---
--- @author Heiko Hoffmann, Michael Hanus
--- @version January 2015
--- @version December 2018
------------------------------------------------------------------------
-- analysis computations on the server side
......@@ -11,7 +11,6 @@ module CASS.ServerFunctions where
import FlatCurry.Types (QName)
import FlatCurry.Goodies (progImports)
import Socket(Socket(..),listenOnFresh,sClose,waitForSocketAccept)
import IO(Handle(..),hClose,hFlush,hGetLine,hPutStrLn,hWaitForInput,hWaitForInputs)
import ReadShowTerm(readQTerm,showQTerm)
import System(system,sleep)
......
......@@ -2,17 +2,18 @@
--- Implementation of a worker client to analyze a module
---
--- @author Heiko Hoffmann, Michael Hanus
--- @version March 2013
--- @version December 2018
------------------------------------------------------------------------
module CASS.Worker(main, startWorker) where
import IO(Handle,hClose,hFlush,hWaitForInput,hPutStrLn,hGetLine)
import ReadShowTerm(readQTerm)
import Socket(connectToSocket)
import System(getArgs,setEnviron)
import Analysis.Logging ( debugMessage )
import Network.Socket ( connectToSocket )
import CASS.Configuration ( waitTime, getDefaultPath )
import CASS.Registry ( lookupRegAnaWorker )
import CASS.ServerFunctions ( WorkerMessage(..) )
......
Copyright (c) 2018, Michael Hanus
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. 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.
3. Neither the names of the copyright holders nor the names of its
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
HOLDER 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.
socket
======
This package contains the library `Network.Socket`
to support network programming with sockets.
{
"name": "socket",
"version": "0.0.1",
"author": "Michael Hanus <mh@informatik.uni-kiel.de>",
"synopsis": "Library for programming with sockets",
"category": [ "Network" ],
"license": "BSD-3-Clause",
"licenseFile": "LICENSE",
"dependencies": {
"base" : ">= 1.0.0, < 2.0.0"
},
"compilerCompatibility": {
"pakcs": ">= 2.0.0",
"kics2": ">= 2.0.0"
},
"exportedModules": [ "Network.Socket" ],
"source": {
"git": "https://git.ps.informatik.uni-kiel.de/curry-packages/socket.git",
"tag": "$version"
}
}
------------------------------------------------------------------------------
--- Library to support network programming with sockets.
--- In standard applications, the server side uses the operations
--- `listenOn` and `socketAccept` to provide some service
--- on a socket, and the client side uses the operation
--- `connectToSocket` to request a service.
---
--- @author Michael Hanus
--- @version December 2018
------------------------------------------------------------------------------
module Network.Socket
(Socket, listenOn, listenOnFresh,
accept, waitForSocketAccept, close, connectToSocket)
where
import IO (Handle)
--- The abstract type of sockets.
external data Socket
---------------------------------------------------------------------
-- Server side operations:
--- Creates a server side socket bound to a given port number.
listenOn :: Int -> IO Socket
listenOn port = prim_listenOn $# port
prim_listenOn :: Int -> IO Socket
prim_listenOn external
--- Creates a server side socket bound to a free port.
--- The port number and the socket is returned.
listenOnFresh :: IO (Int,Socket)
listenOnFresh external
--- Returns a connection of a client to a socket.
--- The connection is returned as a pair consisting of a string identifying
--- the client (the format of this string is implementation-dependent)
--- and a handle to a stream communication with the client.
--- The handle is both readable and writable.
accept :: Socket -> IO (String,Handle)
accept s = prim_socketAccept $## s
prim_socketAccept :: Socket -> IO (String,Handle)
prim_socketAccept external
--- Waits until a connection of a client to a socket is available.
--- If no connection is available within the time limit, it returns Nothing,
--- otherwise the connection is returned as a pair consisting
--- of a string identifying the client
--- (the format of this string is implementation-dependent)
--- and a handle to a stream communication with the client.
--- @param socket - a socket
--- @param timeout - milliseconds to wait for input (< 0 : no time out)
waitForSocketAccept :: Socket -> Int -> IO (Maybe (String,Handle))
waitForSocketAccept s timeout = (prim_waitForSocketAccept $## s) $# timeout
prim_waitForSocketAccept :: Socket -> Int -> IO (Maybe (String,Handle))
prim_waitForSocketAccept external
--- Closes a server socket.
close :: Socket -> IO ()
close s = prim_sClose $## s
prim_sClose :: Socket -> IO ()
prim_sClose external
---------------------------------------------------------------------
-- Client side operations:
--- Creates a new connection to a Unix socket.
--- @param host - the host name of the connection
--- @param port - the port number of the connection
--- @return the handle of the stream (connected to the port port@host)
--- which is both readable and writable
connectToSocket :: String -> Int -> IO Handle
connectToSocket host port = (prim_connectToSocket $## host) $# port
prim_connectToSocket :: String -> Int -> IO Handle
prim_connectToSocket external
---------------------------------------------------------------------