File tree Expand file tree Collapse file tree 2 files changed +20
-13
lines changed
AndroidAsync/src/com/koushikdutta/async Expand file tree Collapse file tree 2 files changed +20
-13
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ public boolean isBuffering() {
13
13
return mPendingWrites .hasRemaining () || forceBuffering ;
14
14
}
15
15
16
+ public boolean isWritable () {
17
+ synchronized (mPendingWrites ) {
18
+ return mPendingWrites .remaining () < mMaxBuffer ;
19
+ }
20
+ }
21
+
16
22
public DataSink getDataSink () {
17
23
return mDataSink ;
18
24
}
@@ -49,22 +55,26 @@ private void writePending() {
49
55
50
56
final ByteBufferList mPendingWrites = new ByteBufferList ();
51
57
52
- @ Override
53
- public void write ( ByteBufferList bb ) {
54
- write ( bb , false );
58
+ // before the data is queued, let inheritors know. allows for filters, without
59
+ // issues with having to filter before writing which may fail in the buffer.
60
+ protected void onDataAccepted ( ByteBufferList bb ) {
55
61
}
56
62
57
- protected void write (final ByteBufferList bb , final boolean ignoreBuffer ) {
63
+ @ Override
64
+ public void write (final ByteBufferList bb ) {
58
65
if (getServer ().getAffinity () != Thread .currentThread ()) {
59
66
synchronized (mPendingWrites ) {
60
- if (mPendingWrites .remaining () >= mMaxBuffer && ! ignoreBuffer )
67
+ if (mPendingWrites .remaining () >= mMaxBuffer )
61
68
return ;
69
+ onDataAccepted (bb );
62
70
bb .get (mPendingWrites );
63
71
}
64
72
getServer ().post (this ::writePending );
65
73
return ;
66
74
}
67
75
76
+ onDataAccepted (bb );
77
+
68
78
if (!isBuffering ())
69
79
mDataSink .write (bb );
70
80
Original file line number Diff line number Diff line change @@ -11,15 +11,12 @@ public ByteBufferList filter(ByteBufferList bb) {
11
11
}
12
12
13
13
@ Override
14
- public final void write (ByteBufferList bb ) {
15
- // don't filter and write if currently buffering, unless we know
16
- // that the buffer can fit the entirety of the filtered result
17
- if (isBuffering () && getMaxBuffer () != Integer .MAX_VALUE )
18
- return ;
14
+ protected void onDataAccepted (ByteBufferList bb ) {
19
15
ByteBufferList filtered = filter (bb );
20
- assert bb == null || filtered == bb || bb .isEmpty ();
21
- super .write (filtered , true );
22
- if (bb != null )
16
+ // filtering may return the same byte buffer, so watch for that.
17
+ if (filtered != bb ) {
23
18
bb .recycle ();
19
+ filtered .get (bb );
20
+ }
24
21
}
25
22
}
You can’t perform that action at this time.
0 commit comments