| 124 | } |
| 125 | |
| 126 | bool sync_jsdev(int jsnum) |
| 127 | { |
| 128 | if (jsdevfds[jsnum].second == 0) |
| 129 | return false; |
| 130 | |
| 131 | /* Do not attempt to sync if the pipe is already full */ |
| 132 | int attempts = 0, count = 0; |
| 133 | NATIVECALL(ioctl(jsdevfds[jsnum].first.first, FIONREAD, &count)); |
| 134 | |
| 135 | if (count >= static_cast<int>(64*sizeof(struct js_event))) |
| 136 | return false; |
| 137 | |
| 138 | do { |
| 139 | NATIVECALL(ioctl(jsdevfds[jsnum].first.first, FIONREAD, &count)); |
| 140 | if (count > 0) { |
| 141 | if (++attempts > 10 * 100) { |
| 142 | LOG(LL_ERROR, LCF_JOYSTICK, "jsdev sync took too long, were asynchronous events incorrectly enabled?"); |
| 143 | return false; |
| 144 | } |
| 145 | struct timespec sleepTime = { 0, 10 * 1000 }; |
| 146 | NATIVECALL(nanosleep(&sleepTime, NULL)); |
| 147 | } |
| 148 | } while (count > 0); |
| 149 | |
| 150 | return true; |
| 151 | } |
| 152 | |
| 153 | int get_js_number(int fd) |
| 154 | { |
no test coverage detected