netsocketserver: yield if there is nothing on the wire
@@ -936,12 +936,43 @@ int main(int argc, char *argv[])
IDC_EXPORT_FLAGS_DEFAULT);
assert(err_is_ok(err));
+ struct waitset *ws = get_default_waitset();
+
+#ifdef POLLING
+#define POLLING_YIELD_IDLE 10
+ uint16_t polling_yield = POLLING_YIELD_IDLE;
+#endif
while(1) {
#ifdef POLLING
- event_dispatch_non_block(get_default_waitset());
- networking_poll();
+ err = event_dispatch_non_block(ws);
+ switch(err_no(err)) {
+ case SYS_ERR_OK:
+ polling_yield = POLLING_YIELD_IDLE;
+ break;
+ case LIB_ERR_NO_EVENT:
+ polling_yield--;
+ break;
+ default:
+ USER_PANIC_ERR(err, "error happened while dispatching event.");
+ }
+ err = networking_poll();
+ switch(err_no(err)) {
+ case SYS_ERR_OK:
+ polling_yield = POLLING_YIELD_IDLE;
+ break;
+ case LIB_ERR_NO_EVENT:
+ polling_yield--;
+ break;
+ default:
+ USER_PANIC_ERR(err, "error happened while dispatching event.");
+ }
+
+ if (polling_yield == 0) {
+ thread_yield();
+ polling_yield = POLLING_YIELD_IDLE;
+ }
#else
- event_dispatch(get_default_waitset());
+ event_dispatch(ws);
#endif
}
