|
|
|
|
@ -400,8 +400,6 @@ func (m *MuxConn) loop() {
|
|
|
|
|
stream.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
case muxPacketData:
|
|
|
|
|
unlocked := false
|
|
|
|
|
|
|
|
|
|
stream.mu.Lock()
|
|
|
|
|
switch stream.state {
|
|
|
|
|
case streamStateFinWait1:
|
|
|
|
|
@ -409,26 +407,15 @@ func (m *MuxConn) loop() {
|
|
|
|
|
case streamStateFinWait2:
|
|
|
|
|
fallthrough
|
|
|
|
|
case streamStateEstablished:
|
|
|
|
|
if len(data) > 0 {
|
|
|
|
|
// Get a reference to the write channel while we have
|
|
|
|
|
// the lock because otherwise the field might change.
|
|
|
|
|
// We unlock early here because the write might block
|
|
|
|
|
// for a long time.
|
|
|
|
|
writeCh := stream.writeCh
|
|
|
|
|
stream.mu.Unlock()
|
|
|
|
|
unlocked = true
|
|
|
|
|
|
|
|
|
|
// Blocked write, this provides some backpressure on
|
|
|
|
|
// the connection if there is a lot of data incoming.
|
|
|
|
|
writeCh <- data
|
|
|
|
|
if len(data) > 0 && stream.writeCh != nil {
|
|
|
|
|
//log.Printf("[TRACE] %p: Stream %d (%s) WRITE-START", m, id, from)
|
|
|
|
|
stream.writeCh <- data
|
|
|
|
|
//log.Printf("[TRACE] %p: Stream %d (%s) WRITE-END", m, id, from)
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
log.Printf("[ERR] Data received for stream in state: %d", stream.state)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !unlocked {
|
|
|
|
|
stream.mu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
stream.mu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -516,6 +503,7 @@ func newStream(from muxPacketFrom, id uint32, m *MuxConn) *Stream {
|
|
|
|
|
go func() {
|
|
|
|
|
defer dataW.Close()
|
|
|
|
|
|
|
|
|
|
drain := false
|
|
|
|
|
for {
|
|
|
|
|
data := <-writeCh
|
|
|
|
|
if data == nil {
|
|
|
|
|
@ -524,8 +512,14 @@ func newStream(from muxPacketFrom, id uint32, m *MuxConn) *Stream {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if drain {
|
|
|
|
|
// We're draining, meaning we're just waiting for the
|
|
|
|
|
// write channel to close.
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := dataW.Write(data); err != nil {
|
|
|
|
|
return
|
|
|
|
|
drain = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
@ -568,7 +562,10 @@ func (s *Stream) Write(p []byte) (int, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Stream) closeWriter() {
|
|
|
|
|
s.writeCh <- nil
|
|
|
|
|
if s.writeCh != nil {
|
|
|
|
|
s.writeCh <- nil
|
|
|
|
|
s.writeCh = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Stream) setState(state streamState) {
|
|
|
|
|
@ -594,6 +591,7 @@ func (s *Stream) waitState(target streamState) error {
|
|
|
|
|
delete(s.stateChange, stateCh)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
//log.Printf("[TRACE] %p: Stream %d (%s) waiting for state: %d", s.mux, s.id, s.from, target)
|
|
|
|
|
state := <-stateCh
|
|
|
|
|
if state == target {
|
|
|
|
|
return nil
|
|
|
|
|
|