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:
parent
95b083165c
commit
3323605fa9
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user