From d269f71a8d89e45da6f1ba3048ff31e9d0c05f10 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Tue, 28 May 2024 17:24:22 +0200 Subject: [PATCH 01/11] Adds the NoTrace dependency files directly to the project The NoTrace library seemed to be unmaintained and required a very old version of ghc. By adding the files directly to the project, the maximum version of the compiler could be increased in the NoTrace.cabal file. --- copied_dependencies/NoTrace-0.3.0.4/LICENSE | 20 ++++++ .../NoTrace-0.3.0.4/NoTrace.cabal | 36 ++++++++++ copied_dependencies/NoTrace-0.3.0.4/Setup.hs | 2 + .../NoTrace-0.3.0.4/src/Debug/NoTrace.hs | 70 +++++++++++++++++++ .../NoTrace-0.3.0.4/test/Main.hs | 13 ++++ 5 files changed, 141 insertions(+) create mode 100644 copied_dependencies/NoTrace-0.3.0.4/LICENSE create mode 100644 copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal create mode 100644 copied_dependencies/NoTrace-0.3.0.4/Setup.hs create mode 100644 copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs create mode 100644 copied_dependencies/NoTrace-0.3.0.4/test/Main.hs diff --git a/copied_dependencies/NoTrace-0.3.0.4/LICENSE b/copied_dependencies/NoTrace-0.3.0.4/LICENSE new file mode 100644 index 0000000..b939533 --- /dev/null +++ b/copied_dependencies/NoTrace-0.3.0.4/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Cindy Wang + +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. diff --git a/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal b/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal new file mode 100644 index 0000000..3584cde --- /dev/null +++ b/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal @@ -0,0 +1,36 @@ +-- Initial NoTrace.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ + +name: NoTrace +version: 0.3.0.4 +synopsis: Remove all the functions come from Debug.Trace after debugging +description: This module introduce functions with identical types with functions in the Debug.Trace. + When completing the debug process, + use this module to overwrite and silently remove all the tracing functions. +homepage: https://github.com/CindyLinz/Haskell-NoTrace +license: MIT +license-file: LICENSE +author: Cindy Wang (CindyLinz) +maintainer: cindylinz@gmail.com +-- copyright: +category: Development +build-type: Simple +cabal-version: >=1.8 + +source-repository head + type: git + location: git@github.com:CindyLinz/Haskell-NoTrace.git + +library + exposed-modules: Debug.NoTrace + -- other-modules: + hs-source-dirs: src + build-depends: base >=4.7 + +Test-Suite main + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: test + , src + build-depends: base >=4.5 + ghc-options: -O2 diff --git a/copied_dependencies/NoTrace-0.3.0.4/Setup.hs b/copied_dependencies/NoTrace-0.3.0.4/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/copied_dependencies/NoTrace-0.3.0.4/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs b/copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs new file mode 100644 index 0000000..ff4516e --- /dev/null +++ b/copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs @@ -0,0 +1,70 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Debug.NoTrace +-- Copyright : (c) Cindy Wang (CindyLinz) 2013 +-- License : MIT +-- +-- Maintainer : Cindy Wang (CindyLinz) +-- Stability : provisional +-- Portability : portable +-- +-- This module introduce functions that have identical types with functions in the "Debug.Trace" module. +-- +-- You might write some programs like this: +-- +-- > import Debug.Trace +-- > +-- > fib 0 = 1 +-- > fib 1 = 1 +-- > fib n = ("fib " ++ show n) `trace` fib (n - 1) + fib (n - 2) +-- +-- And after you finish the debugging process, just change the line +-- +-- > import Debug.Trace +-- +-- into +-- +-- > import Debug.NoTrace +-- +-- Then all the tracing functions are silently removed. +------------------------------------------------------------------------------- +module Debug.NoTrace where + +trace :: String -> a -> a +trace _ = id + +traceId :: String -> String +traceId = id + +traceShow :: Show a => a -> b -> b +traceShow _ = id + +traceShowId :: Show a => a -> a +traceShowId = id + +traceStack :: String -> a -> a +traceStack _ = id + +traceIO :: String -> IO () +traceIO _ = return () + +traceM :: Monad m => String -> m () +traceM _ = return () + +traceShowM :: (Show a, Monad m) => a -> m () +traceShowM _ = return () + +putTraceMsg :: String -> IO () +putTraceMsg _ = return () + +traceEvent :: String -> a -> a +traceEvent _ = id + +traceEventIO :: String -> IO () +traceEventIO _ = return () + +traceMarker :: String -> a -> a +traceMarker _ = id + +traceMarkerIO :: String -> IO () +traceMarkerIO _ = return () diff --git a/copied_dependencies/NoTrace-0.3.0.4/test/Main.hs b/copied_dependencies/NoTrace-0.3.0.4/test/Main.hs new file mode 100644 index 0000000..b7b9be7 --- /dev/null +++ b/copied_dependencies/NoTrace-0.3.0.4/test/Main.hs @@ -0,0 +1,13 @@ +module Main where + +import Debug.NoTrace + +fib :: Int -> Int +fib 0 = 1 +fib 1 = 1 +fib n = traceStack "FIB" $ trace "fib " $ n `traceShow` fib (n - 1) + fib (n - 2) + +main = do + traceIO "begin" + putStrLn $ show (fib 5) + traceIO "end" From 40ec4a8807ae31abe73b54ef8c257f4917fe7415 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Tue, 28 May 2024 17:27:44 +0200 Subject: [PATCH 02/11] Removes some depricated function calls to Network.Socket library --- .gitignore | 1 + src/Network/TextViaSockets.hs | 23 ++++++++++++++++++----- stack.yaml | 7 ++++++- stack.yaml.lock | 26 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 stack.yaml.lock diff --git a/.gitignore b/.gitignore index 3940279..47b939a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .stack-work/ *.cabal +!/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal *~ *.class TAGS diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 812b120..5511322 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -49,7 +49,6 @@ import Control.Exception.Base import Data.Foldable import Control.Retry import Control.Monad.Catch (Handler) -import Data.Monoid #ifdef DEBUG import Debug.Trace @@ -105,11 +104,24 @@ retryCnect act = recovering connectRetryPolicy [ioExceptionHandler] (const act) -- reached. acceptOn :: PortNumber -> IO Connection acceptOn p = retryCnect $ do - sock <- socket AF_INET Stream 0 + addr <- resolvePort p + sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) traceIO $ "TextViaSockets: Accepting a connection on port " ++ show p setSocketOption sock ReuseAddr 1 - bind sock (SockAddrInet p iNADDR_ANY) + bind sock (addrAddress addr) acceptOnSocket sock + +-- | Resolves a portnumber to the SockAddr object needed for many functions from the Network.Socket library +-- Implementation is based on example code from the Network.Socket library. +resolvePort :: PortNumber -> IO AddrInfo +resolvePort port = do + let hints = defaultHints { + addrFamily = AF_INET + , addrSocketType = Stream + } + addr:_ <- getAddrInfo (Just hints) Nothing (Just $ show port) + return addr + -- | Like @acceptOn@ but it takes a bound socket as parameter. acceptOnSocket :: Socket -> IO Connection @@ -126,9 +138,10 @@ acceptOnSocket sock = retryCnect $ do -- | Get a free socket from the operating system. getFreeSocket :: IO Socket getFreeSocket = retryCnect $ do - sock <- socket AF_INET Stream 0 + addr <- resolvePort defaultPort + sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) setSocketOption sock ReuseAddr 1 - bind sock (SockAddrInet aNY_PORT iNADDR_ANY) + bind sock (addrAddress addr) return sock -- | Connect to the given host and service name (usually a port number). diff --git a/stack.yaml b/stack.yaml index 57ee885..749495a 100644 --- a/stack.yaml +++ b/stack.yaml @@ -15,7 +15,7 @@ # resolver: # name: custom-snapshot # location: "./custom-snapshot.yaml" -resolver: lts-10.0 +resolver: lts-18.28 # User packages to be built. # Various formats can be used as shown in the example below. @@ -37,6 +37,11 @@ resolver: lts-10.0 # will not be run. This is useful for tweaking upstream packages. packages: - . + +extra-deps: +- copied_dependencies/NoTrace-0.3.0.4 +- MissingH-1.5.0.1 +- network-2.8.0.1 # Dependency packages to be pulled from upstream that are not in the resolver # (e.g., acme-missiles-0.3) # extra-deps: [] diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..ec0467a --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,26 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: +- completed: + hackage: MissingH-1.5.0.1@sha256:34bdc3ddc94a5c58d76d3c36bc7af052213c2584492cf81f7b005c03b210a985,4791 + pantry-tree: + sha256: a708a8d90e6370fb4150d6eb45cb88034660c56c7ac799c27211fa6fc253af68 + size: 5272 + original: + hackage: MissingH-1.5.0.1 +- completed: + hackage: network-2.8.0.1@sha256:a79f3cf88b2623d5f2e7a8fc7962055f6858d6beb6d13c2aef43c20a5060cf28,3034 + pantry-tree: + sha256: 151e632248940bc4cd9e9ee420c8026ab6f2e3315139c32116ca083c60382b67 + size: 2488 + original: + hackage: network-2.8.0.1 +snapshots: +- completed: + sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68 + size: 590100 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml + original: lts-18.28 From a045303405cc3a7a9ccc156c16363e223c0b649d Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Thu, 30 May 2024 12:24:51 +0200 Subject: [PATCH 03/11] Replaces closeIfOpen behaviour with close' function from Network.Socket library. Network.Socket.close' already seems to cover most if not all functionality of the old custom closeIfOpen function. The old function was using several depricated apis, and was therfore no longer maintainable. Also added a test to check if the new implementation of getfreeSocket can sucessfully create multiple sockets, instead of creating multiple instances of the same socket. --- src/Network/TextViaSockets.hs | 15 ++------------- test/Network/TextViaSocketsSpec.hs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 5511322..858950d 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -32,7 +32,6 @@ module Network.TextViaSockets ) where import Network.Socket hiding (recv, close, send) -import qualified Network.Socket as Socket import Network.Socket.ByteString import Data.Text (Text) import qualified Data.Text as T @@ -252,21 +251,11 @@ close :: Connection -> IO () close Connection{connSock, serverSock, socketReaderTid} = tryClose `catch` handler where tryClose = do - closeIfOpen connSock + close' connSock traceIO $ "TextViaSockets: Closing server socket " ++ show serverSock - traverse_ closeIfOpen serverSock + traverse_ close' serverSock killThread socketReaderTid traceIO "TextViaSockets: Connection closed" - closeIfOpen sock = do - let MkSocket _ _ _ _ stMV = sock - st <- readMVar stMV - case st of - Closed -> return () - _ -> do - pn <- socketPort sock - traceIO $ "TextViaSockets: Closing connection on " ++ show pn - ++ " (" ++ show sock ++ ")" - Socket.close sock handler :: IOException -> IO () handler ex = do traceIO $ "TextViaSockets: exception while closing the socket: " diff --git a/test/Network/TextViaSocketsSpec.hs b/test/Network/TextViaSocketsSpec.hs index 08298e1..3dd0da3 100644 --- a/test/Network/TextViaSocketsSpec.hs +++ b/test/Network/TextViaSocketsSpec.hs @@ -4,6 +4,7 @@ module Network.TextViaSocketsSpec (spec) where import Control.Concurrent import Data.Text (Text) import Network.Socket hiding (close) +import qualified Network.Socket (close) import Control.Exception.Base hiding (assert) import Control.Concurrent.Async import qualified Data.Text as T @@ -149,3 +150,14 @@ spec = do close svrConn close svrConn close cliConn + describe "Creating:" $ do + it "multiple sockets can be created" $ do + sock1 <- getFreeSocket + sock2 <- getFreeSocket + (SockAddrInet port1 host1) <- getSocketName sock1 + (SockAddrInet port2 host2) <- getSocketName sock2 + (port1,port2,host1,host2) `shouldSatisfy` (\(p1,p2,h1,h2)-> p1 /= p2 || h1 /= h2) + print (port1,port2,host1,host2) + Network.Socket.close sock1 + Network.Socket.close sock2 + From e1fad08642b0dfb64a5e504c2b6e4b15794552b9 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Thu, 30 May 2024 13:30:03 +0200 Subject: [PATCH 04/11] Remove specific older version requirement for Network.Socket library --- src/Network/TextViaSockets.hs | 2 +- stack.yaml | 2 +- stack.yaml.lock | 7 ------- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 858950d..66e8492 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -31,7 +31,7 @@ module Network.TextViaSockets , close ) where -import Network.Socket hiding (recv, close, send) +import Network.Socket hiding (close) import Network.Socket.ByteString import Data.Text (Text) import qualified Data.Text as T diff --git a/stack.yaml b/stack.yaml index 749495a..52d13b0 100644 --- a/stack.yaml +++ b/stack.yaml @@ -41,7 +41,7 @@ packages: extra-deps: - copied_dependencies/NoTrace-0.3.0.4 - MissingH-1.5.0.1 -- network-2.8.0.1 +# - network-2.8.0.1 # Dependency packages to be pulled from upstream that are not in the resolver # (e.g., acme-missiles-0.3) # extra-deps: [] diff --git a/stack.yaml.lock b/stack.yaml.lock index ec0467a..6f87fb1 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -11,13 +11,6 @@ packages: size: 5272 original: hackage: MissingH-1.5.0.1 -- completed: - hackage: network-2.8.0.1@sha256:a79f3cf88b2623d5f2e7a8fc7962055f6858d6beb6d13c2aef43c20a5060cf28,3034 - pantry-tree: - sha256: 151e632248940bc4cd9e9ee420c8026ab6f2e3315139c32116ca083c60382b67 - size: 2488 - original: - hackage: network-2.8.0.1 snapshots: - completed: sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68 From 18c69816e60951c41b0958f0666be61e1018811c Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Thu, 30 May 2024 13:35:11 +0200 Subject: [PATCH 05/11] Remove specific older version requirment for MissingH --- stack.yaml | 2 -- stack.yaml.lock | 9 +-------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/stack.yaml b/stack.yaml index 52d13b0..9370dda 100644 --- a/stack.yaml +++ b/stack.yaml @@ -40,8 +40,6 @@ packages: extra-deps: - copied_dependencies/NoTrace-0.3.0.4 -- MissingH-1.5.0.1 -# - network-2.8.0.1 # Dependency packages to be pulled from upstream that are not in the resolver # (e.g., acme-missiles-0.3) # extra-deps: [] diff --git a/stack.yaml.lock b/stack.yaml.lock index 6f87fb1..da10c3e 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -3,14 +3,7 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: -- completed: - hackage: MissingH-1.5.0.1@sha256:34bdc3ddc94a5c58d76d3c36bc7af052213c2584492cf81f7b005c03b210a985,4791 - pantry-tree: - sha256: a708a8d90e6370fb4150d6eb45cb88034660c56c7ac799c27211fa6fc253af68 - size: 5272 - original: - hackage: MissingH-1.5.0.1 +packages: [] snapshots: - completed: sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68 From fbd55018147c28413775c8c6fa7c08923d097f74 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Thu, 30 May 2024 13:40:47 +0200 Subject: [PATCH 06/11] Increase version number --- package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.yaml b/package.yaml index f703b14..b83d809 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: text-via-sockets -version: 0.1.0.0 +version: 0.1.1.0 github: "capitanbatata/text-via-sockets" license: BSD3 author: "Damian Nadales" From 1d069e8660ddfcbb95ed68af72497f4d19bbd170 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Fri, 7 Jun 2024 12:14:38 +0200 Subject: [PATCH 07/11] Remove copied dependencies from list of package dependencies, which resulted in problems when using this library in other projects. --- .../NoTrace-0.3.0.4/NoTrace.cabal | 36 ------------------- copied_dependencies/NoTrace-0.3.0.4/Setup.hs | 2 -- .../NoTrace-0.3.0.4/test/Main.hs | 13 ------- package.yaml | 2 -- .../Copied_dependencies/Debug}/LICENSE | 0 .../Copied_dependencies}/Debug/NoTrace.hs | 8 ++--- src/Network/TextViaSockets.hs | 2 +- stack.yaml | 3 +- test/Network/TextViaSocketsSpec.hs | 2 +- 9 files changed, 7 insertions(+), 61 deletions(-) delete mode 100644 copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal delete mode 100644 copied_dependencies/NoTrace-0.3.0.4/Setup.hs delete mode 100644 copied_dependencies/NoTrace-0.3.0.4/test/Main.hs rename {copied_dependencies/NoTrace-0.3.0.4 => src/Copied_dependencies/Debug}/LICENSE (100%) rename {copied_dependencies/NoTrace-0.3.0.4/src => src/Copied_dependencies}/Debug/NoTrace.hs (88%) diff --git a/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal b/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal deleted file mode 100644 index 3584cde..0000000 --- a/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal +++ /dev/null @@ -1,36 +0,0 @@ --- Initial NoTrace.cabal generated by cabal init. For further --- documentation, see http://haskell.org/cabal/users-guide/ - -name: NoTrace -version: 0.3.0.4 -synopsis: Remove all the functions come from Debug.Trace after debugging -description: This module introduce functions with identical types with functions in the Debug.Trace. - When completing the debug process, - use this module to overwrite and silently remove all the tracing functions. -homepage: https://github.com/CindyLinz/Haskell-NoTrace -license: MIT -license-file: LICENSE -author: Cindy Wang (CindyLinz) -maintainer: cindylinz@gmail.com --- copyright: -category: Development -build-type: Simple -cabal-version: >=1.8 - -source-repository head - type: git - location: git@github.com:CindyLinz/Haskell-NoTrace.git - -library - exposed-modules: Debug.NoTrace - -- other-modules: - hs-source-dirs: src - build-depends: base >=4.7 - -Test-Suite main - type: exitcode-stdio-1.0 - main-is: Main.hs - hs-source-dirs: test - , src - build-depends: base >=4.5 - ghc-options: -O2 diff --git a/copied_dependencies/NoTrace-0.3.0.4/Setup.hs b/copied_dependencies/NoTrace-0.3.0.4/Setup.hs deleted file mode 100644 index 9a994af..0000000 --- a/copied_dependencies/NoTrace-0.3.0.4/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/copied_dependencies/NoTrace-0.3.0.4/test/Main.hs b/copied_dependencies/NoTrace-0.3.0.4/test/Main.hs deleted file mode 100644 index b7b9be7..0000000 --- a/copied_dependencies/NoTrace-0.3.0.4/test/Main.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Main where - -import Debug.NoTrace - -fib :: Int -> Int -fib 0 = 1 -fib 1 = 1 -fib n = traceStack "FIB" $ trace "fib " $ n `traceShow` fib (n - 1) + fib (n - 2) - -main = do - traceIO "begin" - putStrLn $ show (fib 5) - traceIO "end" diff --git a/package.yaml b/package.yaml index b83d809..f3f8b4b 100644 --- a/package.yaml +++ b/package.yaml @@ -30,7 +30,6 @@ library: dependencies: - bytestring - stm - - NoTrace - retry - exceptions - text @@ -70,7 +69,6 @@ tests: - QuickCheck - quickcheck-text - async - - NoTrace - text - text-via-sockets diff --git a/copied_dependencies/NoTrace-0.3.0.4/LICENSE b/src/Copied_dependencies/Debug/LICENSE similarity index 100% rename from copied_dependencies/NoTrace-0.3.0.4/LICENSE rename to src/Copied_dependencies/Debug/LICENSE diff --git a/copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs b/src/Copied_dependencies/Debug/NoTrace.hs similarity index 88% rename from copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs rename to src/Copied_dependencies/Debug/NoTrace.hs index ff4516e..bfbd529 100644 --- a/copied_dependencies/NoTrace-0.3.0.4/src/Debug/NoTrace.hs +++ b/src/Copied_dependencies/Debug/NoTrace.hs @@ -1,6 +1,6 @@ ----------------------------------------------------------------------------- -- | --- Module : Debug.NoTrace +-- Module : Copied_dependencies.Debug.NoTrace -- Copyright : (c) Cindy Wang (CindyLinz) 2013 -- License : MIT -- @@ -20,15 +20,15 @@ -- -- And after you finish the debugging process, just change the line -- --- > import Debug.Trace +-- > import Copied_dependencies.Debug.Trace -- -- into -- --- > import Debug.NoTrace +-- > import Copied_dependencies.Debug.NoTrace -- -- Then all the tracing functions are silently removed. ------------------------------------------------------------------------------- -module Debug.NoTrace where +module Copied_dependencies.Debug.NoTrace where trace :: String -> a -> a trace _ = id diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 66e8492..429bf1d 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -52,7 +52,7 @@ import Control.Monad.Catch (Handler) #ifdef DEBUG import Debug.Trace #else -import Debug.NoTrace +import Copied_dependencies.Debug.NoTrace #endif -- | A connection for sending and receiving @Text@ lines. diff --git a/stack.yaml b/stack.yaml index 9370dda..dd6e34e 100644 --- a/stack.yaml +++ b/stack.yaml @@ -37,9 +37,8 @@ resolver: lts-18.28 # will not be run. This is useful for tweaking upstream packages. packages: - . - extra-deps: -- copied_dependencies/NoTrace-0.3.0.4 +# - copied_dependencies/NoTrace-0.3.0.4 # Dependency packages to be pulled from upstream that are not in the resolver # (e.g., acme-missiles-0.3) # extra-deps: [] diff --git a/test/Network/TextViaSocketsSpec.hs b/test/Network/TextViaSocketsSpec.hs index 3dd0da3..e6828b7 100644 --- a/test/Network/TextViaSocketsSpec.hs +++ b/test/Network/TextViaSocketsSpec.hs @@ -19,7 +19,7 @@ import Network.TextViaSockets #ifdef DEBUG import Debug.Trace #else -import Debug.NoTrace +import Copied_dependencies.Debug.NoTrace #endif -- | Timeout token. From 4ce4ecef00e53891f2005bc9f0d887cbb8e914c0 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Fri, 7 Jun 2024 14:47:05 +0200 Subject: [PATCH 08/11] Generalizes connectTo function into two parts such that the socket creation can be reused, as this was removed from the Network module. --- src/Network/TextViaSockets.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 429bf1d..4e01434 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -18,6 +18,9 @@ module Network.TextViaSockets ( Connection () -- * Connect to a server , connectTo + -- * Same as connectTo, + -- but only creates the socket without setting up a connection + , connectToSocket -- * Start a server , acceptOn , acceptOnSocket @@ -149,7 +152,18 @@ getFreeSocket = retryCnect $ do -- an exponential back-off strategy, until the maximum number of tries is -- reached. connectTo :: HostName -> ServiceName -> IO Connection -connectTo hn sn = withSocketsDo $ retryCnect $ do +connectTo hn sn = do + sock <-connectToSocket hn sn + mkConnection sock Nothing + + +-- | Connect to the given host and service name (usually a port number). +-- +-- If the connection cannot be established, this action will be retried using +-- an exponential back-off strategy, until the maximum number of tries is +-- reached. +connectToSocket :: HostName -> ServiceName -> IO Socket +connectToSocket hn sn = withSocketsDo $ retryCnect $ do -- Open the socket. traceIO $ "TextViaSockets: Connecting to " ++ show hn' ++ " on " ++ show sn addrinfos <- getAddrInfo Nothing (Just hn') (Just sn) @@ -159,7 +173,7 @@ connectTo hn sn = withSocketsDo $ retryCnect $ do pn <- socketPort sock traceIO $ "TextViaSockets: Connected to " ++ show hn' ++ " on " ++ show pn ++ " (" ++ show sock ++ ")" - mkConnection sock Nothing + return sock where -- Replace "localhost" to prevent errors on Windows systems where -- "localhost" does not resolve to "127.0.0.1" From 3e6c2c05713d50a58310a3ed5cfd2a884e7dec16 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Thu, 13 Jun 2024 14:59:51 +0200 Subject: [PATCH 09/11] Adds listenOn method, to replace old listenOn method removed from network library. Mimics acceptOn method, but stops before actually making the connection. --- src/Network/TextViaSockets.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 4e01434..750c6cb 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -112,6 +112,19 @@ acceptOn p = retryCnect $ do setSocketOption sock ReuseAddr 1 bind sock (addrAddress addr) acceptOnSocket sock + +-- | Accept byte-streams by serving on the given port number. +-- This function will start listening, but will not block. +listenOn :: PortNumber -> IO Socket +listenOn p = + addr <- resolvePort p + sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) + traceIO $ "TextViaSockets: Accepting a connection on port " ++ show p + setSocketOption sock ReuseAddr 1 + bind sock (addrAddress addr) + listen sock 1 -- Only one queued connection. + return sock + -- | Resolves a portnumber to the SockAddr object needed for many functions from the Network.Socket library -- Implementation is based on example code from the Network.Socket library. From d551ccecfe81c8f970e898e2a063d6d3fd32e359 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Thu, 13 Jun 2024 15:06:04 +0200 Subject: [PATCH 10/11] Export and fix listenOn function. --- src/Network/TextViaSockets.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Network/TextViaSockets.hs b/src/Network/TextViaSockets.hs index 750c6cb..f8a3e6a 100644 --- a/src/Network/TextViaSockets.hs +++ b/src/Network/TextViaSockets.hs @@ -22,6 +22,7 @@ module Network.TextViaSockets -- but only creates the socket without setting up a connection , connectToSocket -- * Start a server + , listenOn , acceptOn , acceptOnSocket , getFreeSocket @@ -116,7 +117,7 @@ acceptOn p = retryCnect $ do -- | Accept byte-streams by serving on the given port number. -- This function will start listening, but will not block. listenOn :: PortNumber -> IO Socket -listenOn p = +listenOn p = do addr <- resolvePort p sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) traceIO $ "TextViaSockets: Accepting a connection on port " ++ show p From 8817cb4210103d92ba96aca525ddcd08e1cc96e9 Mon Sep 17 00:00:00 2001 From: Gijs van Cuyck Date: Fri, 28 Jun 2024 16:32:55 +0200 Subject: [PATCH 11/11] Adds .cabal file to repository, because newer versions of stack are complaining about support for hpack and package.yaml files being deprecated. --- .gitignore | 1 - text-via-sockets.cabal | 119 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 text-via-sockets.cabal diff --git a/.gitignore b/.gitignore index 47b939a..6f7d02b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .stack-work/ -*.cabal !/copied_dependencies/NoTrace-0.3.0.4/NoTrace.cabal *~ *.class diff --git a/text-via-sockets.cabal b/text-via-sockets.cabal new file mode 100644 index 0000000..195d792 --- /dev/null +++ b/text-via-sockets.cabal @@ -0,0 +1,119 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.35.2. +-- +-- see: https://github.com/sol/hpack + +name: text-via-sockets +version: 0.1.1.0 +synopsis: Send and receive text lines using sockets. +description: Please see the README on Github at +category: Network +homepage: https://github.com/capitanbatata/text-via-sockets#readme +bug-reports: https://github.com/capitanbatata/text-via-sockets/issues +author: Damian Nadales +maintainer: damian.nadales@gmail.com +copyright: Copyright: (c) 2017 Damian Nadales +license: BSD3 +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/capitanbatata/text-via-sockets + +flag debug + description: Enable debug + manual: True + default: False + +library + exposed-modules: + Copied_dependencies.Debug.NoTrace + Network.TextViaSockets + other-modules: + Paths_text_via_sockets + hs-source-dirs: + src + default-extensions: + OverloadedStrings + ghc-options: -O -Werror -Wall + build-depends: + base >=4.7 && <5 + , bytestring + , exceptions + , network + , retry + , stm + , text + default-language: Haskell2010 + if flag(debug) + cpp-options: -DDEBUG + +test-suite no-resources-leak-test + type: exitcode-stdio-1.0 + main-is: Main.hs + other-modules: + Paths_text_via_sockets + hs-source-dirs: + test/endurance/no-resources-leak + default-extensions: + OverloadedStrings + ghc-options: -O -Werror -Wall -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T -Werror -Wall -O + build-depends: + async + , base >=4.7 && <5 + , ekg + , network + , text-via-sockets + default-language: Haskell2010 + if flag(debug) + cpp-options: -DDEBUG + +test-suite text-via-sockets-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Network.TextViaSocketsSpec + Paths_text_via_sockets + hs-source-dirs: + test + default-extensions: + OverloadedStrings + ghc-options: -O -Werror -Wall -threaded -rtsopts -with-rtsopts=-N -Werror -Wall -O + build-depends: + QuickCheck + , async + , base >=4.7 && <5 + , hspec + , network + , quickcheck-text + , text + , text-via-sockets + default-language: Haskell2010 + if flag(debug) + cpp-options: -DDEBUG + +benchmark text-via-sockets-bench + type: exitcode-stdio-1.0 + main-is: Main.hs + other-modules: + Paths_text_via_sockets + hs-source-dirs: + bench + default-extensions: + OverloadedStrings + ghc-options: -O -Werror -Wall -threaded -rtsopts -with-rtsopts=-N -Werror -Wall -O + build-depends: + async + , base >=4.7 && <5 + , criterion + , network + , text + , text-via-sockets + default-language: Haskell2010 + if flag(debug) + cpp-options: -DDEBUG