Skip to content

Commit

Permalink
add support for message tokenisation on the transport
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Feb 14, 2019
1 parent dfe8db9 commit 534b1cb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/engine-driver/transport.cr
@@ -1,3 +1,5 @@
require "tokenizer"

abstract class EngineDriver::Transport
abstract def send(message) : Int32
abstract def send(message, task : EngineDriver::Task, &block : Bytes -> Nil) : Int32
Expand All @@ -6,6 +8,8 @@ abstract class EngineDriver::Transport
abstract def start_tls(verify_mode : OpenSSL::SSL::VerifyMode, context : OpenSSL::SSL::Context) : Nil
abstract def connect(connect_timeout : Int32)

property tokenizer : ::Tokenizer?

# Only SSH implements exec
def exec(message) : SSH2::Channel
raise ::IO::EOFError.new("exec is only available to SSH transports")
Expand Down Expand Up @@ -48,6 +52,19 @@ abstract class EngineDriver::Transport
end

protected def process(data) : Nil
if tokenize = @tokenizer
messages = tokenize.extract(data)
if messages.size == 1
process_message(messages[0])
else
messages.each { |message| spawn { process_message(message) } }
end
else
process_message(data)
end
end

private def process_message(data)
# Check if the task provided a response processing block
if task = @queue.current
if processing = task.processing
Expand Down

0 comments on commit 534b1cb

Please sign in to comment.