mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Make improvements
- Expand redbean UNIX module - Expand redbean documentation - Ensure Lua copyright is embedded in binary - Increase the PATH_MAX limit especially on NT - Use column major sorting for linenoise completions - Fix some suboptimalities in redbean's new UNIX API - Figured out right flags for Multics newline in raw mode
This commit is contained in:
parent
cf3174dc74
commit
2046c0d2ae
305 changed files with 6602 additions and 4221 deletions
|
@ -17,20 +17,54 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timeval.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/yoink.inc"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/so.h"
|
||||
#include "libc/sysv/consts/sol.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
textwindows int sys_getsockopt_nt(struct Fd *fd, int level, int optname,
|
||||
void *out_opt_optval, uint32_t *out_optlen) {
|
||||
/* TODO(jart): Use WSAIoctl? */
|
||||
void *out_opt_optval,
|
||||
uint32_t *inout_optlen) {
|
||||
uint64_t ms;
|
||||
uint32_t in_optlen;
|
||||
assert(fd->kind == kFdSocket);
|
||||
if (__sys_getsockopt_nt(fd->handle, level, optname, out_opt_optval,
|
||||
out_optlen) != -1) {
|
||||
return 0;
|
||||
|
||||
if (out_opt_optval && inout_optlen) {
|
||||
in_optlen = *inout_optlen;
|
||||
} else {
|
||||
in_optlen = 0;
|
||||
}
|
||||
|
||||
// TODO(jart): Use WSAIoctl?
|
||||
if (__sys_getsockopt_nt(fd->handle, level, optname, out_opt_optval,
|
||||
inout_optlen) == -1) {
|
||||
return __winsockerr();
|
||||
}
|
||||
|
||||
if (level == SOL_SOCKET) {
|
||||
if ((optname == SO_RCVTIMEO || optname == SO_SNDTIMEO) &&
|
||||
in_optlen == sizeof(struct timeval) &&
|
||||
*inout_optlen == sizeof(uint32_t)) {
|
||||
ms = *(uint32_t *)out_opt_optval;
|
||||
((struct timeval *)out_opt_optval)->tv_sec = ms / 1000;
|
||||
((struct timeval *)out_opt_optval)->tv_usec = ms % 1000 * 1000;
|
||||
*inout_optlen = sizeof(struct timeval);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_optlen == 4 && *inout_optlen == 1) {
|
||||
// handle cases like this
|
||||
// getsockopt(8, SOL_TCP, TCP_FASTOPEN, [u"☺"], [1]) → 0
|
||||
int32_t wut = *(signed char *)out_opt_optval;
|
||||
memcpy(out_opt_optval, &wut, 4);
|
||||
*inout_optlen = 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue