]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/sp.go
Do not close fd each time chunk is sent
[nncp.git] / src / sp.go
index 0e33c06f769f71a704a80889fd5cec173de103bf..5840bd15c794b7586a26098d6c4cdc750a9d0f7c 100644 (file)
--- a/src/sp.go
+++ b/src/sp.go
@@ -875,6 +875,9 @@ func (state *SPState) StartWorkers(
                                fdAndFullSize, exists := state.fds[pth]
                                state.fdsLock.RUnlock()
                                if !exists {
+                                       state.Ctx.LogD("sp-queue-open", lesp, func(les LEs) string {
+                                               return logMsg(les) + ": opening"
+                                       })
                                        fd, err := os.Open(pth)
                                        if err != nil {
                                                state.Ctx.LogE("sp-queue-open", lesp, err, func(les LEs) string {
@@ -896,6 +899,7 @@ func (state *SPState) StartWorkers(
                                }
                                fd := fdAndFullSize.fd
                                fullSize := fdAndFullSize.fullSize
+                               lesp = append(lesp, LE{"FullSize", fullSize})
                                var bufRead []byte
                                if freq.Offset < uint64(fullSize) {
                                        state.Ctx.LogD("sp-file-seek", lesp, func(les LEs) string {
@@ -920,6 +924,7 @@ func (state *SPState) StartWorkers(
                                                LE{"XX", string(TTx)},
                                                LE{"Pkt", pktName},
                                                LE{"Size", int64(n)},
+                                               LE{"FullSize", fullSize},
                                        )
                                        state.Ctx.LogD("sp-file-read", lesp, func(les LEs) string {
                                                return fmt.Sprintf(
@@ -927,8 +932,9 @@ func (state *SPState) StartWorkers(
                                                        logMsg(les), humanize.IBytes(uint64(n)),
                                                )
                                        })
+                               } else {
+                                       state.closeFd(pth)
                                }
-                               state.closeFd(pth)
                                payload = MarshalSP(SPTypeFile, SPFile{
                                        Hash:    freq.Hash,
                                        Offset:  freq.Offset,