aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-06-05 17:19:35 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2017-07-15 14:28:25 +0200
commite8f9abd2efacdee175dc811b982234fd9aec28d5 (patch)
tree6ef1890b00b2783ba7cfc01d1e60d68708a9f011
parent3ea1a72ad61865fac3134686d5f4c6b4a17b2a91 (diff)
downloadslirp-e8f9abd2efacdee175dc811b982234fd9aec28d5.zip
slirp-e8f9abd2efacdee175dc811b982234fd9aec28d5.tar.gz
slirp-e8f9abd2efacdee175dc811b982234fd9aec28d5.tar.bz2
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: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--socket.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/socket.c b/socket.c
index 859ff35..4151eb8 100644
--- a/socket.c
+++ b/socket.c
@@ -342,39 +342,41 @@ int sosendoob(struct socket *so)
/* We can send it directly */
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 {
/*
* Since there's no sendv or sendtov like writev,
* we must copy all data to a linear buffer then
* send it all
*/
+ uint32_t urgc = so->so_urgc;
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);
- so->so_urgc -= len;
- if (so->so_urgc) {
+ urgc -= len;
+ if (urgc) {
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);
- so->so_urgc -= n;
len += n;
}
n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
+ }
+
#ifdef DEBUG
- if (n != len)
- DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+ if (n != len) {
+ DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
+ }
#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_rptr += n;