blob: c71882c97a18ed22db3d4eca98fcdf98d0dc46ab [file] [log] [blame]
iproctorff8eb922007-07-25 19:06:13 +00001module TServer(run_basic_server,run_threaded_server) where
2
3import Network
4import Thrift
5import Control.Exception
6import TBinaryProtocol
7import TChannelTransport
8import Control.Concurrent
9
10proc_loop hand proc ps = do v <-proc hand ps
11 if v then proc_loop hand proc ps
12 else return ()
13
14accept_loop hand sock proc transgen iprotgen oprotgen =
15 do (h,hn,_) <- accept sock
16 let t = transgen h
17 let ip = iprotgen t
18 let op = oprotgen t
19 forkIO (handle (\e -> return ()) (proc_loop hand proc (ip,op)))
20 accept_loop hand sock proc transgen iprotgen oprotgen
21
22run_threaded_server hand proc port transgen iprotgen oprotgen =
23 do sock <- listenOn (PortNumber port)
24 accept_loop hand sock proc transgen iprotgen oprotgen
25 return ()
26
27
28-- A basic threaded binary protocol socket server.
29run_basic_server hand proc port = run_threaded_server hand proc port TChannelTrans TBinaryProtocol TBinaryProtocol