Revision 684a096e qemu-char.c
b/qemu-char.c | ||
---|---|---|
727 | 727 |
return chan; |
728 | 728 |
} |
729 | 729 |
|
730 |
static int io_channel_send_all(GIOChannel *fd, const void *_buf, int len1)
|
|
730 |
static int io_channel_send(GIOChannel *fd, const void *buf, size_t len)
|
|
731 | 731 |
{ |
732 | 732 |
GIOStatus status; |
733 |
gsize bytes_written; |
|
734 |
int len; |
|
735 |
const uint8_t *buf = _buf; |
|
733 |
size_t offset; |
|
736 | 734 |
|
737 |
len = len1; |
|
738 |
while (len > 0) { |
|
739 |
status = g_io_channel_write_chars(fd, (const gchar *)buf, len, |
|
735 |
offset = 0; |
|
736 |
while (offset < len) { |
|
737 |
gsize bytes_written; |
|
738 |
|
|
739 |
status = g_io_channel_write_chars(fd, buf + offset, len - offset, |
|
740 | 740 |
&bytes_written, NULL); |
741 | 741 |
if (status != G_IO_STATUS_NORMAL) { |
742 | 742 |
if (status == G_IO_STATUS_AGAIN) { |
743 |
/* If we've written any data, return a partial write. */ |
|
744 |
if (offset) { |
|
745 |
break; |
|
746 |
} |
|
743 | 747 |
errno = EAGAIN; |
744 |
return -1; |
|
745 | 748 |
} else { |
746 | 749 |
errno = EINVAL; |
747 |
return -1; |
|
748 | 750 |
} |
751 |
|
|
752 |
return -1; |
|
749 | 753 |
} else if (status == G_IO_STATUS_EOF) { |
750 | 754 |
break; |
751 |
} else { |
|
752 |
buf += bytes_written; |
|
753 |
len -= bytes_written; |
|
754 | 755 |
} |
756 |
|
|
757 |
offset += bytes_written; |
|
755 | 758 |
} |
756 |
return len1 - len; |
|
759 |
|
|
760 |
return offset; |
|
757 | 761 |
} |
758 | 762 |
|
759 | 763 |
#ifndef _WIN32 |
... | ... | |
770 | 774 |
{ |
771 | 775 |
FDCharDriver *s = chr->opaque; |
772 | 776 |
|
773 |
return io_channel_send_all(s->fd_out, buf, len);
|
|
777 |
return io_channel_send(s->fd_out, buf, len); |
|
774 | 778 |
} |
775 | 779 |
|
776 | 780 |
static gboolean fd_chr_read(GIOChannel *chan, GIOCondition cond, void *opaque) |
... | ... | |
1088 | 1092 |
pty_chr_update_read_handler(chr); |
1089 | 1093 |
return 0; |
1090 | 1094 |
} |
1091 |
return io_channel_send_all(s->fd, buf, len);
|
|
1095 |
return io_channel_send(s->fd, buf, len); |
|
1092 | 1096 |
} |
1093 | 1097 |
|
1094 | 1098 |
static GSource *pty_chr_add_watch(CharDriverState *chr, GIOCondition cond) |
... | ... | |
2347 | 2351 |
{ |
2348 | 2352 |
TCPCharDriver *s = chr->opaque; |
2349 | 2353 |
if (s->connected) { |
2350 |
return io_channel_send_all(s->chan, buf, len);
|
|
2354 |
return io_channel_send(s->chan, buf, len); |
|
2351 | 2355 |
} else { |
2352 | 2356 |
/* XXX: indicate an error ? */ |
2353 | 2357 |
return len; |
Also available in: Unified diff