Remove not needed chunking code

This commit is contained in:
Kovid Goyal 2022-08-30 21:36:43 +05:30
parent 192eccc6cc
commit b5e2871aa0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 6 additions and 23 deletions

View File

@ -97,6 +97,7 @@ func (self *wrapped_serializer) next(io_data *rc_io_data) ([]byte, error) {
} else { } else {
self.all_payloads_done = true self.all_payloads_done = true
} }
self.state++
return self.serializer(io_data.rc) return self.serializer(io_data.rc)
case 2: case 2:
if self.all_payloads_done { if self.all_payloads_done {
@ -168,34 +169,16 @@ type rc_io_data struct {
string_response_is_err bool string_response_is_err bool
timeout time.Duration timeout time.Duration
multiple_payload_generator func(io_data *rc_io_data) (bool, error) multiple_payload_generator func(io_data *rc_io_data) (bool, error)
pending_chunks [][]byte
} }
func (self *rc_io_data) next_chunk(limit_size bool) (chunk []byte, err error) { func (self *rc_io_data) next_chunk() (chunk []byte, err error) {
if len(self.pending_chunks) > 0 {
chunk = self.pending_chunks[0]
copy(self.pending_chunks, self.pending_chunks[1:])
self.pending_chunks = self.pending_chunks[:len(self.pending_chunks)-1]
return
}
block, err := self.serializer.next(self) block, err := self.serializer.next(self)
if err != nil && !errors.Is(err, io.EOF) { if err != nil && !errors.Is(err, io.EOF) {
return return
} }
err = nil err = nil
const limit = 2048
if !limit_size || len(block) < limit {
chunk = block chunk = block
return return
}
chunk = block[:limit]
block = block[limit:]
for len(block) > 0 {
self.pending_chunks = append(self.pending_chunks, block[:limit])
block = block[limit:]
}
return
} }
func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) { func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) {

View File

@ -54,7 +54,7 @@ func read_response_from_conn(conn *net.Conn, timeout time.Duration) (serialized_
func simple_socket_io(conn *net.Conn, io_data *rc_io_data) (serialized_response []byte, err error) { func simple_socket_io(conn *net.Conn, io_data *rc_io_data) (serialized_response []byte, err error) {
for { for {
var chunk []byte var chunk []byte
chunk, err = io_data.next_chunk(false) chunk, err = io_data.next_chunk()
if err != nil { if err != nil {
return return
} }

View File

@ -44,7 +44,7 @@ func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error)
} }
lp.OnInitialize = func() (string, error) { lp.OnInitialize = func() (string, error) {
chunk, err := io_data.next_chunk(false) chunk, err := io_data.next_chunk()
if err != nil { if err != nil {
return "", err return "", err
} }
@ -62,7 +62,7 @@ func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error)
} }
return nil return nil
} }
chunk, err := io_data.next_chunk(false) chunk, err := io_data.next_chunk()
if err != nil { if err != nil {
return err return err
} }