|
4 | 4 | "crypto/tls" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
| 7 | + "log" |
7 | 8 | "net" |
8 | 9 | "sync" |
9 | 10 | "sync/atomic" |
|
40 | 41 | ErrTooLarge = errors.New("synapse: message body too large") |
41 | 42 | ) |
42 | 43 |
|
| 44 | +// ErrorLogger is the logger used |
| 45 | +// by the package to log protocol |
| 46 | +// errors. (In general, protocol-level |
| 47 | +// errors are not returned directly |
| 48 | +// to the client.) It can be set during |
| 49 | +// initialization. If it is left |
| 50 | +// as nil, nothing will be logged. |
| 51 | +var ErrorLogger *log.Logger |
| 52 | + |
| 53 | +func errorln(s string) { |
| 54 | + if ErrorLogger != nil { |
| 55 | + ErrorLogger.Println(s) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func errorf(s string, args ...interface{}) { |
| 60 | + if ErrorLogger != nil { |
| 61 | + ErrorLogger.Printf(s, args...) |
| 62 | + } |
| 63 | +} |
| 64 | + |
43 | 65 | // Dial creates a new client by dialing |
44 | 66 | // the provided network and remote address. |
45 | 67 | // The provided timeout is used as the timeout |
@@ -199,6 +221,7 @@ func (c *Client) readLoop() { |
199 | 221 | // they are routed to waiters |
200 | 222 | // precisely the same way |
201 | 223 | if frame != fCMD && frame != fRES { |
| 224 | + errorf("server at addr %s sent a bad frame", c.conn.RemoteAddr()) |
202 | 225 | // ignore |
203 | 226 | if !c.do(bwr.Skip(sz)) { |
204 | 227 | return |
@@ -458,5 +481,8 @@ func (c *Client) ping() error { |
458 | 481 |
|
459 | 482 | // sync known service addresses |
460 | 483 | func (c *Client) syncLinks() { |
461 | | - c.sendCommand(cmdListLinks, svclistbytes()) |
| 484 | + err := c.sendCommand(cmdListLinks, svclistbytes()) |
| 485 | + if err != nil { |
| 486 | + errorf("error synchronizing links: %s", err) |
| 487 | + } |
462 | 488 | } |
0 commit comments