blob: 83a6ee3f78bdc75b850797a8cd8fdf0067296718 [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
iproctor7897c922007-08-08 01:43:39 +000014accept_loop accepter hand sock proc transgen iprotgen oprotgen =
15 do (h,hn,_) <- accepter sock
iproctorff8eb922007-07-25 19:06:13 +000016 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)))
iproctor7897c922007-08-08 01:43:39 +000020 accept_loop accepter hand sock proc transgen iprotgen oprotgen
iproctorff8eb922007-07-25 19:06:13 +000021
iproctor7897c922007-08-08 01:43:39 +000022run_threaded_server accepter listener hand proc port transgen iprotgen oprotgen =
23 do sock <- listener
24 accept_loop accepter hand sock proc transgen iprotgen oprotgen
iproctorff8eb922007-07-25 19:06:13 +000025 return ()
26
27
28-- A basic threaded binary protocol socket server.
iproctor7897c922007-08-08 01:43:39 +000029run_basic_server hand proc port = run_threaded_server accept (listenOn (PortNumber port)) hand proc port TChannelTrans TBinaryProtocol TBinaryProtocol