From 90577e48753c569ff0efe18c0ec48ea7b1b6d259 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Sun, 20 May 2007 04:56:51 +0000 Subject: [PATCH] an attempt to put a cross platform poll into the header file. This is really wrong as we can't differentiate between in band and oob on windows right now. git-svn-id: http://svn.openzap.org/svn/openzap/trunk@44 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/sangoma_tdm_api.h | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libs/openzap/src/include/sangoma_tdm_api.h b/libs/openzap/src/include/sangoma_tdm_api.h index 98033bb523..a2ede350c3 100644 --- a/libs/openzap/src/include/sangoma_tdm_api.h +++ b/libs/openzap/src/include/sangoma_tdm_api.h @@ -441,4 +441,70 @@ static __inline void empty_api_queue(api_queue_t* api_queue) /////////////////////////////////////////////////////////////////////////// #endif +#if defined(__WINDOWS__) +/* This is broken, we don't actually get real results for oob messages on windows */ +#define POLLPRI (POLL_EVENT_LINK_STATE | POLL_EVENT_LINK_CONNECT | POLL_EVENT_LINK_DISCONNECT) +#endif + +/* return -1 for error, 0 for timeout, or POLLIN | POLLOUT | POLLPRI based on the result of the poll */ +int tdmv_api_wait_socket(sng_fd_t fd, int timeout, int flags) +{ +#if defined(__WINDOWS__) + API_POLL_STRUCT api_poll; + + memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT)); + + api_poll.user_flags_bitmap = flags; + api_poll.timeout = timeout; + + if(DoApiPollCommand(fd, &api_poll)) { + return -1; + } + + switch(api_poll.operation_status) + { + case SANG_STATUS_RX_DATA_AVAILABLE: + break; + + case SANG_STATUS_RX_DATA_TIMEOUT: + return 0; + + default: + return -1; + } + + if(api_poll.poll_events_bitmap == 0){ + return -1; + } + + if(api_poll.poll_events_bitmap & POLL_EVENT_TIMEOUT){ + return 0; + } + + return api_poll.poll_events_bitmap; +#else + struct pollfd pfds[1]; + int res; + + memset(&pfds[0], 0, sizeof(pfds[0])); + pfds[0].fd = fd; + pfds[0].events = flags; + res = poll(pfds, 1, timeout); + + if (res == 0) { + return 0; + } + + if (res < 0) { + return -1; + } + + if ((pfds[0].revents & POLLERR)) { + return -1; + } + + return pfds[0].revents; +#endif +} + #endif /* _SANGOMA_TDM_API_H */