diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-10-10 07:56:56 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-10-10 07:56:56 +0200 |
commit | 57fc2e284684aab5b6bb3b56d0035fda4b1e63b3 (patch) | |
tree | 7b42397793ca55ccbcac47ee7188d5d9a6ccd396 /apps/osc.c | |
parent | midi is back from threded to async io (diff) |
got rid of threads entirely
Diffstat (limited to 'apps/osc.c')
-rw-r--r-- | apps/osc.c | 37 |
1 files changed, 23 insertions, 14 deletions
@@ -54,36 +54,45 @@ int osc_init(osc_t* o, const char* port) { assert(o != NULL); - o->st_ = lo_server_thread_new(port, print_error); - if(!o->st_) + o->server_ = lo_server_new(port, print_error); + if(!o->server_) return -1; - if(!lo_server_thread_add_method(o->st_, NULL, NULL, generic_handler, NULL)) + if(!lo_server_add_method(o->server_, NULL, NULL, generic_handler, NULL)) return -1; return 0; } -int osc_start(osc_t* o) + +int osc_get_poll_fd_count(osc_t* o) { - assert(o != NULL); + return 1; +} - int ret = lo_server_thread_start(o->st_); - if(ret) - error(0, ret, "faild to create osc thread"); +int osc_get_poll_fds(osc_t* o, struct pollfd *pfds, int npfds) +{ + assert(npfds == 1); + + pfds[0].fd = lo_server_get_socket_fd(o->server_); + pfds[0].events = POLLIN; + pfds[0].revents = 0; return 0; } -int osc_stop(osc_t* o) +int osc_handle_revents(osc_t* o, struct pollfd *pfds, int npfds) { - assert(o != NULL); + assert(npfds == 1); - int ret = lo_server_thread_stop(o->st_); - if(ret) - error(0, ret, "faild to stop osc thread"); + if(pfds[0].revents & (POLLERR | POLLHUP)) { + error(0, 0, "OSC: got POLLERR or POLLHUP"); + return -1; + } + if(!(pfds[0].revents & POLLIN)) + return 0; - lo_server_thread_free(o->st_); + lo_server_recv_noblock(o->server_, 0); return 0; } |