From 7303df46edf2468f4e704584fdabf22697e63657 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 12 May 2017 16:20:38 -0400 Subject: [PATCH] Make one's own arrival non-special --- chat-sync.rkt | 2 +- chat-threads.py | 2 +- chat-threadstate-total.rkt | 2 +- chat-threadstate.rkt | 2 +- chat.erl | 2 +- chat.hs | 3 +-- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/chat-sync.rkt b/chat-sync.rkt index 8cf35c1..6ac6386 100644 --- a/chat-sync.rkt +++ b/chat-sync.rkt @@ -38,7 +38,7 @@ (define (arrive! connection-id) (call-with-semaphore active-connection-mutex (lambda () - (thread-send (current-thread) `(you-are ,connection-id)) + (thread-send (current-thread) `(arrived ,connection-id)) (for ([c active-connections]) (thread-send (current-thread) `(arrived ,(cdr c))) (thread-send (car c) `(arrived ,connection-id))) diff --git a/chat-threads.py b/chat-threads.py index d9fe811..e13fe23 100644 --- a/chat-threads.py +++ b/chat-threads.py @@ -26,7 +26,7 @@ class ConnectionHandler(StreamRequestHandler): self.depart() def arrive(self): - self.announce('you are %s' % (self.connection_id,)) + self.announce('%s arrived' % (self.connection_id,)) with active_connection_mutex: for c in active_connections: self.announce('%s arrived' % (c.connection_id,)) diff --git a/chat-threadstate-total.rkt b/chat-threadstate-total.rkt index 193da72..99b2fc3 100644 --- a/chat-threadstate-total.rkt +++ b/chat-threadstate-total.rkt @@ -50,7 +50,7 @@ (channel-put ch active-connections) (loop active-connections)] [`(arrive ,caller ,connection-id) - (thread-send caller `(you-are ,connection-id)) + (thread-send caller `(arrived ,connection-id)) (for ([c active-connections]) (thread-send caller `(arrived ,(cdr c))) (thread-send (car c) `(arrived ,connection-id))) diff --git a/chat-threadstate.rkt b/chat-threadstate.rkt index ba5852c..36b06bd 100644 --- a/chat-threadstate.rkt +++ b/chat-threadstate.rkt @@ -43,7 +43,7 @@ (let loop () (match (thread-receive) [`(arrive ,caller ,connection-id) - (thread-send caller `(you-are ,connection-id)) + (thread-send caller `(arrived ,connection-id)) (for ([c active-connections]) (thread-send caller `(arrived ,(cdr c))) (thread-send (car c) `(arrived ,connection-id))) diff --git a/chat.erl b/chat.erl index a5a80ca..0c608bd 100644 --- a/chat.erl +++ b/chat.erl @@ -17,6 +17,7 @@ accept_loop(LSock, IndexPid) -> index(Connected) -> receive {arrive, Pid} -> + Pid ! {utterance, {arrive, Pid}}, [begin P ! {utterance, {arrive, Pid}}, Pid ! {utterance, {arrive, P}} @@ -39,7 +40,6 @@ say(Sock, V) -> connection(Sock, IndexPid) -> IndexPid ! {arrive, self()}, - say(Sock, {you_are, self()}), connection_mainloop(Sock, IndexPid). connection_mainloop(Sock, IndexPid) -> diff --git a/chat.hs b/chat.hs index d92ef01..b0469f2 100644 --- a/chat.hs +++ b/chat.hs @@ -33,11 +33,10 @@ broadcast str conns = sequence_ $ map sendStr conns where sendStr (_, hdl) = hPutStrLn hdl str arrive index name hdl = do - hPutStrLn hdl ("you are " ++ name) old <- atomically $ do old <- readTVar index writeTVar index ((name, hdl) : old) return old - broadcast (name ++ " arrived") old + broadcast (name ++ " arrived") ((name, hdl) : old) sequence_ $ map (\ (otherName, _) -> hPutStrLn hdl (otherName ++ " arrived")) old depart index name hdl = do