Skip to content

Commit

Permalink
Work around hangs on newer Linux kernels (#147)
Browse files Browse the repository at this point in the history
* Fix off-by-one error in debug print

* Bump min CMake version to avoid deprecation warning

* Change the Linux code to non-blocking sockets

Works around a problem with 6.6.x and newer kernels that seem to not
deliver packets to blocking sockets reliably, causing hangs during the
handshake.

* Prepare release
  • Loading branch information
janoc committed Feb 24, 2024
1 parent 5f5ba66 commit cf82bb3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ Original project (0.12 and earlier):
most recent archive from 2010 (looks identical on homepage to 2011 snapshot above)
<https://web.archive.org/web/20100216015311/http://wiiuse.sourceforge.net/>

v0.15.6 -- 18-Feb-2024
--------------------

Fixed:

- Linux - Fixed hang with kernels 6.6.x and newer
- Corrected historical record about Wiiuse origins
- Require CMake > 3.6.x to avoid deprecation warnings
- Support for Balance Board calibration


v0.15.5 -- 24-Nov-2019
--------------------

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# http://academic.cleardefinition.com/
# Iowa State University HCI Graduate Program/VRAC

cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.6.0)

# Set package properties
project(WiiUse
Expand Down
7 changes: 5 additions & 2 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ button on the web interface should make this even simpler.

## Authors

Mostly-absentee (but delegating!) Fork Maintainer: Ryan Pavlik <ryan.pavlik@gmail.com> or <abiryan@ryand.net>
Mostly-absentee (but delegating!) Fork Maintainer: Rylie Pavlik <https://github.com/rpavlik> <rylie.pavlik@collabora.com>

Original Author: Michael Laforest < para > < thepara (--AT--) g m a i l [--DOT--] com >

Additional Contributors:

- Jan Ciger <https://github.com/janoc> <jan.ciger@gmail.com> (effective co-maintainer)
- Jan Ciger <https://github.com/janoc> <contact@jciger.com> (effective co-maintainer)
- dhewg
- Christopher Sawczuk @ TU-Delft (initial Balance Board support)
- Paul Burton <https://github.com/paulburton/wiiuse>
Expand All @@ -72,6 +72,9 @@ Additional Contributors:
- Bart Ribbers <https://github.com/PureTryOut>
- Samuel Hackbeil <https://github.com/shackbei>
- Jean-Michaël Celerier <https://github.com/jcelerier>
- Dave Murphy <https://github.com/WinterMute>
- Forrest Cahoon <https://github.com/forrcaho>


## License

Expand Down
6 changes: 3 additions & 3 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ int wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buffe
if (elapsed > timeout_ms && timeout_ms > 0)
{
result = -1;
WIIUSE_DEBUG("(id %i) timeout waiting for report 0x%x, aborting!", wm->unid, report);
break;
}
wiiuse_millisleep(10);
}

return result;
Expand Down Expand Up @@ -328,10 +330,8 @@ void wiiuse_handshake(struct wiimote_t *wm, byte *data, uint16_t len)
wiiuse_status(wm);
rc = wiiuse_wait_report(wm, WM_RPT_CTRL_STATUS, buf, MAX_PAYLOAD, WIIUSE_READ_TIMEOUT);

if (buf[3] != 0)
if (rc && buf[3] != 0)
break;

wiiuse_millisleep(500);
}
propagate_event(wm, WM_RPT_CTRL_STATUS, buf + 1);
}
Expand Down
29 changes: 20 additions & 9 deletions src/os_nix.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,33 @@ int wiiuse_os_read(struct wiimote_t *wm, byte *buf, int len)
{
int rc;

rc = read(wm->in_sock, buf, len);

rc = recv(wm->in_sock, buf, len, MSG_DONTWAIT);
if (rc == -1)
{
/* error reading data */
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid);
perror("Error Details");

if (errno == ENOTCONN)
switch(errno)
{
case ENOTCONN:
/* this can happen if the bluetooth dongle is disconnected */
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid);
perror("Error Details");

WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.",
wm->unid);
wiiuse_os_disconnect(wm);
wiiuse_disconnected(wm);
break;

case EAGAIN:
/* no data available yet */
break;

default:
/* error reading data */
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid);
perror("Error Details");
break;
}

} else if (rc == 0)
{
/* remote disconnect */
Expand All @@ -406,7 +417,7 @@ int wiiuse_os_read(struct wiimote_t *wm, byte *buf, int len)
{ /* hack for chatty Balance Boards that flood the logs with useless button reports */
int i;
printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]);
for (i = 1; i < rc; i++)
for (i = 1; i < rc - 1; i++)
{
printf("%.2x ", buf[i]);
}
Expand All @@ -427,7 +438,7 @@ int wiiuse_os_write(struct wiimote_t *wm, byte report_type, byte *buf, int len)
write_buffer[1] = report_type;
memcpy(write_buffer + 2, buf, len);

rc = write(wm->in_sock, write_buffer, len + 2);
rc = send(wm->in_sock, write_buffer, len + 2, 0);

if (rc < 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/wiiuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

#define WIIUSE_MAJOR 0
#define WIIUSE_MINOR 15
#define WIIUSE_MICRO 5
#define WIIUSE_MICRO 6

#define WIIUSE_VERSION_TRANSFORM(MAJ, MIN, MICRO) (MAJ * 1000000 + MIN * 1000 + MICRO)
#define WIIUSE_HAS_VERSION(MAJ, MIN, MICRO) \
Expand Down

0 comments on commit cf82bb3

Please sign in to comment.