Class: Isomorfeus::Speednode::Runtime::VMCommand
- Inherits:
-
Object
- Object
- Isomorfeus::Speednode::Runtime::VMCommand
- Defined in:
- lib/isomorfeus/speednode/runtime/vm_command.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(socket, cmd, arguments) ⇒ VMCommand
constructor
A new instance of VMCommand.
Constructor Details
#initialize(socket, cmd, arguments) ⇒ VMCommand
Returns a new instance of VMCommand.
5 6 7 8 9 |
# File 'lib/isomorfeus/speednode/runtime/vm_command.rb', line 5 def initialize(socket, cmd, arguments) @socket = socket @cmd = cmd @arguments = arguments end |
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/isomorfeus/speednode/runtime/vm_command.rb', line 11 def execute result = '' = ::Oj.dump({ 'cmd' => @cmd, 'args' => @arguments }, mode: :strict) = + "\x04" bytes_to_send = .bytesize sent_bytes = 0 if ::ExecJS.windows? @socket.write() begin result << @socket.read end until result.end_with?("\x04") else sent_bytes = @socket.sendmsg() if sent_bytes < bytes_to_send while sent_bytes < bytes_to_send sent_bytes += @socket.sendmsg(.byteslice((sent_bytes)..-1)) end end begin result << @socket.recvmsg()[0] end until result.end_with?("\x04") end ::Oj.load(result.chop!, mode: :strict) end |