0 | module Node.HTTP.Agent
 1 |
 2 | import Node
 3 | import Node.Internal.Support
 4 |
 5 | export
 6 | data Agent : Type where [external]
 7 |
 8 | public export
 9 | data Scheduling
10 |   = FIFO
11 |   | LIFO
12 |
13 | export
14 | implementation Show Scheduling where
15 |   show = \case
16 |     FIFO => "fifo"
17 |     LIFO => "lifo"
18 |
19 | public export
20 | record Options where
21 |   constructor MkOptions
22 |   keepAlive : Bool
23 |   keepAliveMsecs : Int
24 |   maxSockets : Int
25 |   maxTotalSockets : Int
26 |   maxFreeSockets : Int
27 |   scheduling : Scheduling
28 | --  timeout : Int
29 |
30 | export
31 | defaultOptions : Options
32 | defaultOptions = MkOptions
33 |   { keepAlive = False
34 |   , keepAliveMsecs = 1000
35 |   , maxSockets = 65535
36 |   , maxTotalSockets = 65535
37 |   , maxFreeSockets = 256
38 |   , scheduling = LIFO
39 |   }
40 |
41 | %foreign """
42 |   node:lambda:
43 |   (
44 |     keepAlive
45 |     keepAliveMsecs
46 |     maxSockets
47 |     maxTotalSockets
48 |     maxFreeSockets
49 |     scheduling
50 |   ) => _keepDefined({
51 |     keepAlive: _bool(keepAlive),
52 |     keepAliveMsecs,
53 |     maxSockets,
54 |     maxTotalSockets,
55 |     maxFreeSockets,
56 |     scheduling
57 |   })
58 |   """
59 | ffi_convertOptions :
60 |   (keepAlive : Bool) ->
61 |   (keepAliveMsecs : Int) ->
62 |   (maxSockets : Int) ->
63 |   (maxTotalSockets : Int) ->
64 |   (maxFreeSockets : Int) ->
65 |   (scheduling : String) ->
66 |   Node Options
67 |
68 | %foreign "node:lambda: (options) => new Agent(options)"
69 | ffi_newAgent : Node Options -> Agent
70 |
71 | export
72 | newAgent : Options -> Agent
73 | newAgent o = ffi_newAgent $ ffi_convertOptions
74 |   o.keepAlive
75 |   o.keepAliveMsecs
76 |   o.maxSockets
77 |   o.maxTotalSockets
78 |   o.maxFreeSockets
79 |   (show o.scheduling)
80 |
81 |