mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-24 19:40:28 +00:00
Update redbean lua example code
This commit is contained in:
parent
451e3f73d9
commit
72e9be5c20
7 changed files with 56 additions and 51 deletions
|
@ -35,7 +35,7 @@ Write('<dt>unix.getcwd()\r\n')
|
|||
Write('<dd>%s\r\n' % {EscapeHtml(unix.getcwd())})
|
||||
|
||||
function PrintResourceLimit(name, id)
|
||||
soft, hard, errno = unix.getrlimit(id)
|
||||
soft, errno, hard = unix.getrlimit(id)
|
||||
Write('<dt>getrlimit(%s)\r\n' % {name})
|
||||
if soft then
|
||||
Write('<dd>')
|
||||
|
@ -80,7 +80,7 @@ else
|
|||
Write('%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DEBUG)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DEBUG)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DEBUG)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -88,7 +88,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_ACCEPTCONN)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_ACCEPTCONN)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_ACCEPTCONN)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -96,7 +96,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEADDR)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEADDR)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEADDR)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -104,7 +104,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEPORT)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEPORT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_REUSEPORT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -112,7 +112,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_KEEPALIVE)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_KEEPALIVE)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_KEEPALIVE)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -120,7 +120,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NODELAY)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NODELAY)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NODELAY)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -128,7 +128,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, secs, micros = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVTIMEO)
|
||||
secs, errno, micros = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVTIMEO)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVTIMEO)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -136,7 +136,7 @@ else
|
|||
Write('<dd>%d sec %d µs\r\n' % {secs, micros})
|
||||
end
|
||||
|
||||
errno, secs, micros = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDTIMEO)
|
||||
secs, errno, micros = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDTIMEO)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDTIMEO)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -144,7 +144,7 @@ else
|
|||
Write('<dd>%d sec %d µs\r\n' % {secs, micros})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DONTROUTE)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DONTROUTE)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_DONTROUTE)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -152,7 +152,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDBUF)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDBUF)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDBUF)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -160,7 +160,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVBUF)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVBUF)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVBUF)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -168,7 +168,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -176,7 +176,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_BROADCAST)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_BROADCAST)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_BROADCAST)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -184,7 +184,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_CORK)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_CORK)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_CORK)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -192,7 +192,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_QUICKACK)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_QUICKACK)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_QUICKACK)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -200,7 +200,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_DEFER_ACCEPT)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_DEFER_ACCEPT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_DEFER_ACCEPT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -208,7 +208,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, enabled = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN_CONNECT)
|
||||
enabled, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN_CONNECT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_FASTOPEN_CONNECT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -216,7 +216,7 @@ else
|
|||
Write('<dd>%s\r\n' % {enabled})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDLOWAT)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDLOWAT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_SNDLOWAT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -224,7 +224,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVLOWAT)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVLOWAT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_SOCKET, unix.SO_RCVLOWAT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -232,7 +232,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPCNT)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPCNT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPCNT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -240,7 +240,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_MAXSEG)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_MAXSEG)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_MAXSEG)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -248,7 +248,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_SYNCNT)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_SYNCNT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_SYNCNT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -256,7 +256,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NOTSENT_LOWAT)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NOTSENT_LOWAT)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_NOTSENT_LOWAT)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -264,7 +264,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_WINDOW_CLAMP)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_WINDOW_CLAMP)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_WINDOW_CLAMP)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -272,7 +272,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPIDLE)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPIDLE)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPIDLE)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
@ -280,7 +280,7 @@ else
|
|||
Write('<dd>%d\r\n' % {bytes})
|
||||
end
|
||||
|
||||
errno, bytes = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPINTVL)
|
||||
bytes, errno = unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPINTVL)
|
||||
Write('<dt>unix.getsockopt(GetClientFd(), unix.SOL_TCP, unix.TCP_KEEPINTVL)\r\n')
|
||||
if errno then
|
||||
Write('<dd>%s\r\n' % {EscapeHtml(unix.strerrno(errno))})
|
||||
|
|
|
@ -111,7 +111,7 @@ local function main()
|
|||
if dir then
|
||||
unix.write(fd, '<ul>\r\n')
|
||||
while true do
|
||||
name, kind, ino, off = dir:read()
|
||||
name, errno, kind, ino, off = dir:read()
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
|
|
|
@ -8,14 +8,14 @@ function main()
|
|||
cmd = 'ls'
|
||||
end
|
||||
syscall = 'commandv'
|
||||
ls, errno = unix.commandv(cmd)
|
||||
ls = assert(unix.commandv(cmd))
|
||||
if ls then
|
||||
syscall = 'pipe'
|
||||
reader, writer, errno = unix.pipe()
|
||||
if reader then
|
||||
oldint = unix.sigaction(unix.SIGINT, unix.SIG_IGN)
|
||||
oldquit = unix.sigaction(unix.SIGQUIT, unix.SIG_IGN)
|
||||
oldmask = unix.sigprocmask(unix.SIG_BLOCK, (1 << (unix.SIGCHLD - 1)))
|
||||
-- oldint = assert(unix.sigaction(unix.SIGINT, unix.SIG_IGN))
|
||||
-- oldquit = assert(unix.sigaction(unix.SIGQUIT, unix.SIG_IGN))
|
||||
-- oldmask = assert(unix.sigprocmask(unix.SIG_BLOCK, (1 << (unix.SIGCHLD - 1))))
|
||||
syscall = 'fork'
|
||||
child, errno = unix.fork()
|
||||
if child then
|
||||
|
|
|
@ -33,7 +33,7 @@ function main()
|
|||
pollfds = {}
|
||||
pollfds[mainfd] = unix.POLLIN
|
||||
|
||||
ifs, errno = unix.siocgifconf()
|
||||
ifs = assert(unix.siocgifconf())
|
||||
for i = 1,#ifs do
|
||||
if (IsLoopbackIp(mainip) and (IsPublicIp(ifs[i].ip) or
|
||||
IsPrivateIp(ifs[i].ip) or
|
||||
|
@ -45,7 +45,7 @@ function main()
|
|||
server = unix.socket()
|
||||
unix.bind(server, ifs[i].ip)
|
||||
unix.listen(server)
|
||||
ip, port = unix.getsockname(server)
|
||||
ip, errno, port = unix.getsockname(server)
|
||||
addr = '%s:%d' % {FormatIp(ip), port}
|
||||
url = 'http://%s' % {addr}
|
||||
Log(kLogInfo, 'listening on %s' % {addr})
|
||||
|
@ -79,7 +79,7 @@ function main()
|
|||
unix.write(mainfd, data)
|
||||
elseif servers[fd] then
|
||||
unix.write(mainfd, 'preparing to accept from %d<br>\r\n' % {fd})
|
||||
client, clientip, clientport = unix.accept(fd)
|
||||
client, errno, clientip, clientport = unix.accept(fd)
|
||||
unix.write(mainfd, 'preparing to accept from %d<br>\r\n' % {fd})
|
||||
addr = '%s:%d' % {FormatIp(clientip), clientport}
|
||||
addrs[client] = addr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue