Module: ShadowsocksRuby::Protocols::BufferHelper

Included in:
HttpSimpleProtocol, IvCipherProtocol, TlsTicketProtocol, VerifySha1Protocol
Defined in:
lib/shadowsocks_ruby/protocols/protocol.rb

Overview

This module include helper methods for deal with @buffer.

Instance Method Summary collapse

Instance Method Details

#tcp_receive_from_localbackend_in_buffer(n) ⇒ Object


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 141

def tcp_receive_from_localbackend_in_buffer n
  if n == -1
    class << self
      alias tcp_receive_from_localbackend tcp_receive_from_localbackend_other_packet
    end
    return @buffer.slice!(0, @buffer.length)
  elsif n < @buffer.length
    return @buffer.slice!(0, n)
  else
    class << self
      alias tcp_receive_from_localbackend tcp_receive_from_localbackend_other_packet
    end
    if n == @buffer.length
      return @buffer.slice!(0, n)
    else
      data = async_recv(n - @buffer.length)
      return @buffer.slice!(0, n) << data 
    end
  end
end

#tcp_receive_from_localbackend_other_packet_helper(n) ⇒ Object


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 122

def tcp_receive_from_localbackend_other_packet_helper n
  if n == -1
    return @buffer.slice!(0, @buffer.length)
  elsif n < @buffer.length
    class << self
      alias tcp_receive_from_localbackend tcp_receive_from_localbackend_in_buffer
    end
    return @buffer.slice!(0, n)
  else
    if n == @buffer.length
      return @buffer.slice!(0, n)
    else
      data = async_recv(n - @buffer.length)
      return @buffer.slice!(0, n) << data 
    end
  end
end

#tcp_receive_from_remoteserver_in_buffer(n) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 101

def tcp_receive_from_remoteserver_in_buffer n
  if n == -1
    class << self
      alias tcp_receive_from_remoteserver tcp_receive_from_remoteserver_other_packet
    end
    return @buffer.slice!(0, @buffer.length)          
  elsif n < @buffer.length
    return @buffer.slice!(0, n)
  else
    class << self
      alias tcp_receive_from_remoteserver tcp_receive_from_remoteserver_other_packet
    end
    if n == @buffer.length
      return @buffer.slice!(0, n)
    else
      data = async_recv(n - @buffer.length)
      return @buffer.slice!(0, n) << data 
    end
  end
end

#tcp_receive_from_remoteserver_other_packet_helper(n) ⇒ Object


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 83

def tcp_receive_from_remoteserver_other_packet_helper n
  if n == -1
    return @buffer.slice!(0, @buffer.length)          
  elsif n < @buffer.length
    class << self
      alias tcp_receive_from_remoteserver tcp_receive_from_remoteserver_in_buffer
    end
    return @buffer.slice!(0, n)
  else
    if n == @buffer.length
      return @buffer.slice!(0, n)
    else
      data = async_recv(n - @buffer.length)
      return @buffer.slice!(0, n) << data 
    end
  end
end