2021-11-13 01:50:50 +08:00
|
|
|
#include "net_intr.h"
|
|
|
|
|
|
|
|
bool
|
|
|
|
net_connect_intr(struct sc_intr *intr, sc_socket socket, uint32_t addr,
|
|
|
|
uint16_t port) {
|
|
|
|
if (!sc_intr_set_socket(intr, socket)) {
|
|
|
|
// Already interrupted
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = net_connect(socket, addr, port);
|
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2022-08-17 22:38:59 +08:00
|
|
|
net_listen_intr(struct sc_intr *intr, sc_socket server_socket, uint32_t addr,
|
2021-11-13 01:50:50 +08:00
|
|
|
uint16_t port, int backlog) {
|
2022-08-17 22:38:59 +08:00
|
|
|
if (!sc_intr_set_socket(intr, server_socket)) {
|
2021-11-13 01:50:50 +08:00
|
|
|
// Already interrupted
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-17 22:38:59 +08:00
|
|
|
bool ret = net_listen(server_socket, addr, port, backlog);
|
2021-11-13 01:50:50 +08:00
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc_socket
|
|
|
|
net_accept_intr(struct sc_intr *intr, sc_socket server_socket) {
|
|
|
|
if (!sc_intr_set_socket(intr, server_socket)) {
|
|
|
|
// Already interrupted
|
2021-11-13 16:58:52 +08:00
|
|
|
return SC_SOCKET_NONE;
|
2021-11-13 01:50:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sc_socket socket = net_accept(server_socket);
|
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
net_recv_intr(struct sc_intr *intr, sc_socket socket, void *buf, size_t len) {
|
|
|
|
if (!sc_intr_set_socket(intr, socket)) {
|
|
|
|
// Already interrupted
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t r = net_recv(socket, buf, len);
|
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
net_recv_all_intr(struct sc_intr *intr, sc_socket socket, void *buf,
|
|
|
|
size_t len) {
|
|
|
|
if (!sc_intr_set_socket(intr, socket)) {
|
|
|
|
// Already interrupted
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t r = net_recv_all(socket, buf, len);
|
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
net_send_intr(struct sc_intr *intr, sc_socket socket, const void *buf,
|
|
|
|
size_t len) {
|
|
|
|
if (!sc_intr_set_socket(intr, socket)) {
|
|
|
|
// Already interrupted
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t w = net_send(socket, buf, len);
|
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
net_send_all_intr(struct sc_intr *intr, sc_socket socket, const void *buf,
|
|
|
|
size_t len) {
|
|
|
|
if (!sc_intr_set_socket(intr, socket)) {
|
|
|
|
// Already interrupted
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t w = net_send_all(socket, buf, len);
|
|
|
|
|
2021-11-13 16:58:52 +08:00
|
|
|
sc_intr_set_socket(intr, SC_SOCKET_NONE);
|
2021-11-13 01:50:50 +08:00
|
|
|
return w;
|
|
|
|
}
|