提交 0b466065 编写于 作者: P Peter Maydell 提交者: Samuel Thibault

slirp: Handle error returns from slirp_send() in sosendoob()

The code in sosendoob() assumes that slirp_send() always
succeeds, but it might return an OS error code (for instance
if the other end has disconnected). Catch these and return
the caller either -1 on error or the number of urgent bytes
actually written. (None of the callers check this return
value currently, though.)
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
Reviewed-by: NDr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: NSamuel Thibault <samuel.thibault@ens-lyon.org>
上级 12dccfe4
...@@ -345,33 +345,40 @@ sosendoob(struct socket *so) ...@@ -345,33 +345,40 @@ sosendoob(struct socket *so)
if (sb->sb_rptr < sb->sb_wptr) { if (sb->sb_rptr < sb->sb_wptr) {
/* We can send it directly */ /* We can send it directly */
n = slirp_send(so, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */ n = slirp_send(so, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */
so->so_urgc -= n;
DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
} else { } else {
/* /*
* Since there's no sendv or sendtov like writev, * Since there's no sendv or sendtov like writev,
* we must copy all data to a linear buffer then * we must copy all data to a linear buffer then
* send it all * send it all
*/ */
uint32_t urgc = so->so_urgc;
len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr;
if (len > so->so_urgc) len = so->so_urgc; if (len > urgc) {
len = urgc;
}
memcpy(buff, sb->sb_rptr, len); memcpy(buff, sb->sb_rptr, len);
so->so_urgc -= len; urgc -= len;
if (so->so_urgc) { if (urgc) {
n = sb->sb_wptr - sb->sb_data; n = sb->sb_wptr - sb->sb_data;
if (n > so->so_urgc) n = so->so_urgc; if (n > urgc) {
n = urgc;
}
memcpy((buff + len), sb->sb_data, n); memcpy((buff + len), sb->sb_data, n);
so->so_urgc -= n;
len += n; len += n;
} }
n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
}
#ifdef DEBUG #ifdef DEBUG
if (n != len) if (n != len) {
DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n")); DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
}
#endif #endif
DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc)); if (n < 0) {
return n;
} }
so->so_urgc -= n;
DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
sb->sb_cc -= n; sb->sb_cc -= n;
sb->sb_rptr += n; sb->sb_rptr += n;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册