Skip to content

Commit

Permalink
keep specifics
Browse files Browse the repository at this point in the history
  • Loading branch information
kickster97 committed Oct 30, 2023
1 parent c443e1b commit 4f92bdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lavinmq/mfile.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/stdlib/slice.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f92bdf

Please sign in to comment.