libimobiledevice / libimobiledevice-glue

A library with common code used by libraries and tools around the libimobiledevice project
GNU Lesser General Public License v2.1
91 stars 70 forks source link

socket: select returns 1 when the socket is closed #19

Closed AiXanadu closed 2 years ago

AiXanadu commented 2 years ago

On Windows, when I quickly unplug the device. Sometimes it gets stuck in send(). The reason is that when the peer (driver) closes the socket, select returns a value of 1. So I use very little time to check if the current is readable. If the read data is less than or equal to 0, the socket is closed. We don't need to send, because continuing the operation will prevent the thread from returning and continue to consume CPU resources.

nikias commented 2 years ago

I get the point but I could measure a noticeable performance impact on the transfer speeds via USB. I need to find a different solution for this...

AiXanadu commented 2 years ago

You can check out the latter commit, which is a temporary solution and is closed.

nikias commented 2 years ago

You're probably referring to #22. I want to check if there's a more elegant solution to this generic problem, but the new PR definitely makes it better.

AiXanadu commented 2 years ago

You're quite right, the new changes are mainly due to the slowness of sending large amounts of filesystem data when restoring a device. So I added an actively set flag to let the user decide whether to enable this feature.