iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 1 | module TServer(run_basic_server,run_threaded_server) where |
| 2 | |
| 3 | import Network |
| 4 | import Thrift |
| 5 | import Control.Exception |
| 6 | import TBinaryProtocol |
| 7 | import TChannelTransport |
| 8 | import Control.Concurrent |
| 9 | |
| 10 | proc_loop hand proc ps = do v <-proc hand ps |
| 11 | if v then proc_loop hand proc ps |
| 12 | else return () |
| 13 | |
iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 14 | accept_loop accepter hand sock proc transgen iprotgen oprotgen = |
| 15 | do (h,hn,_) <- accepter sock |
iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 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))) |
iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 20 | accept_loop accepter hand sock proc transgen iprotgen oprotgen |
iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 21 | |
iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 22 | run_threaded_server accepter listener hand proc port transgen iprotgen oprotgen = |
| 23 | do sock <- listener |
| 24 | accept_loop accepter hand sock proc transgen iprotgen oprotgen |
iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 25 | return () |
| 26 | |
| 27 | |
| 28 | -- A basic threaded binary protocol socket server. |
iproctor | 7897c92 | 2007-08-08 01:43:39 +0000 | [diff] [blame] | 29 | run_basic_server hand proc port = run_threaded_server accept (listenOn (PortNumber port)) hand proc port TChannelTrans TBinaryProtocol TBinaryProtocol |