mirror of
git://git.proxmox.com/git/spiceterm.git
synced 2025-08-22 10:17:06 +00:00
handle partial writes
This commit is contained in:
parent
5cba579072
commit
c13b33617b
21
spiceterm.c
21
spiceterm.c
@ -1791,28 +1791,41 @@ static void
|
|||||||
master_watch(int master, int event, void *opaque)
|
master_watch(int master, int event, void *opaque)
|
||||||
{
|
{
|
||||||
spiceTerm *vt = (spiceTerm *)opaque;
|
spiceTerm *vt = (spiceTerm *)opaque;
|
||||||
|
int c;
|
||||||
|
|
||||||
// fixme: if (!vt->mark_active) {
|
// fixme: if (!vt->mark_active) {
|
||||||
|
|
||||||
if (event == SPICE_WATCH_EVENT_READ) {
|
if (event == SPICE_WATCH_EVENT_READ) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
int c;
|
|
||||||
while ((c = read(master, buffer, 1024)) == -1) {
|
while ((c = read(master, buffer, 1024)) == -1) {
|
||||||
if (errno != EAGAIN) break;
|
if (errno != EAGAIN) break;
|
||||||
}
|
}
|
||||||
if (c == -1) {
|
if (c == -1) {
|
||||||
g_error("got read error"); // fixme
|
perror("master pipe read error"); // fixme
|
||||||
}
|
}
|
||||||
spiceterm_puts (vt, buffer, c);
|
spiceterm_puts (vt, buffer, c);
|
||||||
} else {
|
} else {
|
||||||
if (vt->ibuf_count > 0) {
|
if (vt->ibuf_count > 0) {
|
||||||
DPRINTF(1, "write input %x %d", vt->ibuf[0], vt->ibuf_count);
|
DPRINTF(1, "write input %x %d", vt->ibuf[0], vt->ibuf_count);
|
||||||
write (master, vt->ibuf, vt->ibuf_count);
|
if ((c = write (master, vt->ibuf, vt->ibuf_count)) >= 0) {
|
||||||
vt->ibuf_count = 0; // fixme: what if not all data written
|
if (c == vt->ibuf_count) {
|
||||||
|
vt->ibuf_count = 0;
|
||||||
|
} else if (c > 0) {
|
||||||
|
// not all data written
|
||||||
|
memmove(vt->ibuf, vt->ibuf + c, vt->ibuf_count - c);
|
||||||
|
vt->ibuf_count -= c;
|
||||||
|
} else {
|
||||||
|
// nothing written -ignore and try later
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
perror("master pipe write error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vt->ibuf_count == 0) {
|
||||||
spiceterm_update_watch_mask(vt, FALSE);
|
spiceterm_update_watch_mask(vt, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char** argv)
|
main (int argc, char** argv)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user