File tree 1 file changed +24
-13
lines changed
source/AndroidResolver/src
1 file changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -213,21 +213,32 @@ private void Read()
213
213
stream . BeginRead (
214
214
buffer , 0 , buffer . Length , ( asyncResult ) => {
215
215
int bytesRead = stream . EndRead ( asyncResult ) ;
216
- if ( ! complete )
217
- {
218
- complete = bytesRead == 0 ;
219
- if ( DataReceived != null )
220
- {
221
- byte [ ] copy = new byte [ bytesRead ] ;
222
- Array . Copy ( buffer , copy , copy . Length ) ;
223
- DataReceived ( new StreamData (
224
- handle , Encoding . UTF8 . GetString ( copy ) , copy ,
225
- complete ) ) ;
226
- }
227
- }
216
+ BytesReadCallback ( bytesRead ) ;
228
217
readEvent . Set ( ) ;
229
218
} , null ) ;
230
- readEvent . WaitOne ( ) ;
219
+ var waitResult = readEvent . WaitOne ( 10000 ) ;
220
+
221
+ if ( ! waitResult )
222
+ {
223
+ UnityEngine . Debug . Log ( $ "Timeout of { nameof ( AsyncStreamReader ) } waiting") ;
224
+ BytesReadCallback ( 0 ) ;
225
+ }
226
+ }
227
+
228
+ void BytesReadCallback ( int bytesRead )
229
+ {
230
+ if ( complete )
231
+ return ;
232
+
233
+ complete = bytesRead == 0 ;
234
+ if ( DataReceived == null )
235
+ return ;
236
+
237
+ byte [ ] copy = new byte [ bytesRead ] ;
238
+ Array . Copy ( buffer , copy , copy . Length ) ;
239
+ DataReceived ( new StreamData (
240
+ handle , Encoding . UTF8 . GetString ( copy ) , copy ,
241
+ complete ) ) ;
231
242
}
232
243
}
233
244
You can’t perform that action at this time.
0 commit comments