Rename SC_INVALID_SOCKET to SC_SOCKET_NONE
For consistency with SC_PROCESS_NONE.
This commit is contained in:
parent
c4d008b96a
commit
9a0bd545d5
7 changed files with 39 additions and 39 deletions
|
@ -59,7 +59,7 @@ enable_tunnel_reverse_any_port(struct sc_adb_tunnel *tunnel,
|
||||||
// need to try to connect until the server socket is listening on the
|
// need to try to connect until the server socket is listening on the
|
||||||
// device.
|
// device.
|
||||||
sc_socket server_socket = net_socket();
|
sc_socket server_socket = net_socket();
|
||||||
if (server_socket != SC_INVALID_SOCKET) {
|
if (server_socket != SC_SOCKET_NONE) {
|
||||||
bool ok = listen_on_port(intr, server_socket, port);
|
bool ok = listen_on_port(intr, server_socket, port);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// success
|
// success
|
||||||
|
@ -141,7 +141,7 @@ void
|
||||||
sc_adb_tunnel_init(struct sc_adb_tunnel *tunnel) {
|
sc_adb_tunnel_init(struct sc_adb_tunnel *tunnel) {
|
||||||
tunnel->enabled = false;
|
tunnel->enabled = false;
|
||||||
tunnel->forward = false;
|
tunnel->forward = false;
|
||||||
tunnel->server_socket = SC_INVALID_SOCKET;
|
tunnel->server_socket = SC_SOCKET_NONE;
|
||||||
tunnel->local_port = 0;
|
tunnel->local_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ sc_adb_tunnel_close(struct sc_adb_tunnel *tunnel, struct sc_intr *intr,
|
||||||
} else {
|
} else {
|
||||||
ret = disable_tunnel_reverse(intr, serial);
|
ret = disable_tunnel_reverse(intr, serial);
|
||||||
|
|
||||||
assert(tunnel->server_socket != SC_INVALID_SOCKET);
|
assert(tunnel->server_socket != SC_SOCKET_NONE);
|
||||||
if (!net_close(tunnel->server_socket)) {
|
if (!net_close(tunnel->server_socket)) {
|
||||||
LOGW("Could not close server socket");
|
LOGW("Could not close server socket");
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ connect_to_server(struct server *server, uint32_t attempts, sc_tick delay) {
|
||||||
do {
|
do {
|
||||||
LOGD("Remaining connection attempts: %d", (int) attempts);
|
LOGD("Remaining connection attempts: %d", (int) attempts);
|
||||||
sc_socket socket = net_socket();
|
sc_socket socket = net_socket();
|
||||||
if (socket != SC_INVALID_SOCKET) {
|
if (socket != SC_SOCKET_NONE) {
|
||||||
bool ok = connect_and_read_byte(&server->intr, socket, port);
|
bool ok = connect_and_read_byte(&server->intr, socket, port);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// it worked!
|
// it worked!
|
||||||
|
@ -249,7 +249,7 @@ connect_to_server(struct server *server, uint32_t attempts, sc_tick delay) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (--attempts > 0);
|
} while (--attempts > 0);
|
||||||
return SC_INVALID_SOCKET;
|
return SC_SOCKET_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -287,8 +287,8 @@ server_init(struct server *server, const struct server_params *params,
|
||||||
|
|
||||||
server->stopped = false;
|
server->stopped = false;
|
||||||
|
|
||||||
server->video_socket = SC_INVALID_SOCKET;
|
server->video_socket = SC_SOCKET_NONE;
|
||||||
server->control_socket = SC_INVALID_SOCKET;
|
server->control_socket = SC_SOCKET_NONE;
|
||||||
|
|
||||||
sc_adb_tunnel_init(&server->tunnel);
|
sc_adb_tunnel_init(&server->tunnel);
|
||||||
|
|
||||||
|
@ -331,29 +331,29 @@ server_connect_to(struct server *server, struct server_info *info) {
|
||||||
|
|
||||||
const char *serial = server->params.serial;
|
const char *serial = server->params.serial;
|
||||||
|
|
||||||
sc_socket video_socket = SC_INVALID_SOCKET;
|
sc_socket video_socket = SC_SOCKET_NONE;
|
||||||
sc_socket control_socket = SC_INVALID_SOCKET;
|
sc_socket control_socket = SC_SOCKET_NONE;
|
||||||
if (!tunnel->forward) {
|
if (!tunnel->forward) {
|
||||||
video_socket = net_accept_intr(&server->intr, tunnel->server_socket);
|
video_socket = net_accept_intr(&server->intr, tunnel->server_socket);
|
||||||
if (video_socket == SC_INVALID_SOCKET) {
|
if (video_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
control_socket = net_accept_intr(&server->intr, tunnel->server_socket);
|
control_socket = net_accept_intr(&server->intr, tunnel->server_socket);
|
||||||
if (control_socket == SC_INVALID_SOCKET) {
|
if (control_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint32_t attempts = 100;
|
uint32_t attempts = 100;
|
||||||
sc_tick delay = SC_TICK_FROM_MS(100);
|
sc_tick delay = SC_TICK_FROM_MS(100);
|
||||||
video_socket = connect_to_server(server, attempts, delay);
|
video_socket = connect_to_server(server, attempts, delay);
|
||||||
if (video_socket == SC_INVALID_SOCKET) {
|
if (video_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we know that the device is listening, we don't need several attempts
|
// we know that the device is listening, we don't need several attempts
|
||||||
control_socket = net_socket();
|
control_socket = net_socket();
|
||||||
if (control_socket == SC_INVALID_SOCKET) {
|
if (control_socket == SC_SOCKET_NONE) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
bool ok = net_connect_intr(&server->intr, control_socket,
|
bool ok = net_connect_intr(&server->intr, control_socket,
|
||||||
|
@ -372,8 +372,8 @@ server_connect_to(struct server *server, struct server_info *info) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(video_socket != SC_INVALID_SOCKET);
|
assert(video_socket != SC_SOCKET_NONE);
|
||||||
assert(control_socket != SC_INVALID_SOCKET);
|
assert(control_socket != SC_SOCKET_NONE);
|
||||||
|
|
||||||
server->video_socket = video_socket;
|
server->video_socket = video_socket;
|
||||||
server->control_socket = control_socket;
|
server->control_socket = control_socket;
|
||||||
|
@ -381,13 +381,13 @@ server_connect_to(struct server *server, struct server_info *info) {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (video_socket != SC_INVALID_SOCKET) {
|
if (video_socket != SC_SOCKET_NONE) {
|
||||||
if (!net_close(video_socket)) {
|
if (!net_close(video_socket)) {
|
||||||
LOGW("Could not close video socket");
|
LOGW("Could not close video socket");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (control_socket != SC_INVALID_SOCKET) {
|
if (control_socket != SC_SOCKET_NONE) {
|
||||||
if (!net_close(control_socket)) {
|
if (!net_close(control_socket)) {
|
||||||
LOGW("Could not close control socket");
|
LOGW("Could not close control socket");
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ sc_intr_init(struct sc_intr *intr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
intr->socket = SC_INVALID_SOCKET;
|
intr->socket = SC_SOCKET_NONE;
|
||||||
intr->process = SC_PROCESS_NONE;
|
intr->process = SC_PROCESS_NONE;
|
||||||
|
|
||||||
atomic_store_explicit(&intr->interrupted, false, memory_order_relaxed);
|
atomic_store_explicit(&intr->interrupted, false, memory_order_relaxed);
|
||||||
|
@ -37,7 +37,7 @@ sc_intr_set_socket(struct sc_intr *intr, sc_socket socket) {
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_intr_set_process(struct sc_intr *intr, sc_pid pid) {
|
sc_intr_set_process(struct sc_intr *intr, sc_pid pid) {
|
||||||
assert(intr->socket == SC_INVALID_SOCKET);
|
assert(intr->socket == SC_SOCKET_NONE);
|
||||||
|
|
||||||
sc_mutex_lock(&intr->mutex);
|
sc_mutex_lock(&intr->mutex);
|
||||||
bool interrupted =
|
bool interrupted =
|
||||||
|
@ -57,13 +57,13 @@ sc_intr_interrupt(struct sc_intr *intr) {
|
||||||
atomic_store_explicit(&intr->interrupted, true, memory_order_relaxed);
|
atomic_store_explicit(&intr->interrupted, true, memory_order_relaxed);
|
||||||
|
|
||||||
// No more than one component to interrupt
|
// No more than one component to interrupt
|
||||||
assert(intr->socket == SC_INVALID_SOCKET ||
|
assert(intr->socket == SC_SOCKET_NONE ||
|
||||||
intr->process == SC_PROCESS_NONE);
|
intr->process == SC_PROCESS_NONE);
|
||||||
|
|
||||||
if (intr->socket != SC_INVALID_SOCKET) {
|
if (intr->socket != SC_SOCKET_NONE) {
|
||||||
LOGD("Interrupting socket");
|
LOGD("Interrupting socket");
|
||||||
net_interrupt(intr->socket);
|
net_interrupt(intr->socket);
|
||||||
intr->socket = SC_INVALID_SOCKET;
|
intr->socket = SC_SOCKET_NONE;
|
||||||
}
|
}
|
||||||
if (intr->process != SC_PROCESS_NONE) {
|
if (intr->process != SC_PROCESS_NONE) {
|
||||||
LOGD("Interrupting process");
|
LOGD("Interrupting process");
|
||||||
|
@ -76,7 +76,7 @@ sc_intr_interrupt(struct sc_intr *intr) {
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_intr_destroy(struct sc_intr *intr) {
|
sc_intr_destroy(struct sc_intr *intr) {
|
||||||
assert(intr->socket == SC_INVALID_SOCKET);
|
assert(intr->socket == SC_SOCKET_NONE);
|
||||||
assert(intr->process == SC_PROCESS_NONE);
|
assert(intr->process == SC_PROCESS_NONE);
|
||||||
|
|
||||||
sc_mutex_destroy(&intr->mutex);
|
sc_mutex_destroy(&intr->mutex);
|
||||||
|
|
|
@ -37,7 +37,7 @@ sc_intr_init(struct sc_intr *intr);
|
||||||
/**
|
/**
|
||||||
* Set a socket as the interruptible component
|
* Set a socket as the interruptible component
|
||||||
*
|
*
|
||||||
* Call with SC_INVALID_SOCKET to unset.
|
* Call with SC_SOCKET_NONE to unset.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
sc_intr_set_socket(struct sc_intr *intr, sc_socket socket);
|
sc_intr_set_socket(struct sc_intr *intr, sc_socket socket);
|
||||||
|
|
|
@ -46,13 +46,13 @@ static inline sc_socket
|
||||||
wrap(sc_raw_socket sock) {
|
wrap(sc_raw_socket sock) {
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
if (sock == INVALID_SOCKET) {
|
if (sock == INVALID_SOCKET) {
|
||||||
return SC_INVALID_SOCKET;
|
return SC_SOCKET_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sc_socket_windows *socket = malloc(sizeof(*socket));
|
struct sc_socket_windows *socket = malloc(sizeof(*socket));
|
||||||
if (!socket) {
|
if (!socket) {
|
||||||
closesocket(sock);
|
closesocket(sock);
|
||||||
return SC_INVALID_SOCKET;
|
return SC_SOCKET_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket->socket = sock;
|
socket->socket = sock;
|
||||||
|
@ -67,7 +67,7 @@ wrap(sc_raw_socket sock) {
|
||||||
static inline sc_raw_socket
|
static inline sc_raw_socket
|
||||||
unwrap(sc_socket socket) {
|
unwrap(sc_socket socket) {
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
if (socket == SC_INVALID_SOCKET) {
|
if (socket == SC_SOCKET_NONE) {
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ sc_socket
|
||||||
net_socket(void) {
|
net_socket(void) {
|
||||||
sc_raw_socket raw_sock = socket(AF_INET, SOCK_STREAM, 0);
|
sc_raw_socket raw_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
sc_socket sock = wrap(raw_sock);
|
sc_socket sock = wrap(raw_sock);
|
||||||
if (sock == SC_INVALID_SOCKET) {
|
if (sock == SC_SOCKET_NONE) {
|
||||||
net_perror("socket");
|
net_perror("socket");
|
||||||
}
|
}
|
||||||
return sock;
|
return sock;
|
||||||
|
@ -195,7 +195,7 @@ net_send_all(sc_socket socket, const void *buf, size_t len) {
|
||||||
|
|
||||||
bool
|
bool
|
||||||
net_interrupt(sc_socket socket) {
|
net_interrupt(sc_socket socket) {
|
||||||
assert(socket != SC_INVALID_SOCKET);
|
assert(socket != SC_SOCKET_NONE);
|
||||||
|
|
||||||
sc_raw_socket raw_sock = unwrap(socket);
|
sc_raw_socket raw_sock = unwrap(socket);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
# include <stdatomic.h>
|
# include <stdatomic.h>
|
||||||
# define SC_INVALID_SOCKET NULL
|
# define SC_SOCKET_NONE NULL
|
||||||
typedef struct sc_socket_windows {
|
typedef struct sc_socket_windows {
|
||||||
SOCKET socket;
|
SOCKET socket;
|
||||||
atomic_flag closed;
|
atomic_flag closed;
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
#else // not __WINDOWS__
|
#else // not __WINDOWS__
|
||||||
|
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
# define SC_INVALID_SOCKET -1
|
# define SC_SOCKET_NONE -1
|
||||||
typedef int sc_socket;
|
typedef int sc_socket;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,7 +10,7 @@ net_connect_intr(struct sc_intr *intr, sc_socket socket, uint32_t addr,
|
||||||
|
|
||||||
bool ret = net_connect(socket, addr, port);
|
bool ret = net_connect(socket, addr, port);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ net_listen_intr(struct sc_intr *intr, sc_socket socket, uint32_t addr,
|
||||||
|
|
||||||
bool ret = net_listen(socket, addr, port, backlog);
|
bool ret = net_listen(socket, addr, port, backlog);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +32,12 @@ sc_socket
|
||||||
net_accept_intr(struct sc_intr *intr, sc_socket server_socket) {
|
net_accept_intr(struct sc_intr *intr, sc_socket server_socket) {
|
||||||
if (!sc_intr_set_socket(intr, server_socket)) {
|
if (!sc_intr_set_socket(intr, server_socket)) {
|
||||||
// Already interrupted
|
// Already interrupted
|
||||||
return SC_INVALID_SOCKET;
|
return SC_SOCKET_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_socket socket = net_accept(server_socket);
|
sc_socket socket = net_accept(server_socket);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ net_recv_intr(struct sc_intr *intr, sc_socket socket, void *buf, size_t len) {
|
||||||
|
|
||||||
ssize_t r = net_recv(socket, buf, len);
|
ssize_t r = net_recv(socket, buf, len);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ net_recv_all_intr(struct sc_intr *intr, sc_socket socket, void *buf,
|
||||||
|
|
||||||
ssize_t r = net_recv_all(socket, buf, len);
|
ssize_t r = net_recv_all(socket, buf, len);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ net_send_intr(struct sc_intr *intr, sc_socket socket, const void *buf,
|
||||||
|
|
||||||
ssize_t w = net_send(socket, buf, len);
|
ssize_t w = net_send(socket, buf, len);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,6 @@ net_send_all_intr(struct sc_intr *intr, sc_socket socket, const void *buf,
|
||||||
|
|
||||||
ssize_t w = net_send_all(socket, buf, len);
|
ssize_t w = net_send_all(socket, buf, len);
|
||||||
|
|
||||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue