Romain Vimont
aba1fc03c3
Add acksync helper to wait for acks
...
This will allow to send requests with sequence numbers to the server
and wait for acknowledgements.
PR #2814 <https://github.com/Genymobile/scrcpy/pull/2814 >
2021-11-23 21:15:05 +01:00
RipleyTom
52e5181c84
Add function to parse IPv4 addresses
...
PR #2807 <https://github.com/Genymobile/scrcpy/pull/2807 >
Signed-off-by: Romain Vimont <rom@rom1v.com >
2021-11-21 22:37:37 +01:00
Romain Vimont
ea454e9cee
Add interruptible function to read from pipe
...
This will avoid to block Ctrl+c if the process the pipe is read from
takes too much time.
2021-11-18 19:39:11 +01:00
Romain Vimont
cb65531533
Simplify sc_str_truncate()
...
Use strcspn() to get the prefix length directly.
2021-11-18 19:37:53 +01:00
Romain Vimont
9619ade706
Generalize string trunctation util function
...
Add an additional argument to let the client pass the possible end
chars.
2021-11-18 18:48:16 +01:00
Romain Vimont
f2781a8b6d
Expose util function to truncate first line
...
Move the local implementation from adb functions to the string util
functions.
2021-11-18 18:48:16 +01:00
Romain Vimont
de50846905
Close process on check success
...
The interruptible version of the function to check process success
(sc_process_check_success_intr()) did not accept a close parameter to
avoid a race condition. But as the result, the processes were not closed
at all.
Add a close parameter, and close the process separately to avoid the
race condition.
2021-11-18 18:31:36 +01:00
Romain Vimont
057c7a4df4
Move str_util to str
...
Simplify naming.
2021-11-14 01:22:22 +01:00
Romain Vimont
979ce64dc0
Improve string util API
...
Use prefixed names and improve documentation.
2021-11-14 01:22:22 +01:00
Romain Vimont
9a0bd545d5
Rename SC_INVALID_SOCKET to SC_SOCKET_NONE
...
For consistency with SC_PROCESS_NONE.
2021-11-14 01:22:22 +01:00
Romain Vimont
0d45c29d13
Move IPV4_LOCALHOST to net.h
...
This constant will be used from several files.
2021-11-14 01:22:22 +01:00
Romain Vimont
40340509d9
Add interruptor utilities
...
Expose wrapper functions for interrupting blocking calls, for process
and sockets.
2021-11-13 22:54:18 +01:00
Romain Vimont
e0896142db
Introduce interruptor tool
...
An interruptor instance will help to wake up a blocking call from
another thread (typically to terminate immediately on Ctrl+C).
2021-11-13 22:53:07 +01:00
Romain Vimont
0bfa75a48b
Split socket creation and connect/listen
...
This will allow to assign the socket to a variable before connecting or
listening, so that it can be interrupted from another thread.
2021-11-13 10:05:20 +01:00
Romain Vimont
03de9224fc
Introduce process observer
...
Add a tool to easily observe process termination.
This allows to move this complexity out of the server code.
2021-11-13 10:02:23 +01:00
Romain Vimont
aa011832c1
Improve process API
...
Prefix symbols and constants names and improve documentation.
2021-11-12 22:44:37 +01:00
Romain Vimont
7e93abcf6d
Factorize common impl of process_execute()
...
Both implementations are the same. Move them to the common process.c.
2021-11-12 22:44:37 +01:00
Romain Vimont
e80e6631e4
Remove duplicate function declaration
...
The function process_terminate() was declared twice.
2021-11-12 22:44:37 +01:00
Romain Vimont
fcc04f967b
Improve file API
...
Prefix symbols and constants names and improve documentation.
2021-11-12 22:44:37 +01:00
Romain Vimont
d4c262301f
Move functions from process to file
...
Move filesystem-related functions from process.[ch] to file.[ch].
2021-11-12 22:44:37 +01:00
Romain Vimont
38332f683c
Add util function to get terminal size
2021-11-11 15:22:39 +01:00
Romain Vimont
9ec3406568
Add line wrapper
...
Add a tool to wrap lines at words boundaries (spaces) to fit in a
specified number of columns, left-indented by a specified number of
spaces.
2021-11-11 14:55:53 +01:00
Romain Vimont
6dba1922c1
Add string buffer util
...
This will help to build strings incrementally.
2021-11-11 14:55:52 +01:00
Romain Vimont
48fcfa96ab
Add missing include "common.h"
2021-11-06 19:26:29 +01:00
Romain Vimont
e4d5c1ce36
Move scrcpy option structs to options.h
...
This will allow to define symbols in options.c without all the
dependencies of scrcpy.c.
2021-10-27 18:43:47 +02:00
Romain Vimont
ac23bec144
Expose socket interruption
...
On Linux, socket functions are unblocked by shutdown(), but on Windows
they are unblocked by closesocket().
Expose net_interrupt() and net_close() to abstract these differences:
- net_interrupt() calls shutdown() on Linux and closesocket() on
Windows (if not already called);
- net_close() calls close() on Linux and closesocket() on Windows (if
not already called).
This simplifies the server code, and prevents a data race on close
(reported by TSAN) on Linux (but does not fix it on Windows):
WARNING: ThreadSanitizer: data race (pid=836124)
Write of size 8 at 0x7ba0000000d0 by main thread:
#0 close ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1690 (libtsan.so.0+0x359d8)
#1 net_close ../app/src/util/net.c:211 (scrcpy+0x1c76b)
#2 close_socket ../app/src/server.c:330 (scrcpy+0x19442)
#3 server_stop ../app/src/server.c:522 (scrcpy+0x19e33)
#4 scrcpy ../app/src/scrcpy.c:532 (scrcpy+0x156fc)
#5 main ../app/src/main.c:92 (scrcpy+0x622a)
Previous read of size 8 at 0x7ba0000000d0 by thread T6:
#0 recv ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:6603 (libtsan.so.0+0x4f4a6)
#1 net_recv ../app/src/util/net.c:167 (scrcpy+0x1c5a7)
#2 run_receiver ../app/src/receiver.c:76 (scrcpy+0x12819)
#3 <null> <null> (libSDL2-2.0.so.0+0x84f40)
2021-10-27 18:41:58 +02:00
Romain Vimont
e5ea13770b
Add socket wrapper
...
This paves the way to store an additional "closed" flag on Windows
to interrupt and close properly.
2021-10-26 22:49:57 +02:00
Romain Vimont
3eac212af1
Use net_send() from net_send_all()
...
This will make net_send_all() continue to work even if net_send()
behavior is changed.
2021-10-26 22:49:45 +02:00
Romain Vimont
3adff37c2d
Use sc_ prefix for sockets
...
Rename:
- socket_t to sc_socket
- INVALID_SOCKET to SC_INVALID_SOCKET
2021-10-26 22:49:45 +02:00
Romain Vimont
eb6afe7669
Move net_init() and net_cleanup() upwards
...
These two functions are global, define them at the top of the
implementation file. This is consistent with the header file.
2021-10-26 22:49:45 +02:00
Romain Vimont
0681480809
Add read_pipe_all()
...
Add a convenience function to read from a pipe until all requested data
has been read.
2021-10-26 21:30:04 +02:00
Romain Vimont
eaf4afaad9
Add command execution with redirection
...
Expose command execution with pipes to stdin, stdout and stderr.
This will allow to read the result of adb commands.
2021-10-26 21:30:04 +02:00
Romain Vimont
7229e3cce0
Extract util function to build a local file path
...
Finding a local file in the scrcpy directory may be useful for files
other than scrcpy-server in the future.
2021-10-25 16:29:43 +02:00
Romain Vimont
07d75eb336
Simplify net_send_all()
...
There is no need to declare the variable before the loop.
2021-10-17 16:21:37 +02:00
Romain Vimont
1d1c9f36f4
Retrieve correct error messages on Windows
...
For sockets functions, Windows does not store error codes in errno, so
perror() does not print any error. Use WSAGetLastError() instead.
Refs #2624 <https://github.com/Genymobile/scrcpy/issues/2624 >
2021-09-09 23:03:35 +02:00
Romain Vimont
6f03022646
Fix net_send_all()
...
On partial writes, the final result was the number of bytes written by
the last send() rather than the total.
2021-07-15 18:16:26 +02:00
Romain Vimont
4c4d02295c
Add buffering debugging tools
...
Output buffering and clock logs by disabling a compilation flag.
2021-07-14 14:54:22 +02:00
Romain Vimont
32e692d5d2
Replace delay by deadline in timedwait()
...
The function sc_cond_timedwait() accepted a parameter representing the
max duration to wait, because it internally uses SDL_CondWaitTimeout().
Instead, accept a deadline, to be consistent with
pthread_cond_timedwait().
2021-07-14 14:22:32 +02:00
Romain Vimont
ec871dd3f5
Wrap tick API
...
This avoids to use the SDL timer API directly, and will allow to handle
generic ticks (possibly negative).
2021-07-14 14:22:32 +02:00
Romain Vimont
099cba07f0
Rename queue to sc_queue
...
Add a scrcpy-specific prefix.
2021-07-14 00:35:10 +02:00
Romain Vimont
f33d37976c
Fix assertion race condition in debug mode
...
Commit 21d206f360 added mutex assertions.
However, the "locker" variable to trace the locker thread id was read
and written by several threads without any protection, so it was racy.
Reported by TSAN.
2021-06-26 15:31:50 +02:00
Romain Vimont
488991116b
Expose function to get the current log level
...
This will allow to avoid unnecessary processing for creating logs which
will be discarded anyway.
2021-06-20 16:04:18 +02:00
Romain Vimont
5c95d18beb
Move log level conversion to log API
2021-06-20 16:04:18 +02:00
Romain Vimont
f062dfd30b
Merge branch 'master' into dev
2021-05-09 11:00:30 +02:00
Romain Vimont
ffc00210e9
Add strlist_contains()
...
Add a function to know if a string list, using some separator, contains
a specific string.
2021-04-25 14:38:42 +02:00
Andrea Gelmini
498ad23e98
Fix typos
...
PR #2263 <https://github.com/Genymobile/scrcpy/pull/2263 >
Signed-off-by: Romain Vimont <rom@rom1v.com >
2021-04-18 14:36:31 +02:00
Romain Vimont
c53bd4d8b6
Assert non-recursive usage of mutexes
2021-02-17 09:54:03 +01:00
Romain Vimont
21d206f360
Expose mutex assertions
...
Add a function to assert that the mutex is held (or not).
2021-02-17 09:54:03 +01:00
Romain Vimont
d2689fc168
Expose thread id
2021-02-17 09:54:03 +01:00
Romain Vimont
f6320c7e31
Wrap SDL thread functions into scrcpy-specific API
...
The goal is to expose a consistent API for system tools, and paves the
way to make the "core" independant of SDL in the future.
2021-02-17 09:54:03 +01:00