Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EINTR handling #26

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,12 @@ void *ep_loop_write(void *arg) {
ep.bEndpointAddress, transfer_type.c_str(), dir.c_str());
continue;
}
else if (rv < 0) {
if (rv < 0) {
perror("usb_raw_ep_write()");
exit(EXIT_FAILURE);
}
else {
printf("EP%x(%s_%s): wrote %d bytes to host\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str(), rv);
}
printf("EP%x(%s_%s): wrote %d bytes to host\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str(), rv);
}
else {
int length = io.inner.length;
Expand Down Expand Up @@ -249,25 +247,28 @@ void *ep_loop_read(void *arg) {
ep.bEndpointAddress, transfer_type.c_str(), dir.c_str());
break;
}
else if (rv < 0) {
if (rv < 0 && errno == EINTR) {
printf("EP%x(%s_%s): interface likely changing, stopping thread\n",
ep.bEndpointAddress, transfer_type.c_str(), dir.c_str());
break;
}
if (rv < 0) {
perror("usb_raw_ep_read()");
exit(EXIT_FAILURE);
}
else {
printf("EP%x(%s_%s): read %d bytes from host\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str(), rv);
io.inner.length = rv;
printf("EP%x(%s_%s): read %d bytes from host\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str(), rv);
io.inner.length = rv;

if (injection_enabled)
injection(io, ep, transfer_type);
if (injection_enabled)
injection(io, ep, transfer_type);

data_mutex->lock();
data_queue->push_back(io);
data_mutex->unlock();
if (verbose_level)
printf("EP%x(%s_%s): enqueued %d bytes to queue\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str(), rv);
}
data_mutex->lock();
data_queue->push_back(io);
data_mutex->unlock();
if (verbose_level)
printf("EP%x(%s_%s): enqueued %d bytes to queue\n", ep.bEndpointAddress,
transfer_type.c_str(), dir.c_str(), rv);
}
}

Expand Down