Skip to content

Commit

Permalink
Be recursive in Release_ipc.handle_request
Browse files Browse the repository at this point in the history
This is better than expecting the handler to be recursive, and
is similar to the way the control socket handler works.
  • Loading branch information
andrenth committed Mar 14, 2012
1 parent f22fc53 commit 3ab345d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 13 additions & 9 deletions lib/release_ipc.ml
Expand Up @@ -89,13 +89,17 @@ struct
| `Data resp -> `Response (O.response_of_string resp))

let handle_request ?timeout fd handler =
match_lwt read ?timeout fd with
| `Timeout ->
raise_lwt (Failure "read from slave shouldn't timeout")
| `EOF ->
lwt () = Lwt_log.notice "got EOF on IPC socket" in
Lwt_unix.close fd
| `Data req ->
lwt resp = handler (O.request_of_string req) in
write fd (O.string_of_response resp)
let rec handle_req () =
match_lwt read ?timeout fd with
| `Timeout ->
raise_lwt (Failure "read from slave shouldn't timeout")
| `EOF ->
lwt () = Lwt_log.notice "got EOF on IPC socket" in
Lwt_unix.close fd
| `Data req ->
let _resp_t =
lwt resp = handler (O.request_of_string req) in
write fd (O.string_of_response resp) in
handle_req () in
handle_req ()
end
5 changes: 2 additions & 3 deletions lib_test/master.ml
Expand Up @@ -2,15 +2,14 @@ open Lwt
open Printf
open Ipc

let rec ipc_handler fd =
let ipc_handler fd =
let handler req =
let s = SlaveIpcOps.string_of_request req in
lwt () = Lwt_log.notice_f "got request: %s" s in
match req with
| SlaveIpcOps.Req1 pid -> return (SlaveIpcOps.Resp1 pid)
| SlaveIpcOps.Req2 pid -> return (SlaveIpcOps.Resp2 pid) in
lwt () = SlaveIpc.handle_request fd handler in
ipc_handler fd
SlaveIpc.handle_request fd handler

let control_connection_handler fd =
let handler req =
Expand Down

0 comments on commit 3ab345d

Please sign in to comment.