Report server connection state
We must distinguish 3 cases for await_for_server(): - an error occurred - no error occurred, the device is connected - no error occurred, the device is not connected (user requested to quit) For this purpose, use an additional output parameter to indicate if the device is connected (only set when no error occurs). Refs #3085 <https://github.com/Genymobile/scrcpy/pull/3085>
This commit is contained in:
parent
8d91cda4f6
commit
1f4c801f3c
1 changed files with 13 additions and 3 deletions
|
@ -168,19 +168,22 @@ event_loop(struct scrcpy *s) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return true on success, false on error
|
||||||
static bool
|
static bool
|
||||||
await_for_server(void) {
|
await_for_server(bool *connected) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_WaitEvent(&event)) {
|
while (SDL_WaitEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
LOGD("User requested to quit");
|
LOGD("User requested to quit");
|
||||||
return false;
|
*connected = false;
|
||||||
|
return true;
|
||||||
case EVENT_SERVER_CONNECTION_FAILED:
|
case EVENT_SERVER_CONNECTION_FAILED:
|
||||||
LOGE("Server connection failed");
|
LOGE("Server connection failed");
|
||||||
return false;
|
return false;
|
||||||
case EVENT_SERVER_CONNECTED:
|
case EVENT_SERVER_CONNECTED:
|
||||||
LOGD("Server connected");
|
LOGD("Server connected");
|
||||||
|
*connected = true;
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -351,7 +354,14 @@ scrcpy(struct scrcpy_options *options) {
|
||||||
sdl_configure(options->display, options->disable_screensaver);
|
sdl_configure(options->display, options->disable_screensaver);
|
||||||
|
|
||||||
// Await for server without blocking Ctrl+C handling
|
// Await for server without blocking Ctrl+C handling
|
||||||
if (!await_for_server()) {
|
bool connected;
|
||||||
|
if (!await_for_server(&connected)) {
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connected) {
|
||||||
|
// This is not an error, user requested to quit
|
||||||
|
ret = true;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue