Rename SC_INVALID_SOCKET to SC_SOCKET_NONE
For consistency with SC_PROCESS_NONE.
This commit is contained in:
@@ -12,7 +12,7 @@ sc_intr_init(struct sc_intr *intr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
intr->socket = SC_INVALID_SOCKET;
|
||||
intr->socket = SC_SOCKET_NONE;
|
||||
intr->process = SC_PROCESS_NONE;
|
||||
|
||||
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
|
||||
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);
|
||||
bool interrupted =
|
||||
@@ -57,13 +57,13 @@ sc_intr_interrupt(struct sc_intr *intr) {
|
||||
atomic_store_explicit(&intr->interrupted, true, memory_order_relaxed);
|
||||
|
||||
// No more than one component to interrupt
|
||||
assert(intr->socket == SC_INVALID_SOCKET ||
|
||||
assert(intr->socket == SC_SOCKET_NONE ||
|
||||
intr->process == SC_PROCESS_NONE);
|
||||
|
||||
if (intr->socket != SC_INVALID_SOCKET) {
|
||||
if (intr->socket != SC_SOCKET_NONE) {
|
||||
LOGD("Interrupting socket");
|
||||
net_interrupt(intr->socket);
|
||||
intr->socket = SC_INVALID_SOCKET;
|
||||
intr->socket = SC_SOCKET_NONE;
|
||||
}
|
||||
if (intr->process != SC_PROCESS_NONE) {
|
||||
LOGD("Interrupting process");
|
||||
@@ -76,7 +76,7 @@ sc_intr_interrupt(struct sc_intr *intr) {
|
||||
|
||||
void
|
||||
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);
|
||||
|
||||
sc_mutex_destroy(&intr->mutex);
|
||||
|
||||
@@ -37,7 +37,7 @@ sc_intr_init(struct sc_intr *intr);
|
||||
/**
|
||||
* Set a socket as the interruptible component
|
||||
*
|
||||
* Call with SC_INVALID_SOCKET to unset.
|
||||
* Call with SC_SOCKET_NONE to unset.
|
||||
*/
|
||||
bool
|
||||
sc_intr_set_socket(struct sc_intr *intr, sc_socket socket);
|
||||
|
||||
@@ -46,13 +46,13 @@ static inline sc_socket
|
||||
wrap(sc_raw_socket sock) {
|
||||
#ifdef __WINDOWS__
|
||||
if (sock == INVALID_SOCKET) {
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
struct sc_socket_windows *socket = malloc(sizeof(*socket));
|
||||
if (!socket) {
|
||||
closesocket(sock);
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
socket->socket = sock;
|
||||
@@ -67,7 +67,7 @@ wrap(sc_raw_socket sock) {
|
||||
static inline sc_raw_socket
|
||||
unwrap(sc_socket socket) {
|
||||
#ifdef __WINDOWS__
|
||||
if (socket == SC_INVALID_SOCKET) {
|
||||
if (socket == SC_SOCKET_NONE) {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ sc_socket
|
||||
net_socket(void) {
|
||||
sc_raw_socket raw_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
sc_socket sock = wrap(raw_sock);
|
||||
if (sock == SC_INVALID_SOCKET) {
|
||||
if (sock == SC_SOCKET_NONE) {
|
||||
net_perror("socket");
|
||||
}
|
||||
return sock;
|
||||
@@ -195,7 +195,7 @@ net_send_all(sc_socket socket, const void *buf, size_t len) {
|
||||
|
||||
bool
|
||||
net_interrupt(sc_socket socket) {
|
||||
assert(socket != SC_INVALID_SOCKET);
|
||||
assert(socket != SC_SOCKET_NONE);
|
||||
|
||||
sc_raw_socket raw_sock = unwrap(socket);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
# include <winsock2.h>
|
||||
# include <stdatomic.h>
|
||||
# define SC_INVALID_SOCKET NULL
|
||||
# define SC_SOCKET_NONE NULL
|
||||
typedef struct sc_socket_windows {
|
||||
SOCKET socket;
|
||||
atomic_flag closed;
|
||||
@@ -20,7 +20,7 @@
|
||||
#else // not __WINDOWS__
|
||||
|
||||
# include <sys/socket.h>
|
||||
# define SC_INVALID_SOCKET -1
|
||||
# define SC_SOCKET_NONE -1
|
||||
typedef int sc_socket;
|
||||
|
||||
#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);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
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);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ sc_socket
|
||||
net_accept_intr(struct sc_intr *intr, sc_socket server_socket) {
|
||||
if (!sc_intr_set_socket(intr, server_socket)) {
|
||||
// Already interrupted
|
||||
return SC_INVALID_SOCKET;
|
||||
return SC_SOCKET_NONE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
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);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
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);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
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);
|
||||
|
||||
sc_intr_set_socket(intr, SC_INVALID_SOCKET);
|
||||
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
||||
return w;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user