835 } else if (debug.on()) { |
835 } else if (debug.on()) { |
836 debug.log("Channel already closed, no need to reset stream %d", |
836 debug.log("Channel already closed, no need to reset stream %d", |
837 streamid); |
837 streamid); |
838 } |
838 } |
839 } finally { |
839 } finally { |
|
840 decrementStreamsCount(streamid); |
840 closeStream(streamid); |
841 closeStream(streamid); |
|
842 } |
|
843 } |
|
844 |
|
845 // reduce count of streams by 1 if stream still exists |
|
846 synchronized void decrementStreamsCount(int streamid) { |
|
847 Stream<?> s = streams.get(streamid); |
|
848 if (s == null || !s.deRegister()) |
|
849 return; |
|
850 if (streamid % 2 == 1) { |
|
851 numReservedClientStreams--; |
|
852 } else { |
|
853 numReservedServerStreams--; |
841 } |
854 } |
842 } |
855 } |
843 |
856 |
844 void closeStream(int streamid) { |
857 void closeStream(int streamid) { |
845 if (debug.on()) debug.log("Closed stream %d", streamid); |
858 if (debug.on()) debug.log("Closed stream %d", streamid); |
846 boolean isClient = (streamid % 2) == 1; |
859 boolean isClient = (streamid % 2) == 1; |
847 Stream<?> s = streams.remove(streamid); |
860 Stream<?> s = streams.remove(streamid); |
848 if (s != null) { |
861 if (s != null) { |
849 synchronized (this) { |
|
850 if (isClient) |
|
851 numReservedClientStreams--; |
|
852 else |
|
853 numReservedServerStreams--; |
|
854 } |
|
855 assert numReservedClientStreams >= 0; |
|
856 assert numReservedServerStreams >= 0; |
|
857 // decrement the reference count on the HttpClientImpl |
862 // decrement the reference count on the HttpClientImpl |
858 // to allow the SelectorManager thread to exit if no |
863 // to allow the SelectorManager thread to exit if no |
859 // other operation is pending and the facade is no |
864 // other operation is pending and the facade is no |
860 // longer referenced. |
865 // longer referenced. |
861 client().streamUnreference(); |
866 client().streamUnreference(); |