Improve redbean

- Improve serialization
- Add Benchmark() API to redbean
- Refactor UNIX API to be assert() friendly
- Make the redbean Lua REPL print data structures
- Fix recent regressions in linenoise reverse search
- Add -i flag so redbean can be a language interpreter
This commit is contained in:
Justine Tunney 2022-04-25 08:30:14 -07:00
parent 2046c0d2ae
commit 451e3f73d9
74 changed files with 1781 additions and 1024 deletions

View file

@ -22,7 +22,7 @@
/**
* Describes setsockopt() level arguments.
*/
const char *DescribeSockLevel(int x) {
char *DescribeSockLevel(int x) {
static char buf[12];
if (x == SOL_IP) return "SOL_IP";
if (x == SOL_TCP) return "SOL_TCP";

View file

@ -18,26 +18,32 @@
*/
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/sol.h"
/**
* Describes setsockopt() optname arguments.
*/
const char *DescribeSockOptname(int l, int x) {
char *DescribeSockOptname(int l, int x) {
int i;
static char buf[12], *s;
char *ps, *s;
const struct MagnumStr *ms = 0;
_Alignas(char) static char buf[32];
if (x) {
if (l == SOL_SOCKET) {
ps = "SO_";
ms = kSockOptnames;
} else if (l == SOL_TCP) {
ps = "TCP_";
ms = kTcpOptnames;
} else if (l == SOL_IP) {
ps = "IP_";
ms = kIpOptnames;
}
}
if (ms && (s = GetMagnumStr(ms, x))) {
return s;
stpcpy(stpcpy(buf, ps), s);
return buf;
} else {
FormatInt32(buf, x);
return buf;

View file

@ -20,8 +20,10 @@
#include "libc/bits/bits.h"
#include "libc/calls/internal.h"
#include "libc/calls/struct/timeval.h"
#include "libc/nt/struct/linger.h"
#include "libc/nt/winsock.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/yoink.inc"
#include "libc/str/str.h"
#include "libc/sysv/consts/so.h"
@ -33,6 +35,7 @@ textwindows int sys_getsockopt_nt(struct Fd *fd, int level, int optname,
uint32_t *inout_optlen) {
uint64_t ms;
uint32_t in_optlen;
struct linger_nt linger;
assert(fd->kind == kFdSocket);
if (out_opt_optval && inout_optlen) {
@ -55,6 +58,11 @@ textwindows int sys_getsockopt_nt(struct Fd *fd, int level, int optname,
((struct timeval *)out_opt_optval)->tv_sec = ms / 1000;
((struct timeval *)out_opt_optval)->tv_usec = ms % 1000 * 1000;
*inout_optlen = sizeof(struct timeval);
} else if (optname == SO_LINGER && in_optlen == sizeof(struct linger)) {
linger = *(struct linger_nt *)out_opt_optval;
((struct linger *)out_opt_optval)->l_onoff = !!linger.l_onoff;
((struct linger *)out_opt_optval)->l_linger = linger.l_linger;
*inout_optlen = sizeof(struct linger);
}
}

View file

@ -16,24 +16,25 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/macros.internal.h"
.macro .e e
.macro .e e s
.long \e - kIpOptnames
.long 1f - kIpOptnames
.rodata.str1.1
1: .string "\e"
1: .string "\s"
.previous
.endm
.section .rodata
.align 4
.align 4
.underrun
kIpOptnames:
.e IP_TOS # int
.e IP_MTU # int
.e IP_TTL # int
.e IP_HDRINCL # bool32
.long -123
.e IP_TOS,"TOS" # int
.e IP_MTU,"MTU" # int
.e IP_TTL,"TTL" # int
.e IP_HDRINCL,"HDRINCL" # bool32
.long MAGNUM_TERMINATOR
.endobj kIpOptnames,globl,hidden
.overrun

View file

@ -16,13 +16,14 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/macros.internal.h"
.macro .e e
.macro .e e s
.long \e - kSockOptnames
.long 1f - kSockOptnames
.rodata.str1.1
1: .string "\e"
1: .string "\s"
.previous
.endm
@ -30,20 +31,22 @@
.align 4
.underrun
kSockOptnames:
.e SO_DEBUG # bool32
.e SO_BROADCAST # bool32
.e SO_REUSEADDR # bool32
.e SO_REUSEPORT # bool32
.e SO_KEEPALIVE # bool32
.e SO_DONTROUTE # bool32
.e SO_RCVTIMEO # timeval
.e SO_SNDTIMEO # timeval
.e SO_LINGER # linger
.e SO_SNDBUF # int
.e SO_RCVBUF # int
.e SO_RCVLOWAT # int
.e SO_SNDLOWAT # int
.e SO_ERROR # int
.long -123
.e SO_DEBUG,"DEBUG" # bool32
.e SO_ACCEPTCONN,"ACCEPTCONN" # bool32
.e SO_BROADCAST,"BROADCAST" # bool32
.e SO_REUSEADDR,"REUSEADDR" # bool32
.e SO_REUSEPORT,"REUSEPORT" # bool32
.e SO_KEEPALIVE,"KEEPALIVE" # bool32
.e SO_DONTROUTE,"DONTROUTE" # bool32
.e SO_RCVTIMEO,"RCVTIMEO" # timeval
.e SO_SNDTIMEO,"SNDTIMEO" # timeval
.e SO_LINGER,"LINGER" # linger
.e SO_TYPE,"TYPE" # int
.e SO_SNDBUF,"SNDBUF" # int
.e SO_RCVBUF,"RCVBUF" # int
.e SO_RCVLOWAT,"RCVLOWAT" # int
.e SO_SNDLOWAT,"SNDLOWAT" # int
.e SO_ERROR,"ERROR" # int
.long MAGNUM_TERMINATOR
.endobj kSockOptnames,globl,hidden
.overrun

View file

@ -16,33 +16,34 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/macros.internal.h"
.macro .e e
.macro .e e s
.long \e - kTcpOptnames
.long 1f - kTcpOptnames
.rodata.str1.1
1: .string "\e"
1: .string "\s"
.previous
.endm
.section .rodata
.align 4
.align 4
.underrun
kTcpOptnames:
.e TCP_NODELAY # bool32
.e TCP_CORK # bool32
.e TCP_QUICKACK # bool32
.e TCP_FASTOPEN_CONNECT # bool32
.e TCP_DEFER_ACCEPT # bool32
.e TCP_KEEPIDLE # int (seconds)
.e TCP_KEEPINTVL # int (seconds)
.e TCP_FASTOPEN # int
.e TCP_KEEPCNT # int
.e TCP_MAXSEG # int
.e TCP_SYNCNT # int
.e TCP_NOTSENT_LOWAT # int
.e TCP_WINDOW_CLAMP # int
.long -123
.e TCP_NODELAY,"NODELAY" # bool32
.e TCP_CORK,"CORK" # bool32
.e TCP_QUICKACK,"QUICKACK" # bool32
.e TCP_FASTOPEN_CONNECT,"FASTOPEN_CONNECT" # bool32
.e TCP_DEFER_ACCEPT,"DEFER_ACCEPT" # bool32
.e TCP_KEEPIDLE,"KEEPIDLE" # int (seconds)
.e TCP_KEEPINTVL,"KEEPINTVL" # int (seconds)
.e TCP_FASTOPEN,"FASTOPEN" # int
.e TCP_KEEPCNT,"KEEPCNT" # int
.e TCP_MAXSEG,"MAXSEG" # int
.e TCP_SYNCNT,"SYNCNT" # int
.e TCP_NOTSENT_LOWAT,"NOTSENT_LOWAT" # int
.e TCP_WINDOW_CLAMP,"WINDOW_CLAMP" # int
.long MAGNUM_TERMINATOR
.endobj kTcpOptnames,globl,hidden
.overrun

View file

@ -19,16 +19,12 @@
#include "libc/calls/struct/timeval.h"
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/nt/struct/linger.h"
#include "libc/sock/internal.h"
#include "libc/sysv/consts/so.h"
#include "libc/sysv/consts/sol.h"
#include "libc/sysv/errfuns.h"
struct linger_nt { /* Linux+XNU+BSD ABI */
uint16_t l_onoff; /* on/off */
uint16_t l_linger; /* seconds */
};
textwindows int sys_setsockopt_nt(struct Fd *fd, int level, int optname,
const void *optval, uint32_t optlen) {
int64_t ms;