Class: Baykit::BayServer::Util::SysUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/baykit/bayserver/util/sys_util.rb

Class Method Summary collapse

Class Method Details

.pidObject



123
124
125
# File 'lib/baykit/bayserver/util/sys_util.rb', line 123

def SysUtil.pid()
  return $$
end

.processor_countObject



127
128
129
# File 'lib/baykit/bayserver/util/sys_util.rb', line 127

def SysUtil.processor_count()
  return Etc.nprocessors
end

.run_on_rubymineObject

We set environment variable “RUBYMINE” to 1 for debugging



20
21
22
# File 'lib/baykit/bayserver/util/sys_util.rb', line 20

def SysUtil.run_on_rubymine()
  return ENV["RUBYMINE"] == "1"
end

.run_on_windowsObject



13
14
15
# File 'lib/baykit/bayserver/util/sys_util.rb', line 13

def SysUtil.run_on_windows()
  return RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|cygwin|bccwin/
end

.support_forkObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/baykit/bayserver/util/sys_util.rb', line 24

def SysUtil.support_fork()
  begin
    pid = fork()
    if pid == nil
      exit(0)
    end
    Process.waitpid(pid)
    return true
  rescue NotImplementedError => e
    if BayLog.debug_mode
      BayLog.warn("fork() failed: %s ", e)
      #BayLog.warn_e(e)
    end
    return false
  end
end

.support_nonblock_file_readObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/baykit/bayserver/util/sys_util.rb', line 58

def SysUtil.support_nonblock_file_read()
  File.open(BayServer.bserv_plan) do |f|
    begin
      f.read_nonblock(1)
      return true
    rescue SystemCallError => e
      if BayLog.debug_mode
        BayLog.warn("read_nonblock() failed: %s", e)
        #BayLog.warn_e(e)
      end
      return false
    end
  end
end

.support_nonblock_file_writeObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/baykit/bayserver/util/sys_util.rb', line 73

def SysUtil.support_nonblock_file_write()
  Dir.mktmpdir() do |dir|
    File.open(Pathname(dir) + "test_file", "wb") do |f|
      begin
        f.write_nonblock(1)
        return true
      rescue SystemCallError => e
        if BayLog.debug_mode
          BayLog.warn("write_nonblock() failed: %s", e)
          #BayLog.warn_e(e)
        end
        return false
      end
    end
  end
end

.support_nonblock_pipe_readObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/baykit/bayserver/util/sys_util.rb', line 107

def SysUtil.support_nonblock_pipe_read()
  IO.pipe() do |r, w|
    w.write("abcd")
    begin
      r.read_nonblock(1)
      return true
    rescue SystemCallError => e
      if BayLog.debug_mode
        BayLog.warn("read_nonblock() failed: %s", e)
        #BayLog.warn_e(e)
      end
      return false
    end
  end
end

.support_select_fileObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/baykit/bayserver/util/sys_util.rb', line 42

def SysUtil.support_select_file()
  File.open(BayServer.bserv_plan) do |f|
    begin
      n = select([f], [], [], 10)
      return true
    rescue IOError => e
      if BayLog.debug_mode
        BayLog.warn("select() failed: %s", e)
        #BayLog.warn_e(e)
      end
      return false
    end
  end
end

.support_select_pipeObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/baykit/bayserver/util/sys_util.rb', line 91

def SysUtil.support_select_pipe()
  IO.pipe() do |r, w|
    begin
      n = select([r], [w], [], 10)
      return true
    rescue IOError => e
      if BayLog.debug_mode
        BayLog.warn("select() failed: %s", e)
        #BayLog.warn_e(e)
      end
      return false
    end
  end
end

.support_unix_domain_socket_addressObject



131
132
133
# File 'lib/baykit/bayserver/util/sys_util.rb', line 131

def SysUtil.support_unix_domain_socket_address()
  return !SysUtil.run_on_windows()
end