From dbcf30d5239043eafa1282caa369c577130938e9 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 19 Jun 2013 20:51:43 -0400 Subject: Shared hostname with client-connection. --- Presence/main.hs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'Presence/main.hs') diff --git a/Presence/main.hs b/Presence/main.hs index 86503a62..e416d7cc 100644 --- a/Presence/main.hs +++ b/Presence/main.hs @@ -46,6 +46,7 @@ import Data.ByteString.Lazy.Char8 as L (ByteString,putStrLn) import qualified Prelude import Prelude hiding (putStrLn) import System.Environment +import qualified Text.Show.ByteString as L data UnixSession = UnixSession { @@ -79,14 +80,19 @@ instance XMPPSession UnixSession where ) muid rsc <- readIORef (unix_resource s) - let suf = maybe "" ("/"<++>) rsc - jid = user <++> "@" <++> host <++> suf - L.putStrLn $ "SESSION: jid " <++> jid - return jid + -- let jid = user <++> "@" <++> host <++?> "/" <++$> rsc + L.putStrLn $ "SESSION: jid " <++> L.show (JID (Just user) host rsc) + return (JID (Just user) host rsc) closeSession _ = L.putStrLn "SESSION: close" subscribe session Nothing = do let tmvar = greedySubscriber (presence_state session) - chan <- atomically $ + atomically $ subscribeToChan tmvar + subscribe session (Just jid) = do + let tvar = subscriberMap (presence_state session) + atomically $ subscribeToMap tvar jid + + +subscribeToChan tmvar = (do (cnt,chan) <- takeTMVar tmvar putTMVar tmvar (cnt+1,chan) chan' <- dupTChan chan @@ -95,10 +101,8 @@ instance XMPPSession UnixSession where (do chan <- newTChan putTMVar tmvar (1,chan) return chan ) - return chan - subscribe session (Just jid) = do - let tvar = subscriberMap (presence_state session) - atomically $ do + +subscribeToMap tvar jid = do subs <- readTVar tvar let mbchan = Map.lookup jid subs (chan,subs') <- -- cgit v1.2.3