Skip to content

Commit

Permalink
define withSocketType, use network 3.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Vieth committed Jan 15, 2020
1 parent 5230b08 commit 4f32002
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion network-mux/src/Network/Mux/Bearer/Socket.hs
Expand Up @@ -20,7 +20,7 @@ import Control.Monad.Class.MonadThrow
import Control.Monad.Class.MonadTime
import Control.Monad.Class.MonadTimer

import qualified Network.Socket as Socket hiding (recv)
import qualified Network.Socket as Socket
import qualified Network.Socket.ByteString.Lazy as Socket (recv, sendAll)

import qualified Network.Mux as Mx
Expand Down
2 changes: 1 addition & 1 deletion network-mux/src/Network/Mux/Channel.hs
Expand Up @@ -24,7 +24,7 @@ import Data.Time.Clock (DiffTime)
import qualified System.Process as IO (createPipe)
import qualified System.IO as IO
( Handle, withFile, IOMode(..), hFlush, hIsEOF )
import qualified Network.Socket as Socket hiding (send, recv)
import qualified Network.Socket as Socket
import qualified Network.Socket.ByteString as Socket

import Control.Monad.Class.MonadSTM
Expand Down
1 change: 1 addition & 0 deletions nix/.stack.nix/default.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,13 +1,17 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}

module Ouroboros.Network.Connections.Socket.Types
( SockType (..)
, SockAddr (..)
, Some (..)
, withSockType
, forgetSockType
) where

import Data.Kind (Type)
import qualified Network.Socket as Socket

data SockType where
Expand All @@ -26,6 +30,15 @@ data SockAddr (sockType :: SockType) where
-> SockAddr Inet6
SockAddrUnix :: String -> SockAddr Unix

data Some (ty :: l -> Type) where
Some :: ty x -> Some ty

withSockType :: Socket.SockAddr -> Some SockAddr
withSockType sockAddr = case sockAddr of
Socket.SockAddrInet pn ha -> Some (SockAddrInet pn ha)
Socket.SockAddrInet6 pn fi ha si -> Some (SockAddrInet6 pn fi ha si)
Socket.SockAddrUnix st -> Some (SockAddrUnix st)

forgetSockType :: SockAddr sockType -> Socket.SockAddr
forgetSockType sockAddr = case sockAddr of
SockAddrInet pn ha -> Socket.SockAddrInet pn ha
Expand Down
5 changes: 2 additions & 3 deletions ouroboros-network/src/Ouroboros/Network/Socket.hs
Expand Up @@ -66,7 +66,7 @@ import qualified Data.ByteString.Lazy as BL
import Data.Int
import Data.Void

import qualified Network.Socket as Socket hiding (recv)
import qualified Network.Socket as Socket

import Cardano.Prelude (NoUnexpectedThunks (..), ThunkInfo (..))

Expand Down Expand Up @@ -466,8 +466,7 @@ runServerThread NetworkServerTracers { nstMuxTracer
(beginConnection nstMuxTracer nstHandshakeTracer versionDataCodec acceptVersion (acceptConnectionTx sockAddr))
-- register producer when application starts, it will be unregistered
-- using 'CompleteConnection'
(\remoteAddr thread st -> pure $ registerProducer remoteAddr thread
st)
(\remoteAddr thread st -> pure $ registerProducer remoteAddr thread st)
completeTx mainTx (toLazyTVar nmsPeerStates)
where
mainTx :: Server.Main (PeerStates IO Socket.SockAddr) Void
Expand Down
Expand Up @@ -155,7 +155,6 @@ sockAddrFamily
sockAddrFamily (Socket.SockAddrInet _ _ ) = Socket.AF_INET
sockAddrFamily (Socket.SockAddrInet6 _ _ _ _) = Socket.AF_INET6
sockAddrFamily (Socket.SockAddrUnix _ ) = Socket.AF_UNIX
sockAddrFamily _ = Socket.AF_UNSPEC

-- | 'Socket' term instanciated with 'Network.Socket'.
--
Expand Down
2 changes: 2 additions & 0 deletions stack.yaml
Expand Up @@ -79,5 +79,7 @@ extra-deps:
# Windows only
- Win32-2.6.2.0

- network-3.0.0.0

nix:
shell-file: nix/stack-shell.nix

0 comments on commit 4f32002

Please sign in to comment.