diff options
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/LocalPeerCred.hs | 2 | ||||
-rw-r--r-- | Presence/Server.hs | 7 | ||||
-rw-r--r-- | Presence/ServerC.hs | 11 | ||||
-rw-r--r-- | Presence/SocketLike.hs | 2 | ||||
-rw-r--r-- | Presence/XMPPServer.hs | 5 | ||||
-rw-r--r-- | Presence/main.hs | 9 |
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(..)) | |||
14 | import Data.Maybe | 14 | import Data.Maybe |
15 | import Data.Binary | 15 | import Data.Binary |
16 | import Data.Bits | 16 | import Data.Bits |
17 | import Network.Socket | ||
18 | import System.Posix.Types | 17 | import System.Posix.Types |
19 | import Debug.Trace | 18 | import Debug.Trace |
19 | import SocketLike | ||
20 | 20 | ||
21 | xs ?? n | n < 0 = Nothing | 21 | xs ?? 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 | ||
36 | getPacket h = do { hWaitForInput h (-1) ; fmap (fromChunks . (:[])) $ hGetNonBlocking h 1024 } | 36 | getPacket h = do { hWaitForInput h (-1) ; fmap (fromChunks . (:[])) $ hGetNonBlocking h 1024 } |
37 | 37 | ||
38 | newtype ServerHandle = ServerHandle Socket | ||
39 | |||
40 | quitListening :: ServerHandle -> IO () | ||
41 | quitListening (ServerHandle socket) = sClose socket | ||
42 | |||
38 | doServer addrfamily port g startCon = do | 43 | doServer 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 @@ | |||
5 | module ServerC | 5 | module ServerC |
6 | ( doServer | 6 | ( doServer |
7 | , ConnId(..) | 7 | , ConnId(..) |
8 | , ServerHandle | ||
9 | , quitListening | ||
8 | ) where | 10 | ) where |
9 | 11 | ||
10 | import Network.Socket as Socket | 12 | import Network.Socket as Socket |
@@ -46,6 +48,11 @@ import SocketLike | |||
46 | newtype ConnId = ConnId Int | 48 | newtype ConnId = ConnId Int |
47 | deriving Eq | 49 | deriving Eq |
48 | 50 | ||
51 | newtype ServerHandle = ServerHandle Socket | ||
52 | |||
53 | quitListening :: ServerHandle -> IO () | ||
54 | quitListening (ServerHandle socket) = sClose socket | ||
55 | |||
49 | 56 | ||
50 | data AcceptResult = | 57 | data 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 |
63 | doServer (HCons family port) g = runServer port (runConn g) | 70 | doServer (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 #-} |
7 | module XMPPServer where -- ( listenForXmppClients ) where | 7 | module XMPPServer |
8 | ( module XMPPServer | ||
9 | , quitListening | ||
10 | ) where | ||
8 | 11 | ||
9 | import Data.Char (isSpace) | 12 | import Data.Char (isSpace) |
10 | import Data.HList.TypeEqGeneric1() | 13 | import 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 | |||
27 | import FGConsole | 27 | import FGConsole |
28 | import XMPPServer | 28 | import XMPPServer |
29 | import Data.HList | 29 | import Data.HList |
30 | import Network.Socket (sClose) | ||
31 | import Control.Exception | 30 | import Control.Exception |
32 | import LocalPeerCred | 31 | import LocalPeerCred |
33 | import System.Posix.User | 32 | import 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 |