@@ -33,26 +33,26 @@ module Controller = struct
33
33
34
34
module Conn = struct
35
35
type t = {
36
- state : [ `Handshake | ` Active | `Idle | `Kill ];
36
+ state : [ `Active | `Idle | `Kill ];
37
37
version : int option ;
38
38
state_entered : Time .t ;
39
39
last_activity : Time .t
40
40
}
41
41
42
42
let create () : t =
43
43
let now = Time. now () in
44
- { state = `Handshake
44
+ { state = `Active
45
45
; version = None
46
46
; state_entered = now
47
47
; last_activity = now
48
48
}
49
49
50
50
let activity (t :t ) : t =
51
51
let t = { t with last_activity = Time. now () } in
52
- if t.state = `Active then
53
- t
54
- else
52
+ if t.state = `Idle then
55
53
{ t with state = `Active ; state_entered = t.last_activity }
54
+ else
55
+ t
56
56
57
57
let complete_handshake (t :t ) (version :int ) : t =
58
58
activity { t with version = Some (version) }
@@ -107,7 +107,7 @@ module Controller = struct
107
107
| None -> assert false
108
108
| Some (conn ) -> Some (Conn. complete_handshake conn version))
109
109
110
- let activity (t :t ) ? ver (c_id :Client_id.t ) =
110
+ let activity (t :t ) (c_id :Client_id.t ) =
111
111
ClientTbl. change t.clients c_id (function
112
112
| None -> assert false
113
113
| Some (conn ) -> Some (Conn. activity conn))
@@ -194,8 +194,8 @@ module Controller = struct
194
194
let has_client_id t c_id =
195
195
Platform. has_client_id t.platform c_id &&
196
196
match ClientTbl. find t.clients c_id with
197
- | Some (conn ) -> not (conn. Conn. state = `Handshake )
198
- | _ -> false
197
+ | Some ({ Conn. version = Some ( _ ) } ) -> true
198
+ | _ -> false
199
199
200
200
let send t c_id m =
201
201
Platform. send t.platform c_id m
@@ -228,7 +228,7 @@ module Controller = struct
228
228
| `Message (c_id , msg ) ->
229
229
begin match ClientTbl. find t.clients c_id with
230
230
| None -> assert false
231
- | Some ({ Conn. state = `Handshake } ) ->
231
+ | Some ({ Conn. version = None } ) ->
232
232
let hdr, bits = msg in
233
233
begin
234
234
if not (hdr.type_code = type_code_hello) then begin
@@ -247,7 +247,7 @@ module Controller = struct
247
247
| `Disconnect (c_id , exn ) ->
248
248
begin match ClientTbl. find t.clients c_id with
249
249
| None -> assert false
250
- | Some ({ Conn. state = `Handshake } ) ->
250
+ | Some ({ Conn. version = None } ) ->
251
251
ClientTbl. remove t.clients c_id;
252
252
return []
253
253
| Some (_ ) ->
@@ -259,6 +259,7 @@ module Controller = struct
259
259
let open Header in
260
260
match evt with
261
261
| `Message (c_id , (hdr , bytes )) ->
262
+ Handler. activity t c_id;
262
263
begin if hdr.Header. type_code = type_code_echo_request then
263
264
(* Echo requests get a reply *)
264
265
let hdr = { hdr with type_code = type_code_echo_reply } in
@@ -272,7 +273,7 @@ module Controller = struct
272
273
* *)
273
274
>> | (function _ -> [] )
274
275
else if hdr.Header. type_code = type_code_echo_reply then
275
- (* Echo replies get eaten *)
276
+ (* Echo replies get eaten. The activity has been recorded above. *)
276
277
return []
277
278
else
278
279
(* All other messages get forwarded *)
0 commit comments