Skip to content

Commit dcf9596

Browse files
committed
Make more fixups and quality assurance
1 parent 85c58be commit dcf9596

File tree

17 files changed

+80
-78
lines changed

17 files changed

+80
-78
lines changed

libc/calls/getgroups.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "libc/dce.h"
2222
#include "libc/intrin/describeflags.h"
2323
#include "libc/intrin/strace.h"
24-
#include "libc/stdckdint.h"
2524
#include "libc/sysv/errfuns.h"
2625

2726
/**

libc/calls/pipe-nt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static textwindows int sys_pipe_nt_impl(int pipefd[2], unsigned flags) {
5656
__fds_unlock();
5757
hin = CreateNamedPipe(pipename, kNtPipeAccessInbound | kNtFileFlagOverlapped,
5858
mode, 1, PIPE_BUF, PIPE_BUF, 0, &kNtIsInheritable);
59-
__fds_lock();
6059
if (hin != -1) {
6160
if ((hout = CreateFile(
6261
pipename, kNtGenericWrite,
@@ -73,15 +72,13 @@ static textwindows int sys_pipe_nt_impl(int pipefd[2], unsigned flags) {
7372
g_fds.p[writer].handle = hout;
7473
pipefd[0] = reader;
7574
pipefd[1] = writer;
76-
__fds_unlock();
7775
return 0;
7876
} else {
7977
CloseHandle(hin);
8078
}
8179
}
8280
__releasefd(writer);
8381
__releasefd(reader);
84-
__fds_unlock();
8582
return -1;
8683
}
8784

libc/calls/poll-nt.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,14 @@ textwindows static int sys_poll_nt_impl(struct pollfd *fds, uint64_t nfds,
351351
}
352352
}
353353

354-
textwindows int sys_poll_nt(struct pollfd *fds, uint64_t nfds, uint32_t *ms,
354+
textwindows int sys_poll_nt(struct pollfd *fds, uint64_t nfds,
355+
const struct timespec *relative,
355356
const sigset_t *sigmask) {
356357
int rc;
357358
struct timespec now, timeout, deadline;
358359
BLOCK_SIGNALS;
359-
now = ms ? sys_clock_gettime_monotonic_nt() : timespec_zero;
360-
timeout = ms ? timespec_frommillis(*ms) : timespec_max;
360+
now = relative ? sys_clock_gettime_monotonic_nt() : timespec_zero;
361+
timeout = relative ? *relative : timespec_max;
361362
deadline = timespec_add(now, timeout);
362363
rc = sys_poll_nt_impl(fds, nfds, deadline, sigmask ? *sigmask : _SigMask);
363364
ALLOW_SIGNALS;

libc/calls/ppoll.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "libc/dce.h"
2626
#include "libc/errno.h"
2727
#include "libc/intrin/strace.h"
28+
#include "libc/limits.h"
2829
#include "libc/runtime/stack.h"
2930
#include "libc/sock/struct/pollfd.h"
3031
#include "libc/sock/struct/pollfd.internal.h"
@@ -76,10 +77,13 @@ static int ppoll_impl(struct pollfd *fds, size_t nfds,
7677
}
7778
fdcount = sys_ppoll(fds, nfds, tsp, sigmask, 8);
7879
if (fdcount == -1 && errno == ENOSYS) {
79-
int ms;
80+
int64_t ms;
8081
errno = e;
81-
if (!timeout || ckd_add(&ms, timeout->tv_sec,
82-
(timeout->tv_nsec + 999999) / 1000000)) {
82+
if (timeout) {
83+
ms = timespec_tomillis(*timeout);
84+
if (ms > INT_MAX)
85+
ms = -1;
86+
} else {
8387
ms = -1;
8488
}
8589
if (sigmask)
@@ -89,15 +93,7 @@ static int ppoll_impl(struct pollfd *fds, size_t nfds,
8993
sys_sigprocmask(SIG_SETMASK, &oldmask, 0);
9094
}
9195
} else {
92-
uint32_t ms;
93-
uint32_t *msp;
94-
if (timeout &&
95-
!ckd_add(&ms, timeout->tv_sec, (timeout->tv_nsec + 999999) / 1000000)) {
96-
msp = &ms;
97-
} else {
98-
msp = 0;
99-
}
100-
fdcount = sys_poll_nt(fds, nfds, msp, sigmask);
96+
fdcount = sys_poll_nt(fds, nfds, timeout, sigmask);
10197
}
10298

10399
if (IsOpenbsd() && fdcount != -1) {

libc/calls/pselect.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
6868
const struct timespec *timeout, const sigset_t *sigmask) {
6969
int rc;
70-
struct timeval tv, *tvp;
7170
struct timespec ts, *tsp;
7271
struct {
7372
const sigset_t *s;
@@ -111,14 +110,7 @@ int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
111110
rc = sys_pselect(nfds, readfds, writefds, exceptfds,
112111
(struct timespec *)timeout, sigmask);
113112
} else {
114-
if (timeout) {
115-
tv.tv_sec = timeout->tv_sec;
116-
tv.tv_usec = timeout->tv_nsec / 1000;
117-
tvp = &tv;
118-
} else {
119-
tvp = 0;
120-
}
121-
rc = sys_select_nt(nfds, readfds, writefds, exceptfds, tvp, sigmask);
113+
rc = sys_select_nt(nfds, readfds, writefds, exceptfds, timeout, sigmask);
122114
}
123115
}
124116
END_CANCELATION_POINT;

libc/calls/select-nt.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "libc/sock/sock.h"
2626
#include "libc/sock/struct/pollfd.h"
2727
#include "libc/sock/struct/pollfd.internal.h"
28-
#include "libc/stdckdint.h"
2928
#include "libc/sysv/consts/poll.h"
3029
#include "libc/sysv/errfuns.h"
3130
#ifdef __x86_64__
@@ -44,7 +43,7 @@
4443
// </sync libc/sysv/consts.sh>
4544

4645
int sys_select_nt(int nfds, fd_set *readfds, fd_set *writefds,
47-
fd_set *exceptfds, struct timeval *timeout,
46+
fd_set *exceptfds, const struct timespec *timeout,
4847
const sigset_t *sigmask) {
4948
int pfds = 0;
5049

@@ -68,21 +67,8 @@ int sys_select_nt(int nfds, fd_set *readfds, fd_set *writefds,
6867
}
6968
}
7069

71-
// convert the wait time to a word
72-
uint32_t millis;
73-
if (!timeout) {
74-
millis = -1u;
75-
} else {
76-
int64_t ms = timeval_tomillis(*timeout);
77-
if (ms < 0 || ms > UINT32_MAX) {
78-
millis = -1u;
79-
} else {
80-
millis = ms;
81-
}
82-
}
83-
8470
// call our nt poll implementation
85-
int fdcount = sys_poll_nt(fds, pfds, &millis, sigmask);
71+
int fdcount = sys_poll_nt(fds, pfds, timeout, sigmask);
8672
if (fdcount == -1)
8773
return -1;
8874

@@ -115,10 +101,6 @@ int sys_select_nt(int nfds, fd_set *readfds, fd_set *writefds,
115101
}
116102
}
117103

118-
// store remaining time back in caller's timeval
119-
if (timeout)
120-
*timeout = timeval_frommillis(millis);
121-
122104
return bits;
123105
}
124106

libc/calls/select.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
* such as out-of-band data on a socket; it is equivalent to POLLPRI
3232
* in the revents of poll()
3333
* @param timeout may be null which means to block indefinitely; cosmo's
34-
* implementation of select() never modifies this parameter which is
35-
* how most platforms except Linux work which modifies it to reflect
36-
* elapsed time, noting that POSIX permits either behavior therefore
37-
* portable code should assume that timeout memory becomes undefined
34+
* implementation of select() never modifies this parameter
3835
* @raise E2BIG if we exceeded the 64 socket limit on Windows
3936
* @raise ECANCELED if thread was cancelled in masked mode
4037
* @raise EINTR if signal was delivered

libc/calls/setgroups.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "libc/dce.h"
2222
#include "libc/intrin/describeflags.h"
2323
#include "libc/intrin/strace.h"
24-
#include "libc/stdckdint.h"
2524
#include "libc/sysv/errfuns.h"
2625

2726
/**

libc/sock/internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_
33
#include "libc/calls/struct/iovec.h"
44
#include "libc/calls/struct/sigset.h"
5+
#include "libc/calls/struct/timespec.h"
56
#include "libc/nt/struct/overlapped.h"
67
#include "libc/nt/thunk/msabi.h"
78
#include "libc/nt/winsock.h"
@@ -60,7 +61,7 @@ int sys_socketpair_nt_stream(int, int, int, int[2]) ;
6061
int sys_socketpair_nt_dgram(int, int, int, int[2]) ;
6162
*/
6263
int sys_socketpair_nt(int, int, int, int[2]);
63-
int sys_select_nt(int, fd_set *, fd_set *, fd_set *, struct timeval *,
64+
int sys_select_nt(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
6465
const sigset_t *);
6566

6667
size_t __iovec2nt(struct NtIovec[hasatleast 16], const struct iovec *, size_t);

libc/sock/send-nt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ textwindows ssize_t sys_send_nt(int fd, const struct iovec *iov, size_t iovlen,
6666

6767
__sig_unblock(waitmask);
6868

69-
if (rc == -1 && errno == WSAESHUTDOWN) { // ESHUTDOWN
70-
errno = kNtErrorBrokenPipe; // EPIPE
69+
if (rc == -1 && (errno == WSAESHUTDOWN || // ESHUTDOWN
70+
errno == WSAECONNABORTED)) { // ECONNABORTED
71+
errno = kNtErrorBrokenPipe; // EPIPE
7172
if (!(flags & _MSG_NOSIGNAL))
7273
__sig_raise(SIGPIPE, SI_KERNEL);
7374
}

0 commit comments

Comments
 (0)