Class: Baykit::BayServer::Util::SysUtil
- Inherits:
-
Object
- Object
- Baykit::BayServer::Util::SysUtil
- Defined in:
- lib/baykit/bayserver/util/sys_util.rb
Class Method Summary collapse
- .pid ⇒ Object
- .processor_count ⇒ Object
-
.run_on_rubymine ⇒ Object
We set environment variable “RUBYMINE” to 1 for debugging.
- .run_on_windows ⇒ Object
- .support_fork ⇒ Object
- .support_nonblock_file_read ⇒ Object
- .support_nonblock_file_write ⇒ Object
- .support_nonblock_pipe_read ⇒ Object
- .support_select_file ⇒ Object
- .support_select_pipe ⇒ Object
- .support_unix_domain_socket_address ⇒ Object
Class Method Details
.pid ⇒ Object
123 124 125 |
# File 'lib/baykit/bayserver/util/sys_util.rb', line 123 def SysUtil.pid() return $$ end |
.processor_count ⇒ Object
127 128 129 |
# File 'lib/baykit/bayserver/util/sys_util.rb', line 127 def SysUtil.processor_count() return Etc.nprocessors end |
.run_on_rubymine ⇒ Object
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_windows ⇒ Object
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_fork ⇒ Object
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_read ⇒ Object
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_write ⇒ Object
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_read ⇒ Object
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_file ⇒ Object
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_pipe ⇒ Object
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_address ⇒ Object
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 |