Cleaning code for pull request

This commit is contained in:
Killian Richard 2020-07-03 11:29:28 +02:00
commit 1e607c6445
6 changed files with 27 additions and 40 deletions

View file

@ -458,9 +458,9 @@ guess_record_format(const char *filename) {
char** char**
str_split(const char *a_str, const char a_delim) { str_split(const char *a_str, const char a_delim) {
char** result = 0; char **result = 0;
size_t count = 0; size_t count = 0;
char* tmp = (char*)a_str; char *tmp = (char*)a_str;
char str[100]; char str[100];
strncpy(str, a_str, sizeof(str)); strncpy(str, a_str, sizeof(str));
char* last_comma = 0; char* last_comma = 0;
@ -480,8 +480,8 @@ str_split(const char *a_str, const char a_delim) {
/* Add space for trailing token. */ /* Add space for trailing token. */
count += last_comma < (str + strlen(str) - 1); count += last_comma < (str + strlen(str) - 1);
/* Add space for terminating null string so caller /* Add space for terminating null string so caller
knows where the list of returned strings ends. */ knows where the list of returned strings ends. */
count++; count++;
result = malloc(sizeof(char*) * count); result = malloc(sizeof(char*) * count);
@ -506,7 +506,7 @@ str_split(const char *a_str, const char a_delim) {
bool bool
check_if_ip_valid(char *ip) { check_if_ip_valid(char *ip) {
int num, dots = 0; int num, dots = 0;
char* ptr; char *ptr;
if (ip == NULL) if (ip == NULL)
return 0; return 0;
@ -539,9 +539,9 @@ check_if_ip_valid(char *ip) {
uint32_t uint32_t
convert_ip_to_int(char* ip_string) { convert_ip_to_int(char* ip_string) {
int num, dots = 0; int num, dots = 0;
char* ptr; char *ptr;
char* ip = "0x"; char *ip = "0x";
ptr = strtok(ip_string, "."); //Cut the string using dot as delimiter ptr = strtok(ip_string, "."); //Cut the string using dot as delimiter
@ -566,12 +566,12 @@ parse_serve_args(const char *optarg, char **s_protocol, uint32_t *s_ip, uint16_t
bool ip_valid = false; bool ip_valid = false;
bool port_valid = false; bool port_valid = false;
char* protocol = NULL; char *protocol = NULL;
char* ip = NULL; char *ip = NULL;
uint32_t ip_value; uint32_t ip_value;
char* port = NULL; char *port = NULL;
char **values;
char** values;
values = str_split(optarg, ':'); values = str_split(optarg, ':');
if (values) { if (values) {
@ -755,8 +755,7 @@ scrcpy_parse_args(struct scrcpy_cli_args *args, int argc, char *argv[]) {
case OPT_SERVE: case OPT_SERVE:
if (!parse_serve_args(optarg, &opts->serve_protocol, &opts->serve_ip, &opts->serve_port)) { if (!parse_serve_args(optarg, &opts->serve_protocol, &opts->serve_ip, &opts->serve_port)) {
return false; return false;
} } else {
else {
opts->serve = true; opts->serve = true;
} }
break; break;

View file

@ -309,7 +309,7 @@ scrcpy(const struct scrcpy_options *options) {
} }
} }
if (!server_start(&server, options->serial, &params, serv)) { if (!server_start(&server, options->serial, &params)) {
return false; return false;
} }

View file

@ -13,7 +13,7 @@
# define SOCKET_ERROR (-1) # define SOCKET_ERROR (-1)
void void
serve_init(struct serve* serve, char *protocol, uint32_t ip, uint16_t port) { serve_init(struct serve *serve, char *protocol, uint32_t ip, uint16_t port) {
serve->protocol = protocol; serve->protocol = protocol;
serve->ip = ip; serve->ip = ip;
serve->port = port; serve->port = port;
@ -21,7 +21,7 @@ serve_init(struct serve* serve, char *protocol, uint32_t ip, uint16_t port) {
} }
bool bool
serve_start(struct serve* serve) { serve_start(struct serve *serve) {
LOGD("Starting serve thread"); LOGD("Starting serve thread");
socket_t Listensocket; socket_t Listensocket;
@ -53,7 +53,7 @@ serve_start(struct serve* serve) {
} }
bool bool
serve_push(struct serve* serve, const AVPacket *packet) { serve_push(struct serve *serve, const AVPacket *packet) {
if (serve->isServeReady) if (serve->isServeReady)
{ {
if (net_send(serve->socket, packet->data, packet->size) == SOCKET_ERROR) { if (net_send(serve->socket, packet->data, packet->size) == SOCKET_ERROR) {
@ -68,6 +68,6 @@ serve_push(struct serve* serve, const AVPacket *packet) {
} }
void void
serve_stop(struct serve* serve) { serve_stop(struct serve *serve) {
net_close(serve->socket); net_close(serve->socket);
} }

View file

@ -19,14 +19,14 @@ struct serve {
}; };
void void
serve_init(struct serve* serve, char* protocol, uint32_t ip, uint16_t port); serve_init(struct serve *serve, char *protocol, uint32_t ip, uint16_t port);
bool bool
serve_start(struct serve* serve); serve_start(struct serve *serve);
bool bool
serve_push(struct serve* serve, const AVPacket *packet); serve_push(struct serve *serve, const AVPacket *packet);
void void
serve_stop(struct serve* serve); serve_stop(struct serve *serve);
#endif #endif

View file

@ -350,7 +350,7 @@ run_wait_server(void *data) {
bool bool
server_start(struct server *server, const char *serial, server_start(struct server *server, const char *serial,
const struct server_params *params, struct serve* serve) { const struct server_params *params) {
server->port_range = params->port_range; server->port_range = params->port_range;
if (serial) { if (serial) {
@ -368,22 +368,10 @@ server_start(struct server *server, const char *serial,
goto error1; goto error1;
} }
/*server->serve = serve; server->process = execute_server(server, params);
if (server->serve) { if (server->process == PROCESS_NONE) {
if (server->serve->isServeReady == true) { goto error2;
server->process = execute_server(server, params);
if (server->process == PROCESS_NONE) {
goto error2;
}
}
} }
else {*/
// server will connect to our server socket
server->process = execute_server(server, params);
if (server->process == PROCESS_NONE) {
goto error2;
}
//}
// If the server process dies before connecting to the server socket, then // If the server process dies before connecting to the server socket, then
// the client will be stuck forever on accept(). To avoid the problem, we // the client will be stuck forever on accept(). To avoid the problem, we

View file

@ -61,7 +61,7 @@ server_init(struct server *server);
// push, enable tunnel et start the server // push, enable tunnel et start the server
bool bool
server_start(struct server *server, const char *serial, server_start(struct server *server, const char *serial,
const struct server_params *params, struct serve* serve); const struct server_params *params);
// block until the communication with the server is established // block until the communication with the server is established
bool bool