Skip to content

Commit

Permalink
Less syscalls to open files on the receiving end
Browse files Browse the repository at this point in the history
  • Loading branch information
Unbewohnte committed Feb 5, 2022
1 parent 8eb2f18 commit 2548fa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var (
VERSION string = "v2.3.0"
VERSION string = "v2.3.1"

versionInformation string = fmt.Sprintf("ftu %s\nfile transferring utility\n\nCopyright (C) 2021,2022 Kasyanov Nikolay Alexeevich (Unbewohnte ([email protected]))\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions; type \"ftu -l\" for details.\n", VERSION)

Expand Down
22 changes: 10 additions & 12 deletions src/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,11 @@ func (node *Node) receive() {
// accepted

// append provided bytes to the file

err = acceptedFile.Open()
if err != nil {
panic(err)
if acceptedFile.Handler == nil {
err = acceptedFile.Open()
if err != nil {
panic(err)
}
}

fileBytes := fileBytesBuffer.Bytes()
Expand All @@ -788,11 +789,6 @@ func (node *Node) receive() {
}
acceptedFile.SentBytes += uint64(wrote)
node.transferInfo.Receiving.ReceivedBytes += uint64(wrote)

err = acceptedFile.Close()
if err != nil {
panic(err)
}
}
}

Expand All @@ -819,9 +815,11 @@ func (node *Node) receive() {
fmt.Printf("\n[File] fully received \"%s\" -- %d bytes", acceptedFile.Name, acceptedFile.Size)
}

err = acceptedFile.Open()
if err != nil {
panic(err)
if acceptedFile.Handler == nil {
err = acceptedFile.Open()
if err != nil {
panic(err)
}
}

// remove this file from the pool
Expand Down

0 comments on commit 2548fa6

Please sign in to comment.