MCPcopy Create free account
hub / github.com/clementgallet/libTAS / sync_jsdev

Function sync_jsdev

src/library/inputs/jsdev.cpp:126–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126bool 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
153int get_js_number(int fd)
154{

Callers 1

syncControllerEventsFunction · 0.85

Calls 2

ioctlFunction · 0.85
nanosleepFunction · 0.85

Tested by

no test coverage detected