mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Fix many thread and file descriptor issues on Windows
The greenbean web server now works nearly perfectly on Windows with over 1000 threads. But some synchronization issues still remain which prevent us from going over nine thousand.
This commit is contained in:
parent
96781d0679
commit
7838edae88
32 changed files with 363 additions and 192 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sig.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/spinlock.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/struct/pollfd.h"
|
||||
|
@ -44,7 +45,9 @@ textwindows int sys_accept_nt(struct Fd *fd, void *addr, uint32_t *addrsize,
|
|||
for (;;) {
|
||||
if (!WSAPoll(&(struct sys_pollfd_nt){fd->handle, POLLIN}, 1,
|
||||
__SIG_POLLING_INTERVAL_MS)) {
|
||||
if (_check_interrupts(true, g_fds.p)) return eintr();
|
||||
if (_check_interrupts(true, g_fds.p)) {
|
||||
return eintr();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ((h = WSAAccept(fd->handle, addr, (int32_t *)addrsize, 0, 0)) != -1) {
|
||||
|
@ -54,7 +57,8 @@ textwindows int sys_accept_nt(struct Fd *fd, void *addr, uint32_t *addrsize,
|
|||
if ((!(flags & SOCK_NONBLOCK) ||
|
||||
__sys_ioctlsocket_nt(h, FIONBIO, (uint32_t[]){1}) != -1) &&
|
||||
(sockfd2 = calloc(1, sizeof(struct SockFd)))) {
|
||||
if ((client = __reservefd(-1)) != -1) {
|
||||
_spinlock(&__fds_lock);
|
||||
if ((client = __reservefd_unlocked(-1)) != -1) {
|
||||
sockfd2->family = sockfd->family;
|
||||
sockfd2->type = sockfd->type;
|
||||
sockfd2->protocol = sockfd->protocol;
|
||||
|
@ -63,8 +67,10 @@ textwindows int sys_accept_nt(struct Fd *fd, void *addr, uint32_t *addrsize,
|
|||
g_fds.p[client].mode = 0140666;
|
||||
g_fds.p[client].handle = h;
|
||||
g_fds.p[client].extra = (uintptr_t)sockfd2;
|
||||
_spunlock(&__fds_lock);
|
||||
return client;
|
||||
}
|
||||
_spunlock(&__fds_lock);
|
||||
free(sockfd2);
|
||||
}
|
||||
__sys_closesocket_nt(h);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue