vnc: reorganize code for reverse mode

Avoid the dance between csock and vs->lsock.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2012-10-18 09:01:01 +02:00
parent 1ce52c78ab
commit 007fcd3ee9
3 changed files with 12 additions and 16 deletions

View File

@ -378,7 +378,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen);
/* vnc.c */ /* vnc.c */
void vnc_display_init(DisplayState *ds); void vnc_display_init(DisplayState *ds);
void vnc_display_close(DisplayState *ds); void vnc_display_close(DisplayState *ds);
int vnc_display_open(DisplayState *ds, const char *display); void vnc_display_open(DisplayState *ds, const char *display, Error **errp);
void vnc_display_add_client(DisplayState *ds, int csock, int skipauth); void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
int vnc_display_disable_login(DisplayState *ds); int vnc_display_disable_login(DisplayState *ds);
char *vnc_display_local_addr(DisplayState *ds); char *vnc_display_local_addr(DisplayState *ds);

6
qmp.c
View File

@ -349,11 +349,9 @@ void qmp_change_vnc_password(const char *password, Error **errp)
} }
} }
static void qmp_change_vnc_listen(const char *target, Error **err) static void qmp_change_vnc_listen(const char *target, Error **errp)
{ {
if (vnc_display_open(NULL, target) < 0) { vnc_display_open(NULL, target, errp);
error_set(err, QERR_VNC_SERVER_FAILED, target);
}
} }
static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,

View File

@ -3053,19 +3053,17 @@ int vnc_display_open(DisplayState *ds, const char *display)
if (reverse) { if (reverse) {
/* connect to viewer */ /* connect to viewer */
if (strncmp(display, "unix:", 5) == 0) int csock;
vs->lsock = unix_connect(display+5, NULL); vs->lsock = -1;
else if (strncmp(display, "unix:", 5) == 0) {
vs->lsock = inet_connect(display, NULL); csock = unix_connect(display+5, NULL);
if (vs->lsock < 0) {
goto fail;
} else { } else {
int csock = vs->lsock; csock = inet_connect(display, NULL);
vs->lsock = -1;
vnc_connect(vs, csock, 0);
} }
return 0; if (csock < 0) {
goto fail;
}
vnc_connect(vs, csock, 0);
} else { } else {
/* listen for connects */ /* listen for connects */
char *dpy; char *dpy;