diff --git a/src/lavinmq/mfile.cr b/src/lavinmq/mfile.cr index c5b897c9ca..e864c43064 100644 --- a/src/lavinmq/mfile.cr +++ b/src/lavinmq/mfile.cr @@ -114,6 +114,15 @@ class MFile < IO msync(buffer, @size, LibC::MS_ASYNC) end + def msync + msync(buffer, @size, LibC::MS_SYNC) + end + + def fsync : Nil + ret = LibC.fsync(@fd) + raise IO::Error.from_errno("Error syncing file") if ret != 0 + end + # unload the memory mapping, will be remapped on demand def unmap : Nil munmap @@ -211,6 +220,10 @@ class MFile < IO bytes_count end + def to_unsafe + buffer + end + def to_slice raise IO::Error.new("MFile closed") if @closed Bytes.new(buffer, @size, read_only: true) @@ -241,6 +254,4 @@ class MFile < IO @size = new_size.to_i64 @pos = new_size.to_i64 if @pos > new_size end - - PAGESIZE = LibC.sysconf(LibC::SC_PAGESIZE).to_u32 end diff --git a/src/stdlib/slice.cr b/src/stdlib/slice.cr index a553249201..9f703f73ea 100644 --- a/src/stdlib/slice.cr +++ b/src/stdlib/slice.cr @@ -6,6 +6,10 @@ struct Slice(T) builder.string Base64.encode(self) end + def self.from_json(json : JSON::PullParser) : Bytes + Base64.decode_string json.read_string + end + # Truncate to 72 first items def to_s(io : IO) : Nil if T == UInt8