@@ -22,9 +22,9 @@ import Data.Binary.Get ( runGetIncremental, pushChunk)
22
22
import qualified Data.Binary.Get as BG (Decoder (.. ))
23
23
import Data.Maybe (fromJust )
24
24
import qualified Data.Vector as V
25
- import System.Socket ( Socket , socket )
25
+ import System.Socket hiding ( connect , close , Error )
26
26
import qualified System.Socket as Socket (connect , close , send , receive )
27
- import System.Socket.Family.Inet6
27
+ import System.Socket.Family.Inet
28
28
import System.Socket.Type.Stream
29
29
import System.Socket.Protocol.TCP
30
30
import System.Socket.Family.Unix
@@ -79,32 +79,32 @@ defaultUnixPathDirectory = "/var/run/postgresql"
79
79
unixPathFilename :: B. ByteString
80
80
unixPathFilename = " .s.PGSQL."
81
81
82
- address :: SocketAddress Unix
83
- address = fromJust $ socketAddressUnixPath " /var/run/postgresql/.s.PGSQL.5432"
84
-
85
82
createRawConnection :: ConnectionSettings -> IO RawConnection
86
- createRawConnection settings = do
87
- (s, address) <- createSocket settings
88
- Socket. connect s address
89
- pure $ constructRawConnection s
83
+ createRawConnection settings
84
+ | host == " " = unixConnection defaultUnixPathDirectory
85
+ | " / " `B.isPrefixOf` host = unixConnection host
86
+ | otherwise = tcpConnection
90
87
where
91
- createSocket settings
92
- | host == " " = unixSocket defaultUnixPathDirectory
93
- | " /" `B.isPrefixOf` host = unixSocket host
94
- | otherwise = tcpSocket
95
- where
96
- host = settingsHost settings
97
- unixSocket dirPath = do
98
- -- 47 - `/`
99
- let dir = B. reverse . B. dropWhile (== 47 ) $ B. reverse dirPath
100
- path = dir <> " /" <> unixPathFilename
101
- <> BS. pack (show $ settingsPort settings)
102
- -- TODO check for Nothing
103
- address = fromJust $ socketAddressUnixPath path
104
- s <- socket :: IO (Socket Unix Stream Unix )
105
- pure (s, address)
106
- tcpSocket = do
107
- undefined
88
+ host = settingsHost settings
89
+ unixConnection dirPath = do
90
+ -- 47 - `/`
91
+ let dir = B. reverse . B. dropWhile (== 47 ) $ B. reverse dirPath
92
+ path = dir <> " /" <> unixPathFilename
93
+ <> BS. pack (show $ settingsPort settings)
94
+ -- TODO check for Nothing
95
+ address = fromJust $ socketAddressUnixPath path
96
+ s <- socket :: IO (Socket Unix Stream Unix )
97
+ Socket. connect s address
98
+ pure $ constructRawConnection s
99
+ tcpConnection = do
100
+ addressInfo <- getAddressInfo (Just host) Nothing aiV4Mapped
101
+ :: IO [AddressInfo Inet Stream TCP ]
102
+ let address = (socketAddress $ head addressInfo)
103
+ { inetPort = fromIntegral $ settingsPort settings }
104
+ -- TODO check for empty
105
+ s <- socket :: IO (Socket Inet Stream TCP )
106
+ Socket. connect s address
107
+ pure $ constructRawConnection s
108
108
109
109
constructRawConnection :: Socket f t p -> RawConnection
110
110
constructRawConnection s = RawConnection
0 commit comments