mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-12 14:09:12 +00:00
Add shared memory hit counter example to redbean
This commit is contained in:
parent
38e3ab57a6
commit
8aca94f951
6 changed files with 114 additions and 29 deletions
35
tool/net/demo/hitcounter.lua
Normal file
35
tool/net/demo/hitcounter.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
Write([[<!doctype html>
|
||||
<title>redbean mapshared demo</title>
|
||||
<style>
|
||||
body { padding: 1em; }
|
||||
h1 a { color: inherit; text-decoration: none; }
|
||||
h1 img { border: none; vertical-align: middle; }
|
||||
input { margin: 1em; padding: .5em; }
|
||||
pre { margin-left: 2em; }
|
||||
p { word-break: break-word; max-width: 650px; }
|
||||
dt { font-weight: bold; }
|
||||
dd { margin-top: 1em; margin-bottom: 1em; }
|
||||
.hdr { text-indent: -1em; padding-left: 1em; }
|
||||
</style>
|
||||
<h1>
|
||||
<a href="/"><img src="/redbean.png"></a>
|
||||
<a href="fetch.lua">redbean mapshared demo</a>
|
||||
</h1>
|
||||
<p>
|
||||
This page displays a <code>unix.mapshared()</code> hit counter of
|
||||
the <code>GetPath()</code>.
|
||||
</p>
|
||||
<dl>
|
||||
]])
|
||||
|
||||
Lock()
|
||||
s = shm:read(SHM_JSON)
|
||||
if s == '' then s = '{}' end
|
||||
t = DecodeJson(s)
|
||||
Unlock()
|
||||
|
||||
for k,v in pairs(t) do
|
||||
Write('<dt>%s<dd>%d\n' % {EscapeHtml(k), v})
|
||||
end
|
||||
|
||||
Write('</dl>')
|
Loading…
Add table
Add a link
Reference in a new issue