diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-06-19 03:02:49 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-06-19 03:02:49 +0000 |
commit | 8349a0504e3d69586e783f9327428301528a634c (patch) | |
tree | ca5e9544edee7fc0a236cae5aa966944dcae52d6 /libs/httpd/luasrc/httpd.lua | |
parent | f712a1f2c284bfecff775ceff60c0e7a182ed114 (diff) |
* luci/httpd: add initial server implementation
Diffstat (limited to 'libs/httpd/luasrc/httpd.lua')
-rw-r--r-- | libs/httpd/luasrc/httpd.lua | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libs/httpd/luasrc/httpd.lua b/libs/httpd/luasrc/httpd.lua new file mode 100644 index 000000000..d95de7d31 --- /dev/null +++ b/libs/httpd/luasrc/httpd.lua @@ -0,0 +1,69 @@ +--[[ + +HTTP server implementation for LuCI - core +(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +]]-- + +require("ltn12") +require("socket") + +require("luci.util") +require("luci.http.protocol") +require("luci.httpd.server") + + +local srv = luci.httpd.server +local host = "0.0.0.0" +local port = 50000 + + +server = socket.bind(host, port) +server:settimeout( 0, "t" ) + +reading = { server } +running = { } + + +while true do + + local input = socket.select( reading, nil, 0.1 ) + + -- accept new connections + for i, connection in ipairs(input) do + + local sock = connection:accept() + + -- check capacity + if #running < srv.MAX_CLIENTS then + + table.insert( running, { + coroutine.create( srv.client_handler ), + sock + } ) + + -- reject client + else + srv.error503( sock ) + end + end + + -- create client handler + for i, client in ipairs( running ) do + + -- reap dead clients + if coroutine.status( client[1] ) == "dead" then + table.remove( running, i ) + end + + coroutine.resume( client[1], client[2] ) + end +end |