WriteTo is a packet-oriented interface that fires off the given payload to the given address.
(b []byte, addr string)
| 467 | // WriteTo is a packet-oriented interface that fires off the given |
| 468 | // payload to the given address. |
| 469 | func (t *TCPTransport) WriteTo(b []byte, addr string) (time.Time, error) { |
| 470 | t.shutdownMu.RLock() |
| 471 | defer t.shutdownMu.RUnlock() // Unlock at the end to protect the chan |
| 472 | if t.shutdown { |
| 473 | return time.Time{}, errors.New("transport is shutting down") |
| 474 | } |
| 475 | |
| 476 | // Send the packet to the write workers |
| 477 | // If this blocks for too long (as configured), abort and log an error. |
| 478 | select { |
| 479 | case <-time.After(t.cfg.AcquireWriterTimeout): |
| 480 | // Dropped packets are not an issue, the memberlist protocol will retry later. |
| 481 | level.Debug(t.logger).Log("msg", "WriteTo failed to acquire a writer. Dropping message", "timeout", t.cfg.AcquireWriterTimeout, "addr", addr) |
| 482 | t.droppedPackets.Inc() |
| 483 | // WriteTo is used to send "UDP" packets. Since we use TCP, we can detect more errors, |
| 484 | // but memberlist library doesn't seem to cope with that very well. That is why we return nil instead. |
| 485 | return time.Now(), nil |
| 486 | case t.writeCh <- writeRequest{b: b, addr: addr}: |
| 487 | // OK |
| 488 | } |
| 489 | |
| 490 | return time.Now(), nil |
| 491 | } |
| 492 | |
| 493 | func (t *TCPTransport) writeWorker() { |
| 494 | defer t.writeWG.Done() |