-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use INotify to update the cache if files are changed
- Loading branch information
1 parent
bd2bc69
commit 4c6102b
Showing
7 changed files
with
209 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/bin/ | ||
/.shards/ | ||
*.dwarf | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 1.0 | ||
shards: | ||
inotify: | ||
github: petoem/inotify.cr | ||
version: 1.0.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,8 @@ targets: | |
crystal: 0.32.1 | ||
|
||
license: MIT | ||
|
||
dependencies: | ||
inotify: | ||
github: petoem/inotify.cr | ||
version: 1.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class CachedStaticServer::CLI | ||
def self.default_port : UInt16 | ||
(ENV["port"]? || 12345).to_u16 | ||
end | ||
|
||
def self.build_server(args = ARGV) | ||
port, parent, addr = default_port, Dir.current, "0.0.0.0" | ||
template = nil | ||
OptionParser.parse args do |parser| | ||
parser.banner = "Cached Static File Server" | ||
parser.on "-h", "--help", "Show this help" do | ||
puts parser | ||
exit 0 | ||
end | ||
parser.on "-p PORT", | ||
"--port PORT", | ||
"bind the server to a port. Defaults to 12345" do |p| | ||
port = p.to_u16 | ||
end | ||
parser.on "-d DIR", | ||
"--parent DIR", | ||
"specify the parent directory under which files will be served." do |dir| | ||
parent = dir | ||
end | ||
parser.on "-a ADDR", "--address ADDR", "bind to a given interface address" do |a| | ||
addr = a | ||
end | ||
# parser.on "-t TEMPLATE", "--on-not-found TEMPLATE", TEMPLATE_USAGE do |file| | ||
# template = file | ||
# end | ||
end | ||
server = Server.new parent, port, addr | ||
# if template | ||
# server.on_not_found do |request| | ||
# ECR.render template | ||
# end | ||
# end | ||
pp! parent, port, addr | ||
server | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "./log" | ||
|
||
module ManualMemoryManagement | ||
include Log | ||
|
||
def malloc(size, file) : Bytes | ||
debug "allocating #{size} bytes for #{file}" | ||
ptr = LibC.malloc(size).as Pointer(UInt8) | ||
if ptr.null? | ||
raise Errno.new "\ | ||
failed to allocate 0x#{size.to_s base: 16} bytes for #{file}" | ||
end | ||
debug "successfully returning #{size} allocated bytes at #{ptr.address.to_s base: 16}" | ||
Bytes.new pointer: ptr, size: size | ||
end | ||
|
||
def realloc(buf, size) : Bytes | ||
old_size = buf.size | ||
debug "reallocating buffer from #{old_size} to #{size} bytes at #{addr of: buf}" | ||
ptr = LibC.realloc(buf, size).as Pointer(UInt8) | ||
if ptr.null? | ||
raise Errno.new "\ | ||
failed to reallocate buffer from 0x#{old_size.to_s base: 16} bytes \ | ||
to 0x#{size.to_s base: 16} bytes" | ||
end | ||
|
||
debug "successfully returning #{size} allocated bytes at #{ptr.address.to_s base: 16}" | ||
Bytes.new pointer: ptr, size: size | ||
end | ||
end |