Skip to content

Commit

Permalink
osctld: remove buffer from ct wrapper altogether
Browse files Browse the repository at this point in the history
  • Loading branch information
aither64 committed Oct 12, 2020
1 parent 71d2988 commit ac7f431
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions osctld/bin/osctld-ct-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,6 @@ require 'pty'
require 'socket'
require 'timeout'

class StringBuffer
def initialize(max_size: 4096)
@buffer = ''
@max_size = max_size
end

def <<(data)
@buffer << data

if @buffer.length > @max_size
@buffer[0..(@buffer.length - @max_size - 1)] = ''
end

nil
end

def read
ret = @buffer.clone
@buffer.clear
ret
end
end

class Wrapper
def initialize(args)
ctid = args.shift
Expand All @@ -58,7 +35,6 @@ class Wrapper
@current_rows = 25
@current_cols = 80
@cmd_buf = ''
@read_buf = StringBuffer.new

Process.setproctitle("osctld: CT #{ctid}")
end
Expand All @@ -80,7 +56,7 @@ class Wrapper

protected
attr_reader :server, :socket, :client
attr_reader :pid, :cmd_buf, :read_buf, :current_rows, :current_cols
attr_reader :pid, :cmd_buf, :current_rows, :current_cols

def work(r_pty, w_pty)
rs, _ = IO.select([server, client, r_pty].compact)
Expand Down Expand Up @@ -200,17 +176,15 @@ class Wrapper

def send_to_client(data)
if client
to_send = read_buf.read + data
client.send(to_send, 0) unless to_send.empty?
client.send(data, 0) unless data.empty?
else
read_buf << data
# client not connected, data is dropped
end

rescue SystemCallError
# osctld has crashed/exited
@client.close
@client = nil
read_buf << data
end
end

Expand Down

0 comments on commit ac7f431

Please sign in to comment.