@@ -444,7 +444,7 @@ private static void sendReply(Socket s, UsbIpUnlinkUrbReply reply, int status) {
444
444
445
445
// FIXME: This dispatching could use some refactoring so we don't have to pass
446
446
// a million parameters to this guy
447
- private void dispatchRequest (final AttachedDeviceContext context , final Socket s ,
447
+ private void dispatchRequest (final AttachedDeviceContext context , final int deviceId , final Socket s ,
448
448
final UsbEndpoint selectedEndpoint , final ByteBuffer buff , final UsbIpSubmitUrb msg ) {
449
449
context .requestPool .submit (new Runnable () {
450
450
@ Override
@@ -485,6 +485,14 @@ public void run() {
485
485
}
486
486
487
487
if (res < 0 ) {
488
+ // If the request failed, let's see if the device is still around
489
+ UsbDevice dev = getDevice (deviceId );
490
+ if (dev == null ) {
491
+ // The device is gone, so terminate the client
492
+ server .killClient (s );
493
+ return ;
494
+ }
495
+
488
496
reply .status = res ;
489
497
}
490
498
else {
@@ -524,6 +532,14 @@ else if (selectedEndpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
524
532
525
533
if (res < 0 ) {
526
534
reply .status = res ;
535
+
536
+ // If the request failed, let's see if the device is still around
537
+ UsbDevice dev = getDevice (deviceId );
538
+ if (dev == null ) {
539
+ // The device is gone, so terminate the client
540
+ server .killClient (s );
541
+ return ;
542
+ }
527
543
}
528
544
else {
529
545
reply .actualLength = res ;
@@ -549,13 +565,6 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
549
565
550
566
int deviceId = devIdToDeviceId (msg .devId );
551
567
552
- UsbDevice dev = getDevice (deviceId );
553
- if (dev == null ) {
554
- // The device is gone, so terminate the client
555
- server .killClient (s );
556
- return ;
557
- }
558
-
559
568
AttachedDeviceContext context = connections .get (deviceId );
560
569
if (context == null ) {
561
570
// This should never happen, but kill the connection if it does
@@ -609,6 +618,14 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
609
618
}
610
619
611
620
if (res < 0 ) {
621
+ // If the request failed, let's see if the device is still around
622
+ UsbDevice dev = getDevice (deviceId );
623
+ if (dev == null ) {
624
+ // The device is gone, so terminate the client
625
+ server .killClient (s );
626
+ return ;
627
+ }
628
+
612
629
reply .status = res ;
613
630
}
614
631
else {
@@ -618,7 +635,6 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
618
635
619
636
context .activeMessages .remove (msg );
620
637
sendReply (s , reply , reply .status );
621
- return ;
622
638
}
623
639
else {
624
640
// Find the correct endpoint
@@ -651,7 +667,7 @@ public void submitUrbRequest(Socket s, UsbIpSubmitUrb msg) {
651
667
context .activeMessages .add (msg );
652
668
653
669
// Dispatch this request asynchronously
654
- dispatchRequest (context , s , selectedEndpoint , buff , msg );
670
+ dispatchRequest (context , deviceId , s , selectedEndpoint , buff , msg );
655
671
}
656
672
}
657
673
0 commit comments