Skip to content

Commit 9fbf160

Browse files
authored
Merge pull request #528 from hannesm/unix-stack
unix stack, UDP: if 0 is returned from recvfrom, do not further read data
2 parents 09c0097 + 98f709b commit 9fbf160

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/stack-unix/udpv4v6_socket.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,22 @@ let listen t ~port callback =
181181
if not (Lwt.is_sleeping t.switched_off) then raise Lwt.Canceled ;
182182
Lwt.catch (fun () ->
183183
Lwt_cstruct.recvfrom fd buf [] >>= fun (len, sa) ->
184-
(match sa with
185-
| Lwt_unix.ADDR_INET (addr, src_port) ->
186-
let src = Ipaddr_unix.of_inet_addr addr in
187-
let src =
188-
match Ipaddr.to_v4 src with
189-
| None -> src
190-
| Some v4 -> Ipaddr.V4 v4
191-
in
192-
let dst = Ipaddr.(V6 V6.unspecified) in (* TODO *)
193-
let buf = Cstruct.sub_copy buf 0 len in
194-
callback ~src ~dst ~src_port buf
195-
| _ -> Lwt.return_unit) >|= fun () ->
196-
`Continue)
184+
if len = 0 then
185+
Lwt.return `Stop
186+
else
187+
(match sa with
188+
| Lwt_unix.ADDR_INET (addr, src_port) ->
189+
let src = Ipaddr_unix.of_inet_addr addr in
190+
let src =
191+
match Ipaddr.to_v4 src with
192+
| None -> src
193+
| Some v4 -> Ipaddr.V4 v4
194+
in
195+
let dst = Ipaddr.(V6 V6.unspecified) in (* TODO *)
196+
let buf = Cstruct.sub_copy buf 0 len in
197+
callback ~src ~dst ~src_port buf
198+
| _ -> Lwt.return_unit) >|= fun () ->
199+
`Continue)
197200
(function
198201
| Unix.Unix_error (Unix.EBADF, _, _) ->
199202
(match Hashtbl.find_opt t.listen_fds port with

0 commit comments

Comments
 (0)