Skip to content

Commit 09c0097

Browse files
authored
Merge pull request #527 from hannesm/unix-stack
unix: avoid spurious warnings when the fd is scheduled to be closed anyways
2 parents 6766a3f + 9e6f0c5 commit 09c0097

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

examples/unikernel/config.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* mirage >= 4.6.0 & < 4.7.0 *)
1+
(* mirage >= 4.6.0 & < 4.10.0 *)
22

33
open Mirage
44

src/stack-unix/tcpv4v6_socket.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,17 @@ let listen t ~port ?keepalive callback =
178178
Lwt.catch
179179
(fun () -> callback afd)
180180
(fun exn ->
181-
Log.warn (fun m -> m "error %s in callback" (Printexc.to_string exn)) ;
181+
Log.warn (fun m -> m "tcp error on port %u in callback %s" port (Printexc.to_string exn)) ;
182182
close afd));
183183
`Continue)
184184
(function
185185
| Unix.Unix_error (Unix.EBADF, _, _) ->
186-
Log.warn (fun m -> m "error bad file descriptor in accept") ;
186+
(match Hashtbl.find_opt t.listen_sockets port with
187+
| None -> ()
188+
| Some _ -> Log.warn (fun m -> m "tcp error bad file descriptor in accept on port %u" port)) ;
187189
Lwt.return `Stop
188190
| exn ->
189-
Log.warn (fun m -> m "error %s in accept" (Printexc.to_string exn)) ;
191+
Log.warn (fun m -> m "tcp error on port %u in accept: %s" port (Printexc.to_string exn)) ;
190192
Lwt.return `Continue) >>= function
191193
| `Continue -> loop ()
192194
| `Stop -> Lwt.return_unit

src/stack-unix/udpv4v6_socket.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,19 @@ let listen t ~port callback =
190190
| Some v4 -> Ipaddr.V4 v4
191191
in
192192
let dst = Ipaddr.(V6 V6.unspecified) in (* TODO *)
193-
let buf =
194-
(* Use Cstruct.sub_copy once it exists in a
195-
reasonably mature cstruct release *)
196-
let b = Cstruct.create_unsafe len in
197-
Cstruct.blit buf 0 b 0 len;
198-
b
199-
in
193+
let buf = Cstruct.sub_copy buf 0 len in
200194
callback ~src ~dst ~src_port buf
201195
| _ -> Lwt.return_unit) >|= fun () ->
202196
`Continue)
203197
(function
204198
| Unix.Unix_error (Unix.EBADF, _, _) ->
205-
Log.warn (fun m -> m "error bad file descriptor in accept") ;
199+
(match Hashtbl.find_opt t.listen_fds port with
200+
| None -> ()
201+
| Some _ ->
202+
Log.info (fun m -> m "udp error bad file descriptor in accept on port %u" port)) ;
206203
Lwt.return `Stop
207204
| exn ->
208-
Log.warn (fun m -> m "exception %s in recvfrom" (Printexc.to_string exn)) ;
205+
Log.warn (fun m -> m "udp exception on port %u in recvfrom: %s" port (Printexc.to_string exn)) ;
209206
Lwt.return `Continue) >>= function
210207
| `Continue -> loop ()
211208
| `Stop -> Lwt.return_unit

tcpip.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ depends: [
2727
"dune" {>= "2.7.0"}
2828
"bisect_ppx" {dev & >= "2.5.0"}
2929
"ocaml" {>= "4.08.0"}
30-
"cstruct" {>= "6.0.0"}
30+
"cstruct" {>= "6.2.0"}
3131
"cstruct-lwt"
3232
"mirage-net" {>= "3.0.0"}
3333
"mirage-mtime" {>= "4.0.0"}

0 commit comments

Comments
 (0)