@@ -97,7 +97,7 @@ import Control.Exception ( IOException
97import Data.IORef (IORef, newIORef, writeIORef, readIORef)
97import Data.IORef (IORef, newIORef, writeIORef, readIORef)
98import Data.ByteString (ByteString)
98import Data.ByteString (ByteString)
99import qualified Data.ByteString as BS (concat)
99import qualified Data.ByteString as BS (concat)
100−import qualified Data.ByteString.Char8 as BSC (pack, unpack, split)
100+import qualified Data.ByteString.Char8 as BSC (pack, unpack)
101import Data.Int (Int32)
101import Data.Int (Int32)
102import Data.IntMap (IntMap)
102import Data.IntMap (IntMap)
103import qualified Data.IntMap as IntMap (empty)
103import qualified Data.IntMap as IntMap (empty)
@@ -1539,7 +1539,7 @@ encodeEndPointAddress host port ix = EndPointAddress . BSC.pack $
1539decodeEndPointAddress :: EndPointAddress
1539decodeEndPointAddress :: EndPointAddress
1540 -> Maybe (N.HostName, N.ServiceName, EndPointId)
1540 -> Maybe (N.HostName, N.ServiceName, EndPointId)
1541decodeEndPointAddress (EndPointAddress bs) =
1541decodeEndPointAddress (EndPointAddress bs) =
1542− case map BSC.unpack $ BSC.split ':' bs of
1542+ case splitMaxFromEnd (== ':') 2 $ BSC.unpack bs of
1543 [host, port, endPointIdStr] ->
1543 [host, port, endPointIdStr] ->
1544 case reads endPointIdStr of
1544 case reads endPointIdStr of
1545 [(endPointId, "")] -> Just (host, port, endPointId)
1545 [(endPointId, "")] -> Just (host, port, endPointId)
@@ -1547,6 +1547,21 @@ decodeEndPointAddress (EndPointAddress bs) =
1550+-- | @spltiMaxFromEnd p n xs@ splits list @xs@ at elements matching @p@,
1551+-- returning at most @p@ segments -- counting from the /end/
1553+-- > splitMaxFromEnd (== ':') 2 "ab:cd:ef:gh" == ["ab:cd", "ef", "gh"]
1554+splitMaxFromEnd :: (a -> Bool) -> Int -> [a] -> [[a]]
1555+splitMaxFromEnd p = \n -> go [[]] n . reverse
1557+ -- go :: [[a]] -> Int -> [a] -> [[a]]
1558+ go accs _ [] = accs
1559+ go ([] : accs) 0 xs = reverse xs : accs
1560+ go (acc : accs) n (x:xs) =
1561+ if p x then go ([] : acc : accs) (n - 1) xs
1562+ else go ((x : acc) : accs) n xs
1563+ go _ _ _ = error "Bug in splitMaxFromEnd"
1550--------------------------------------------------------------------------------
1565--------------------------------------------------------------------------------
1551-- Functions from TransportInternals --
1566-- Functions from TransportInternals --
1552--------------------------------------------------------------------------------
1567--------------------------------------------------------------------------------