summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
Diffstat (limited to 'Presence')
-rw-r--r--Presence/LocalPeerCred.hs2
-rw-r--r--Presence/Server.hs7
-rw-r--r--Presence/ServerC.hs11
-rw-r--r--Presence/SocketLike.hs2
-rw-r--r--Presence/XMPPServer.hs5
-rw-r--r--Presence/main.hs9
6 files changed, 25 insertions, 11 deletions
diff --git a/Presence/LocalPeerCred.hs b/Presence/LocalPeerCred.hs
index ee1a4a0f..d3b8d189 100644
--- a/Presence/LocalPeerCred.hs
+++ b/Presence/LocalPeerCred.hs
@@ -14,9 +14,9 @@ import System.IO ( withFile, IOMode(..))
14import Data.Maybe 14import Data.Maybe
15import Data.Binary 15import Data.Binary
16import Data.Bits 16import Data.Bits
17import Network.Socket
18import System.Posix.Types 17import System.Posix.Types
19import Debug.Trace 18import Debug.Trace
19import SocketLike
20 20
21xs ?? n | n < 0 = Nothing 21xs ?? n | n < 0 = Nothing
22[] ?? _ = Nothing 22[] ?? _ = Nothing
diff --git a/Presence/Server.hs b/Presence/Server.hs
index 55a8b57b..80a6e4ba 100644
--- a/Presence/Server.hs
+++ b/Presence/Server.hs
@@ -35,6 +35,11 @@ newtype ConnectionFinalizer = ConnectionFinalizer (IO ())
35 35
36getPacket h = do { hWaitForInput h (-1) ; fmap (fromChunks . (:[])) $ hGetNonBlocking h 1024 } 36getPacket h = do { hWaitForInput h (-1) ; fmap (fromChunks . (:[])) $ hGetNonBlocking h 1024 }
37 37
38newtype ServerHandle = ServerHandle Socket
39
40quitListening :: ServerHandle -> IO ()
41quitListening (ServerHandle socket) = sClose socket
42
38doServer addrfamily port g startCon = do 43doServer addrfamily port g startCon = do
39 doServer' addrfamily port g startCon 44 doServer' addrfamily port g startCon
40 45
@@ -68,7 +73,7 @@ doServer' family port g startCon = runServer2 port (runConn2 g)
68 forkIO $ do 73 forkIO $ do
69 mainLoop sock (ConnId 0) go 74 mainLoop sock (ConnId 0) go
70 -- L.putStrLn $ "quit accept loop" 75 -- L.putStrLn $ "quit accept loop"
71 return sock 76 return (ServerHandle sock)
72 where 77 where
73 mainLoop sock idnum@(ConnId n) go = do 78 mainLoop sock idnum@(ConnId n) go = do
74 let doException ioerror = do 79 let doException ioerror = do
diff --git a/Presence/ServerC.hs b/Presence/ServerC.hs
index 881ce5d2..3933c812 100644
--- a/Presence/ServerC.hs
+++ b/Presence/ServerC.hs
@@ -5,6 +5,8 @@
5module ServerC 5module ServerC
6 ( doServer 6 ( doServer
7 , ConnId(..) 7 , ConnId(..)
8 , ServerHandle
9 , quitListening
8 ) where 10 ) where
9 11
10import Network.Socket as Socket 12import Network.Socket as Socket
@@ -46,6 +48,11 @@ import SocketLike
46newtype ConnId = ConnId Int 48newtype ConnId = ConnId Int
47 deriving Eq 49 deriving Eq
48 50
51newtype ServerHandle = ServerHandle Socket
52
53quitListening :: ServerHandle -> IO ()
54quitListening (ServerHandle socket) = sClose socket
55
49 56
50data AcceptResult = 57data AcceptResult =
51 GotConnection (Socket,SockAddr) 58 GotConnection (Socket,SockAddr)
@@ -59,7 +66,7 @@ doServer ::
59 -> Source m S.ByteString 66 -> Source m S.ByteString
60 -> Sink S.ByteString m () 67 -> Sink S.ByteString m ()
61 -> IO ()) 68 -> IO ())
62 -> IO Socket 69 -> IO ServerHandle
63doServer (HCons family port) g = runServer port (runConn g) 70doServer (HCons family port) g = runServer port (runConn g)
64 where 71 where
65 runServer (HCons port st) go = do 72 runServer (HCons port st) go = do
@@ -72,7 +79,7 @@ doServer (HCons family port) g = runServer port (runConn g)
72 forkIO $ do 79 forkIO $ do
73 mainLoop sock (ConnId 0) go 80 mainLoop sock (ConnId 0) go
74 -- L.putStrLn $ "quit accept loop" 81 -- L.putStrLn $ "quit accept loop"
75 return sock 82 return (ServerHandle sock)
76 where 83 where
77 mainLoop sock idnum@(ConnId n) go = do 84 mainLoop sock idnum@(ConnId n) go = do
78 let doException ioerror = do 85 let doException ioerror = do
diff --git a/Presence/SocketLike.hs b/Presence/SocketLike.hs
index 12fa07a3..d2ff84f6 100644
--- a/Presence/SocketLike.hs
+++ b/Presence/SocketLike.hs
@@ -8,7 +8,7 @@ module SocketLike
8 , RestrictedSocket 8 , RestrictedSocket
9 , restrictSocket 9 , restrictSocket
10 , PortNumber 10 , PortNumber
11 , SockAddr 11 , SockAddr(..)
12 , CUInt 12 , CUInt
13 ) where 13 ) where
14 14
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index 7ed16f6b..e8ab5490 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -4,7 +4,10 @@
4{-# LANGUAGE TupleSections #-} 4{-# LANGUAGE TupleSections #-}
5{-# LANGUAGE TypeFamilies #-} 5{-# LANGUAGE TypeFamilies #-}
6-- {-# LANGUAGE GADTs #-} 6-- {-# LANGUAGE GADTs #-}
7module XMPPServer where -- ( listenForXmppClients ) where 7module XMPPServer
8 ( module XMPPServer
9 , quitListening
10 ) where
8 11
9import Data.Char (isSpace) 12import Data.Char (isSpace)
10import Data.HList.TypeEqGeneric1() 13import Data.HList.TypeEqGeneric1()
diff --git a/Presence/main.hs b/Presence/main.hs
index 74589a41..a0a80569 100644
--- a/Presence/main.hs
+++ b/Presence/main.hs
@@ -27,7 +27,6 @@ import UTmp
27import FGConsole 27import FGConsole
28import XMPPServer 28import XMPPServer
29import Data.HList 29import Data.HList
30import Network.Socket (sClose)
31import Control.Exception 30import Control.Exception
32import LocalPeerCred 31import LocalPeerCred
33import System.Posix.User 32import System.Posix.User
@@ -223,16 +222,16 @@ start ip4or6 = do
223 utmp_file 222 utmp_file
224 dologin 223 dologin
225#endif 224#endif
226 sockLocals <- listenForXmppClients ip4or6 (UnixSessions tracked) 5222 HNil 225 clients <- listenForXmppClients ip4or6 (UnixSessions tracked) 5222 HNil
227 sockRemotes <- listenForRemotePeers ip4or6 (UnixSessions tracked) 5269 HNil 226 peers <- listenForRemotePeers ip4or6 (UnixSessions tracked) 5269 HNil
228 227
229 threadDelay 1000 -- wait a moment to obtain current tty 228 threadDelay 1000 -- wait a moment to obtain current tty
230 dologin () 229 dologin ()
231 putStrLn "\nHit enter to terminate...\n" 230 putStrLn "\nHit enter to terminate...\n"
232 getLine 231 getLine
233 killThread remotes 232 killThread remotes
234 sClose sockLocals 233 quitListening clients
235 sClose sockRemotes 234 quitListening peers
236 -- threadDelay 1000 235 -- threadDelay 1000
237 putStrLn "closed listener." 236 putStrLn "closed listener."
238 unmonitorTTY mtty 237 unmonitorTTY mtty