On Fri, Oct 02, 2015 at 11:21:02AM -0500, Jeremy White wrote: > This should allow multiple vdagents; one can disconnect, > and a different one can connect, and XSpice will continue > to function correctly. > > Signed-off-by: Jeremy White <jwhite@xxxxxxxxxxxxxxx> > --- > src/spiceqxl_uinput.c | 31 +++++++++++++++++++++++++------ > src/spiceqxl_uinput.h | 1 + > 2 files changed, 26 insertions(+), 6 deletions(-) > > diff --git a/src/spiceqxl_uinput.c b/src/spiceqxl_uinput.c > index 2d1b149..23f673f 100644 > --- a/src/spiceqxl_uinput.c > +++ b/src/spiceqxl_uinput.c > @@ -19,9 +19,10 @@ > #include "spiceqxl_uinput.h" > > static const char *uinput_filename; > -static int uinput_fd; > +static int uinput_fd = -1; > static struct input_event inp_event; > static int offset; > +static SpiceWatch *uinput_watch; > > static void spiceqxl_uinput_read_cb(int fd, int event, void *opaque) > { > @@ -30,14 +31,20 @@ static void spiceqxl_uinput_read_cb(int fd, int event, void *opaque) > static int y = -1; > static int buttons_state = 0; > int button = -1; > + qxl_screen_t *qxl = (qxl_screen_t *) opaque; > > n = read(uinput_fd, (char *)&inp_event + offset, sizeof(inp_event) - offset); > - if (n == -1) { > - if (errno != EAGAIN && errno != EINTR && errno != EWOULDBLOCK) { > - fprintf(stderr, "spice: uinput read failed: %s\n", strerror(errno)); > - } > + if (n == -1 && > + (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)) > return; > + > + if (n <= 0) { > + fprintf(stderr, "spice: uinput read failed: %d-%s\n", n, n == 0 ? "closed" : strerror(errno)); > + spiceqxl_uinput_term(qxl); > + spiceqxl_uinput_init(qxl); > + return; > } > + Nit, I think you could keep it like if (n == -1) { if (errno != EAGAIN || ...) { /* reopen uinput socket */ } return; } I think it would be slightly more readable. Or did you want to save an indentation level ? Looks good otherwise. Christophe > offset += n; > if (offset < sizeof(inp_event)) { > return; > @@ -121,5 +128,17 @@ void spiceqxl_uinput_init(qxl_screen_t *qxl) > uinput_filename, strerror(errno)); > return; > } > - qxl->core->watch_add(uinput_fd, SPICE_WATCH_EVENT_READ, spiceqxl_uinput_read_cb, qxl); > + uinput_watch = qxl->core->watch_add(uinput_fd, SPICE_WATCH_EVENT_READ, spiceqxl_uinput_read_cb, qxl); > +} > + > +void spiceqxl_uinput_term(qxl_screen_t *qxl) > +{ > + if (uinput_watch) > + qxl->core->watch_remove(uinput_watch); > + if (uinput_fd > -1) { > + close(uinput_fd); > + unlink(uinput_filename); > + } > + uinput_fd = -1; > + uinput_watch = NULL; > } > diff --git a/src/spiceqxl_uinput.h b/src/spiceqxl_uinput.h > index 59c704c..5023f69 100644 > --- a/src/spiceqxl_uinput.h > +++ b/src/spiceqxl_uinput.h > @@ -4,5 +4,6 @@ > #include "qxl.h" > > void spiceqxl_uinput_init(qxl_screen_t *qxl); > +void spiceqxl_uinput_term(qxl_screen_t *qxl); > > #endif > -- > 2.1.4 > > _______________________________________________ > Spice-devel mailing list > Spice-devel@xxxxxxxxxxxxxxxxxxxxx > http://lists.freedesktop.org/mailman/listinfo/spice-devel
Attachment:
signature.asc
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel