lib/daybreak/writer.rb in daybreak-0.0.2 vs lib/daybreak/writer.rb in daybreak-0.0.3
- old
+ new
@@ -43,12 +43,14 @@
def open!
@fd = File.open @file, 'a'
@fd.binmode
- f = @fd.fcntl(Fcntl::F_GETFL, 0)
- @fd.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK | f)
+ if defined?(Fcntl::O_NONBLOCK)
+ f = @fd.fcntl(Fcntl::F_GETFL, 0)
+ @fd.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK | f)
+ end
end
# Workers handle the actual fiddly bits of asynchronous io and
# and handle background writes.
class Worker
@@ -87,10 +89,14 @@
# Try and write the buffer to the file via non blocking file writes.
# If the write fails try again.
def try_write(fd, buf)
begin
- s = fd.write_nonblock(buf)
+ if defined?(Fcntl::O_NONBLOCK)
+ s = fd.write_nonblock(buf)
+ else
+ s = fd.write(buf)
+ end
if s < buf.length
buf = buf[s..-1] # didn't finish
else
buf = ""
end