Make intr optional for adb commands
All adb commands are executed with an "interruptor", so that they can be interrupted on Ctrl+C. Make this interruptor optional, so that we could call "adb kill-server" in OTG mode. This command always returns almost immediately anyway. Ideally, we should make all blocking calls interruptible (including libusb calls, by using the asynchronous API), but it's a lot of work, and in practice it works well enough. PR #3011 <https://github.com/Genymobile/scrcpy/pull/3011>
This commit is contained in:
parent
6ee75c0cff
commit
3bb24b3926
2 changed files with 14 additions and 6 deletions
|
@ -150,7 +150,7 @@ process_check_success_internal(sc_pid pid, const char *name, bool close,
|
||||||
static bool
|
static bool
|
||||||
process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
||||||
unsigned flags) {
|
unsigned flags) {
|
||||||
if (!sc_intr_set_process(intr, pid)) {
|
if (intr && !sc_intr_set_process(intr, pid)) {
|
||||||
// Already interrupted
|
// Already interrupted
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,9 @@ process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name,
|
||||||
// Always pass close=false, interrupting would be racy otherwise
|
// Always pass close=false, interrupting would be racy otherwise
|
||||||
bool ret = process_check_success_internal(pid, name, false, flags);
|
bool ret = process_check_success_internal(pid, name, false, flags);
|
||||||
|
|
||||||
|
if (intr) {
|
||||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
// Close separately
|
// Close separately
|
||||||
sc_process_close(pid);
|
sc_process_close(pid);
|
||||||
|
|
|
@ -3,27 +3,33 @@
|
||||||
ssize_t
|
ssize_t
|
||||||
sc_pipe_read_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe, char *data,
|
sc_pipe_read_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe, char *data,
|
||||||
size_t len) {
|
size_t len) {
|
||||||
if (!sc_intr_set_process(intr, pid)) {
|
if (intr && !sc_intr_set_process(intr, pid)) {
|
||||||
// Already interrupted
|
// Already interrupted
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ret = sc_pipe_read(pipe, data, len);
|
ssize_t ret = sc_pipe_read(pipe, data, len);
|
||||||
|
|
||||||
|
if (intr) {
|
||||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
sc_pipe_read_all_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe,
|
sc_pipe_read_all_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe,
|
||||||
char *data, size_t len) {
|
char *data, size_t len) {
|
||||||
if (!sc_intr_set_process(intr, pid)) {
|
if (intr && !sc_intr_set_process(intr, pid)) {
|
||||||
// Already interrupted
|
// Already interrupted
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ret = sc_pipe_read_all(pipe, data, len);
|
ssize_t ret = sc_pipe_read_all(pipe, data, len);
|
||||||
|
|
||||||
|
if (intr) {
|
||||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue