#755 fix args to put into the pool

This commit is contained in:
smallnest
2022-08-31 19:24:18 +08:00
parent 109df38db1
commit dacebc70ca
2 changed files with 33 additions and 2 deletions

View File

@@ -92,7 +92,9 @@ func (s *FileTransferService) TransferFile(ctx context.Context, args *share.File
reply.Addr = s.FileTransfer.AdvertiseAddr
}
s.FileTransfer.cachedTokens.Add(string(token), &tokenInfo{token, args})
cloned := args.Clone()
s.FileTransfer.cachedTokens.Add(string(token), &tokenInfo{token, cloned})
return nil
}
@@ -112,7 +114,9 @@ func (s *FileTransferService) DownloadFile(ctx context.Context, args *share.Down
reply.Addr = s.FileTransfer.AdvertiseAddr
}
s.FileTransfer.cachedTokens.Add(string(token), &downloadTokenInfo{token, args})
cloned := args.Clone()
s.FileTransfer.cachedTokens.Add(string(token), &downloadTokenInfo{token, cloned})
return nil
}

View File

@@ -65,6 +65,20 @@ type FileTransferArgs struct {
Meta map[string]string `json:"meta,omitempty"`
}
// Clone clones this DownloadFileArgs.
func (args FileTransferArgs) Clone() *FileTransferArgs {
meta := make(map[string]string)
for k, v := range args.Meta {
meta[k] = v
}
return &FileTransferArgs{
FileName: args.FileName,
FileSize: args.FileSize,
Meta: meta,
}
}
// FileTransferReply response to token and addr to clients.
type FileTransferReply struct {
Token []byte `json:"token,omitempty"`
@@ -77,6 +91,19 @@ type DownloadFileArgs struct {
Meta map[string]string `json:"meta,omitempty"`
}
// Clone clones this DownloadFileArgs.
func (args DownloadFileArgs) Clone() *DownloadFileArgs {
meta := make(map[string]string)
for k, v := range args.Meta {
meta[k] = v
}
return &DownloadFileArgs{
FileName: args.FileName,
Meta: meta,
}
}
// StreamServiceArgs is the request type for stream service.
type StreamServiceArgs struct {
Meta map[string]string `json:"meta,omitempty"`