New creates a session with a random ID is the caller's responsibility — pass it in. needsSYN should be true on the client side (so the first frame carries the SYN flag and Target), false on the server side (created from a received SYN).
(id [frame.SessionIDLen]byte, target string, needsSYN bool)
| 77 | // the SYN flag and Target), false on the server side (created from a received |
| 78 | // SYN). |
| 79 | func New(id [frame.SessionIDLen]byte, target string, needsSYN bool) *Session { |
| 80 | s := &Session{ |
| 81 | ID: id, |
| 82 | Target: target, |
| 83 | rxQueue: make(map[uint64]*frame.Frame), |
| 84 | RxChan: make(chan []byte, 1024), |
| 85 | synNeeded: needsSYN, |
| 86 | rxInbox: make(chan *frame.Frame, rxInboxCap), |
| 87 | rxDone: make(chan struct{}), |
| 88 | } |
| 89 | if needsSYN { |
| 90 | s.firstQueuedAt = time.Now() |
| 91 | } |
| 92 | s.txCond = sync.NewCond(&s.mu) |
| 93 | go s.rxLoop() |
| 94 | return s |
| 95 | } |
| 96 | |
| 97 | // Stop signals the rxLoop goroutine to exit. Must be called after removing the |
| 98 | // session from the routing table so no new ProcessRx calls can arrive. |