()
| 169 | } |
| 170 | |
| 171 | func (c *pconn) ackWorker() { |
| 172 | defer c.wg.Done() |
| 173 | |
| 174 | var ( |
| 175 | oneTime sync.Once |
| 176 | pc rpc.PCaller |
| 177 | err error |
| 178 | ) |
| 179 | |
| 180 | ackWorkerLoop: |
| 181 | for { |
| 182 | ack, got := <-c.ackCh |
| 183 | if !got { // closed and empty |
| 184 | break ackWorkerLoop |
| 185 | } |
| 186 | oneTime.Do(func() { |
| 187 | pc = c.pCaller.New() |
| 188 | }) |
| 189 | if err = ack.Sign(c.parent.privKey); err != nil { |
| 190 | log.WithField("target", pc.Target()).WithError(err).Error("failed to sign ack") |
| 191 | continue |
| 192 | } |
| 193 | |
| 194 | var ackRes types.AckResponse |
| 195 | // send ack back |
| 196 | if err = pc.Call(route.DBSAck.String(), ack, &ackRes); err != nil { |
| 197 | log.WithError(err).Debug("send ack failed") |
| 198 | continue |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if pc != nil { |
| 203 | pc.Close() |
| 204 | } |
| 205 | |
| 206 | log.Debug("ack worker quiting") |
| 207 | } |
| 208 | |
| 209 | func (c *pconn) close() error { |
| 210 | c.stopAckWorkers() |
no test coverage detected