racket/udp: adjust receive into a zero-sized buffer

The OS doesn't necessarily react to a zero-sized buffer the way
that `udp-receive!` is supposed to work, so provide only a
non-zero-sized buffer to the OS.
This commit is contained in:
Matthew Flatt 2014-10-20 17:56:27 -05:00
parent 95b083165c
commit 3323605fa9
2 changed files with 13 additions and 2 deletions

View File

@ -163,6 +163,7 @@
(sync (udp-receive!-evt udp2 us1))) (sync (udp-receive!-evt udp2 us1)))
(test #f sync/timeout 0.05 udp2-r) (test #f sync/timeout 0.05 udp2-r)
(test #f sync/timeout 0.05 (udp-receive!-evt udp2 us1)) (test #f sync/timeout 0.05 (udp-receive!-evt udp2 us1))
(test #f sync/timeout 0.05 (udp-receive!-evt udp2 (make-bytes 0)))
;; break behavior ;; break behavior
(let ([t (parameterize-break #f (let ([t (parameterize-break #f

View File

@ -3682,8 +3682,18 @@ static int do_udp_recv(const char *name, Scheme_UDP *udp, char *bstr, intptr_t s
} }
{ {
x = recvfrom(udp->s, bstr XFORM_OK_PLUS start, end - start, 0, if (end == start) {
(struct sockaddr *)src_addr, &asize); /* recvfrom() doesn't necessarily wait if you pass a buffer size of 0;
to be consistent with accepting a message but discarding bytes that
don't fit, accept at least one byte and turn a `1` result into `0` */
char buf[1];
x = recvfrom(udp->s, buf, 1, 0, (struct sockaddr *)src_addr, &asize);
if (x == 1)
x = 0;
} else {
x = recvfrom(udp->s, bstr XFORM_OK_PLUS start, end - start, 0,
(struct sockaddr *)src_addr, &asize);
}
} }
if (x == -1) { if (x == -1) {