class StringIO

Public Instance Methods

binmode() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 640
def binmode()
  # Question: ok, so the cosmetics are that it is in binmode ... but what will be its actual behavior??
  if self.binmode?()
    self
  else
    self.set_encoding(::Encoding::ASCII_8BIT)
  end
end
binmode?() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 632
def binmode?()
  if self.external_encoding == ::Encoding::ASCII_8BIT
    true
  else
    false
  end
end
fcntl(*args) click to toggle source
# File lib/gxg/gxg_augmented.rb, line 695
def fcntl(*args)
  if args[0] == ::Fcntl::F_GETFL
    current = ::Fcntl::O_NONBLOCK
    if self.closed_read?()
      unless self.closed_write?()
        current = (current | ::Fcntl::O_WRONLY)
      end
    else
      if self.closed_write?()
        current = (current | ::Fcntl::O_RDONLY)
      else
        current = (current | ::Fcntl::O_RDWR)
      end
    end
    current
  else
    0
  end
end
flags() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 715
def flags()
  result = []
  current = self.fcntl(::Fcntl::F_GETFL)
  flags = {}
  if self.binmode?()
    result << :binary
    if self.external_encoding == ::Encoding::ASCII_8BIT
      result << :setenc_by_bom
    end
  else
    result << :text
    result << :wsplit
  end
  if self.tty?
    result << :tty
  end
  #
  #flag[:read] = 0x00000001
  #flag[:write] = 0x00000002
  #flag[:readwrite] = (flag[:read] | flag[:write])
  #flag[:binmode] = 0x00000004
  #flag[:readwrite] = (flag[:read] | flag[:write])
  flags[:read] = ::Fcntl::O_RDONLY
  flags[:write] = ::Fcntl::O_WRONLY
  flags[:readwrite] = ::Fcntl::O_RDWR
  #flags[:binary] = 0x00000004
  flags[:sync] = ::File::SYNC # no internal buffering -- The file will be opened for synchronous I/O. No write operation will complete until the data has been physically written to disk.
  flags[:dsync] = ::File::DSYNC # only normal data be synchronized after each write operation, not metadata.
  flags[:rsync] = ::File::RSYNC # the synchronization of read requests as well as write requests. It must be used with one of IO::SYNC or IO::DSYNC
  #flags[:tty] = 0x00000010
  flags[:notcontrol_tty] = ::Fcntl::O_NOCTTY
  flags[:duplex] = 0x00000020
  flags[:append] = ::Fcntl::O_APPEND
  flags[:create] = ::Fcntl::O_CREAT
  flags[:exclusive] = ::Fcntl::O_EXCL
  # flags[:wsplit] = 0x00000200
  flags[:wsplit_initialized] = 0x00000400
  flags[:trunc] = ::Fcntl::O_TRUNC
  #flags[:text] = 0x00001000
  #flags[:setenc_by_bom] = 0x00100000
  flags[:seek_set] = ::File::SEEK_SET
  flags[:seek_current] = ::File::SEEK_CUR
  flags[:seek_end] = ::File::SEEK_END
  # ### file region locking:
  flags[:shared_lock] = ::File::LOCK_SH # for reading
  flags[:exclusive_lock] = ::File::LOCK_EX # for writing (implies blocking)
  flags[:nonblock_lock] = ::File::LOCK_NB # combine with exclusive_lock for immediate non-blocking lock for writing.
  flags[:unlock] = ::File::LOCK_UN
  #
  flags[:nonblocking] = ::Fcntl::O_NONBLOCK
  flags[:ndelay] = ::Fcntl::O_NDELAY
  # these do not apply to in-memory IO-like things at all:
  #    flags[:nofollow] = ::File::NOFOLLOW # Do not follow symlinks.
  #    flags[:noaccesstime] = ::File::NOATIME # Do not update the access time (atime) of the file.
  #    flags[:match_noescape] = ::File::FNM_NOESCAPE #
  #    flags[:match_pathname] = ::File::FNM_PATHNAME #
  #    flags[:match_dotmatch] = ::File::FNM_DOTMATCH #
  #    flags[:match_casefold] = ::File::FNM_CASEFOLD #
  #    flags[:match_systemcase] = ::File::FNM_SYSCASE #
  #
  flags.keys.to_enum.each do |the_flag_key|
    if (current & flags[(the_flag_key)]) == flags[(the_flag_key)]
      case the_flag_key
      when :readwrite
        if result.index(:write)
          result << :read
        else
          if result.index(:read)
            result << :write
          end
        end
      when :wsplit_initialized
        if result.index(:wsplit)
          result[(result.index(:wsplit))] = :wsplit_initialized
        else
          result << :wsplit_initialized
        end
      else
        result << the_flag_key
      end
    end
  end
  #
  result
end
latency_reading(old_reading=nil,&block) click to toggle source
# File lib/gxg/gxg_augmented.rb, line 665
def latency_reading(old_reading=nil,&block)
  # Just in StringIO for interface compatibility.
  unless old_reading.is_a?(::Hash)
    old_reading = {:low => nil, :last => nil, :high => nil}
  end
  new_reading = {:low => nil, :last => nil, :high => nil}
  reading = millisecond_latency(&block)
  if old_reading[:low]
    if reading[:milliseconds] < old_reading[:low]
      new_reading[:low] = reading[:milliseconds].dup
    else
      new_reading[:low] = old_reading[:low]
    end
  else
    new_reading[:low] = reading[:milliseconds].dup
  end
  new_reading[:last] = reading[:milliseconds].dup
  if old_reading[:high]
    if reading[:milliseconds] > old_reading[:high]
      new_reading[:high] = reading[:milliseconds].dup
    else
      new_reading[:high] = old_reading[:high]
    end
  else
    new_reading[:high] = reading[:milliseconds].dup
  end
  #
  {:result => reading[:result], :reading => new_reading}
end
lstat(*args)
Alias for: stat
profile() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 806
def profile()
  current = self.flags()
  result = {:type => :memory, :flags => current, :permissions => {:effective=>{:execute=>false, :rename=>false, :move=>false, :destroy=>false, :create=>false, :write=>false, :read=>false}}}
  #
  if current.include?(:read)
    result[:permissions][:effective][:read] = true
  end
  if current.include?(:write)
    result[:permissions][:effective][:write] = true
    result[:permissions][:effective][:destroy] = true
    result[:permissions][:effective][:create] = true
  end
  #
  result
end
read_latency() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 657
def read_latency()
  # Just in StringIO for interface compatibility.
  unless self.instance_variable_defined?(:@read_latency)
    @read_latency= {:low => nil, :last => nil, :high => nil}
  end
  @read_latency.clone
end
stat(*args) click to toggle source
# File lib/gxg/gxg_augmented.rb, line 801
def stat(*args)
  nil
end
Also aliased as: lstat
write_latency() click to toggle source
# File lib/gxg/gxg_augmented.rb, line 649
def write_latency()
  # Just in StringIO for interface compatibility.
  unless self.instance_variable_defined?(:@write_latency)
    @write_latency= {:low => nil, :last => nil, :high => nil}
  end
  @write_latency.clone
end