Introduce configurable buffer size
This commit is contained in:
parent
9924771531
commit
0bb19ba8bd
4 changed files with 23 additions and 5 deletions
|
@ -16,6 +16,14 @@ type SignerProtocolHandler interface {
|
|||
HandleSignerProtocol() error
|
||||
}
|
||||
|
||||
type signerProtocolConfig struct {
|
||||
BufferSize int
|
||||
}
|
||||
|
||||
func NewSignerProtocolConfig() *signerProtocolConfig {
|
||||
return &signerProtocolConfig{BufferSize: 2048}
|
||||
}
|
||||
|
||||
type SignerProtocolRequestChannel struct {
|
||||
C chan *datastructures.SignerRequest
|
||||
closed bool
|
||||
|
@ -45,6 +53,7 @@ type protocolHandler struct {
|
|||
requestChannel *SignerProtocolRequestChannel
|
||||
responseChannel *chan *datastructures.SignerResponse
|
||||
serialConnection *io.ReadWriteCloser
|
||||
config *signerProtocolConfig
|
||||
}
|
||||
|
||||
type UnExpectedAcknowledgeByte struct {
|
||||
|
@ -67,11 +76,12 @@ func (ph *protocolHandler) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewProtocolHandler(requests *SignerProtocolRequestChannel, response *chan *datastructures.SignerResponse, serialConnection *io.ReadWriteCloser) SignerProtocolHandler {
|
||||
func NewProtocolHandler(requests *SignerProtocolRequestChannel, response *chan *datastructures.SignerResponse, serialConnection *io.ReadWriteCloser, config *signerProtocolConfig) SignerProtocolHandler {
|
||||
return &protocolHandler{
|
||||
requestChannel: requests,
|
||||
responseChannel: response,
|
||||
serialConnection: serialConnection,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +89,7 @@ func (ph *protocolHandler) HandleSignerProtocol() error {
|
|||
for {
|
||||
select {
|
||||
case request := <-ph.requestChannel.C:
|
||||
log.Debugf("handle request %+v", request)
|
||||
log.Tracef("handle request %+v", request)
|
||||
var err error
|
||||
var lengthBytes, responseBytes *[]byte
|
||||
var checksum byte
|
||||
|
@ -187,7 +197,7 @@ func (ph *protocolHandler) readResponse() (*[]byte, *[]byte, byte, error) {
|
|||
var byteBuffer = bytes.NewBuffer(make([]byte, 0))
|
||||
|
||||
for {
|
||||
readBuffer, err := shared.ReceiveBytes(ph.serialConnection, 100, 5*time.Second)
|
||||
readBuffer, err := shared.ReceiveBytes(ph.serialConnection, ph.config.BufferSize, 5*time.Second)
|
||||
if err != nil {
|
||||
return nil, nil, 0, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue