mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 12:30:30 +00:00
Fix flakes in runitd and popen_test
This commit is contained in:
parent
801224df67
commit
2ebc5781a1
18 changed files with 123 additions and 34 deletions
|
@ -18,10 +18,13 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/struct/fd.internal.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/syscall_fd.internal.h"
|
||||
|
||||
__msabi extern typeof(__sys_bind_nt) *const __imp_bind;
|
||||
|
||||
textwindows int sys_bind_nt(struct Fd *fd, const void *addr,
|
||||
uint32_t addrsize) {
|
||||
unassert(fd->kind == kFdSocket);
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/syscall_fd.internal.h"
|
||||
|
||||
__msabi extern typeof(__sys_closesocket_nt) *const __imp_closesocket;
|
||||
|
||||
/**
|
||||
* Closes socket on Windows.
|
||||
*
|
||||
|
@ -30,7 +33,7 @@ textwindows int sys_closesocket_nt(struct Fd *fd) {
|
|||
struct SockFd *sockfd;
|
||||
sockfd = (struct SockFd *)fd->extra;
|
||||
free(sockfd);
|
||||
int rc = __sys_closesocket_nt(fd->handle);
|
||||
int rc = __imp_closesocket(fd->handle);
|
||||
if (rc != -1) {
|
||||
return 0;
|
||||
} else {
|
||||
|
|
|
@ -19,13 +19,12 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
textwindows struct SockFd *_dupsockfd(struct SockFd *sockfd) {
|
||||
struct SockFd *newsf;
|
||||
if ((newsf = calloc(1, sizeof(struct SockFd)))) {
|
||||
newsf->family = sockfd->family;
|
||||
newsf->type = sockfd->type;
|
||||
newsf->protocol = sockfd->protocol;
|
||||
if ((newsf = malloc(sizeof(struct SockFd)))) {
|
||||
memcpy(newsf, sockfd, sizeof(*sockfd));
|
||||
}
|
||||
return newsf;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/nt/struct/linger.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
|
@ -29,6 +30,8 @@
|
|||
#include "libc/sysv/consts/sol.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
__msabi extern typeof(__sys_getsockopt_nt) *const __imp_getsockopt;
|
||||
|
||||
textwindows int sys_getsockopt_nt(struct Fd *fd, int level, int optname,
|
||||
void *out_opt_optval,
|
||||
uint32_t *inout_optlen) {
|
||||
|
@ -63,8 +66,8 @@ textwindows int sys_getsockopt_nt(struct Fd *fd, int level, int optname,
|
|||
}
|
||||
|
||||
// TODO(jart): Use WSAIoctl?
|
||||
if (__sys_getsockopt_nt(fd->handle, level, optname, out_opt_optval,
|
||||
inout_optlen) == -1) {
|
||||
if (__imp_getsockopt(fd->handle, level, optname, out_opt_optval,
|
||||
inout_optlen) == -1) {
|
||||
return __winsockerr();
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ int sys_select_nt(int, fd_set *, fd_set *, fd_set *, struct timeval *,
|
|||
size_t __iovec2nt(struct NtIovec[hasatleast 16], const struct iovec *, size_t);
|
||||
|
||||
void WinSockInit(void);
|
||||
int64_t __winsockerr(void) nocallback;
|
||||
int64_t __winsockerr(void);
|
||||
int __fixupnewsockfd(int, int);
|
||||
int64_t __winsockblock(int64_t, unsigned, int64_t, uint32_t);
|
||||
struct SockFd *_dupsockfd(struct SockFd *);
|
||||
|
|
|
@ -17,13 +17,16 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/syscall_fd.internal.h"
|
||||
|
||||
__msabi extern typeof(__sys_listen_nt) *const __imp_listen;
|
||||
|
||||
textwindows int sys_listen_nt(struct Fd *fd, int backlog) {
|
||||
npassert(fd->kind == kFdSocket);
|
||||
if (__sys_listen_nt(fd->handle, backlog) != -1) {
|
||||
if (__imp_listen(fd->handle, backlog) != -1) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winsockerr();
|
||||
|
|
|
@ -34,12 +34,15 @@
|
|||
/**
|
||||
* Receives data from network.
|
||||
*
|
||||
* This function blocks unless MSG_DONTWAIT is passed.
|
||||
*
|
||||
* @param fd is the file descriptor returned by socket()
|
||||
* @param buf is where received network data gets copied
|
||||
* @param size is the byte capacity of buf
|
||||
* @param flags can have MSG_{WAITALL,DONTROUTE,PEEK,OOB}, etc.
|
||||
* @param flags is a bitmask which may contain any of the following:
|
||||
* - `MSG_DONTWAIT` to force `O_NONBLOCK` behavior for this call
|
||||
* - `MSG_OOB` is broadly supported (untested by cosmo)
|
||||
* - `MSG_PEEK` is broadly supported (untested by cosmo)
|
||||
* - `MSG_WAITALL` is broadly supported (untested by cosmo)
|
||||
* - `MSG_DONTROUTE` is broadly supported (untested by cosmo)
|
||||
* @param opt_out_srcaddr receives the binary ip:port of the data's origin
|
||||
* @param opt_inout_srcaddrsize is srcaddr capacity which gets updated
|
||||
* @return number of bytes received, 0 on remote close, or -1 w/ errno
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "libc/limits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/struct/linger.h"
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/struct/linger.h"
|
||||
#include "libc/sock/syscall_fd.internal.h"
|
||||
|
@ -28,6 +29,8 @@
|
|||
#include "libc/sysv/consts/sol.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
__msabi extern typeof(__sys_setsockopt_nt) *const __imp_setsockopt;
|
||||
|
||||
textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname,
|
||||
const void *optval, uint32_t optlen) {
|
||||
int64_t ms, micros;
|
||||
|
@ -70,7 +73,7 @@ textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname,
|
|||
}
|
||||
}
|
||||
|
||||
if (__sys_setsockopt_nt(fd->handle, level, optname, optval, optlen) != -1) {
|
||||
if (__imp_setsockopt(fd->handle, level, optname, optval, optlen) != -1) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winsockerr();
|
||||
|
|
|
@ -40,10 +40,10 @@ static bool setsockopt_polyfill(int *optname) {
|
|||
/**
|
||||
* Modifies socket settings.
|
||||
*
|
||||
* This function is the ultimate rabbit hole. Basic usage:
|
||||
* Basic usage:
|
||||
*
|
||||
* int yes = 1;
|
||||
* setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes));
|
||||
* int yes = 1;
|
||||
* setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
|
||||
*
|
||||
* @param level can be SOL_SOCKET, SOL_IP, SOL_TCP, etc.
|
||||
* @param optname can be SO_{REUSE{PORT,ADDR},KEEPALIVE,etc.} etc.
|
||||
|
|
|
@ -16,12 +16,15 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nt/thunk/msabi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/syscall_fd.internal.h"
|
||||
|
||||
__msabi extern typeof(__sys_shutdown_nt) *const __imp_shutdown;
|
||||
|
||||
textwindows int sys_shutdown_nt(struct Fd *fd, int how) {
|
||||
if (__sys_shutdown_nt(fd->handle, how) != -1) {
|
||||
if (__imp_shutdown(fd->handle, how) != -1) {
|
||||
return 0;
|
||||
} else {
|
||||
return __winsockerr();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue