Skip to content

Commit

Permalink
Tidyups to 3722f04 and mirage#53 fix
Browse files Browse the repository at this point in the history
* Add some comments about how the DHCP thread should background
* Do not `choose` between listen/configure, since that causes a
  cancellation when one succeeds.
  • Loading branch information
avsm committed Jun 18, 2014
1 parent 3722f04 commit 0c4ad56
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions lib/tcpip_stack_direct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ module Make
let configure t config =
match config with
| `DHCP -> begin
(* TODO: spawn a background thread to reconfigure the interface
when future offers are received. *)
let dhcp, offers = Dhcp.create t.c t.ipv4 t.udpv4 in
listen_udpv4 t 68 (Dhcp.input dhcp);
(* TODO: stop listening to this port when done with DHCP. *)
Lwt_stream.get offers
>>= function
| None -> fail (Failure "No DHCP offer received")
Expand Down Expand Up @@ -143,16 +146,22 @@ module Make
let tcpv4_listeners = Hashtbl.create 7 in
let t = { id; c; mode; netif; ethif; ipv4; tcpv4; udpv4;
udpv4_listeners; tcpv4_listeners } in
( Console.log_s t.c "Manager: configuring" >>
choose [ listen t;
configure t t.mode ] >> (* TODO: this is fine for now, because the
DHCP state machine isn't fully implemented and its thread will terminate
after one successful lease transaction. For a DHCP thread that runs
forever, `configure` will not terminate, and the client application will
never run. *)
Console.log_s t.c "Manager: configuration done") >>
Console.log_s t.c "Manager: configuring"
>>= fun () ->
let _ = listen t in
configure t t.mode
>>= fun () ->
(* TODO: this is fine for now, because the DHCP state machine isn't fully
implemented and its thread will terminate after one successful lease
transaction. For a DHCP thread that runs forever, `configure` will need
to spawn a background thread, but we need to consider how to inform the
application stack that the IP address has changed (perhaps via a control
Lwt_stream that the application can ignore if it doesn't care). *)
Console.log_s t.c "Manager: configuration done"
>>= fun () ->
return (`Ok t)

let disconnect t =
return ()
(* TODO: kill the listening thread *)
Console.log_s t.c "Manager: disconnect"
end

0 comments on commit 0c4ad56

Please sign in to comment.