LibC: Implement pthread cancelation
This code is not tested at all but it looks correct xD
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return accept4(socket, address, address_len, 0);
|
||||
}
|
||||
|
||||
int accept4(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return syscall(SYS_ACCEPT, socket, address, address_len, flags);
|
||||
}
|
||||
|
||||
@@ -19,6 +22,7 @@ int bind(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||
|
||||
int connect(int socket, const struct sockaddr* address, socklen_t address_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return syscall(SYS_CONNECT, socket, address, address_len);
|
||||
}
|
||||
|
||||
@@ -29,11 +33,13 @@ int listen(int socket, int backlog)
|
||||
|
||||
ssize_t recv(int socket, void* __restrict buffer, size_t length, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return recvfrom(socket, buffer, length, flags, nullptr, nullptr);
|
||||
}
|
||||
|
||||
ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags, struct sockaddr* __restrict address, socklen_t* __restrict address_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
sys_recvfrom_t arguments {
|
||||
.socket = socket,
|
||||
.buffer = buffer,
|
||||
@@ -47,11 +53,13 @@ ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags,
|
||||
|
||||
ssize_t send(int socket, const void* message, size_t length, int flags)
|
||||
{
|
||||
pthread_testcancel();
|
||||
return sendto(socket, message, length, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
ssize_t sendto(int socket, const void* message, size_t length, int flags, const struct sockaddr* dest_addr, socklen_t dest_len)
|
||||
{
|
||||
pthread_testcancel();
|
||||
sys_sendto_t arguments {
|
||||
.socket = socket,
|
||||
.message = message,
|
||||
|
||||
Reference in New Issue
Block a user