diff --git a/.gitignore b/.gitignore index 2359e46..b2c9cc4 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ src/libosmocc/libosmocc.a src/libsample/libsample.a src/libfilter/libfilter.a src/libtimer/libtimer.a +src/libselect/libselect.a src/libph_socket/libph_socket.a src/pstn/osmo-cc-pstn-endpoint diff --git a/configure.ac b/configure.ac index e166919..612f4b2 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,7 @@ AC_OUTPUT( src/libfm/Makefile src/libfilter/Makefile src/libtimer/Makefile + src/libselect/Makefile src/libjitter/Makefile src/libosmocc/Makefile src/libg711/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 37340b7..7eb3a09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ SUBDIRS = \ libdtmf \ libfsk \ libtimer \ + libselect \ libjitter \ libosmocc \ libph_socket \ diff --git a/src/pstn/Makefile.am b/src/pstn/Makefile.am index 37973fd..276cfbd 100644 --- a/src/pstn/Makefile.am +++ b/src/pstn/Makefile.am @@ -20,6 +20,7 @@ osmo_cc_pstn_endpoint_LDADD = \ ../libfm/libfm.a \ ../libfilter/libfilter.a \ ../libtimer/libtimer.a \ + ../libselect/libselect.a \ ../libjitter/libjitter.a \ ../libosmocc/libosmocc.a \ ../libg711/libg711.a \ diff --git a/src/pstn/main.c b/src/pstn/main.c index e77ae3a..15e6c12 100644 --- a/src/pstn/main.c +++ b/src/pstn/main.c @@ -386,15 +386,22 @@ int main(int argc, char *argv[]) signal(SIGPIPE, sighandler); while (!quit) { - int w; - process_timer(); - pstn_work(pstn_ep); - rtp_work(pstn_ep); + int work; + double timeout; + /* handle all handlers until done */ do { - w = 0; - w |= osmo_cc_handle(); - } while (w); - usleep(1000); + work = 0; + work |= osmo_cc_handle(); + } while (work); + /* handle all timers + * timeout is 0, if there was an event + * -> handle FDs without waiting, continue this loop + * timeout is not 0, if there was no event + * -> wait until FD or timeout + */ + timeout = process_timer(); + /* wait for FD event until given timeout */ + work = osmo_fd_select(timeout); } signal(SIGINT, SIG_DFL); diff --git a/src/pstn/pstn.c b/src/pstn/pstn.c index 374da80..52e4263 100644 --- a/src/pstn/pstn.c +++ b/src/pstn/pstn.c @@ -301,7 +301,7 @@ void pstn_destroy(pstn_t *pstn) PDEBUG(DTEL, DEBUG_DEBUG, "PSTN instance destroyed\n"); } -static void pstn_timeout(struct timer *timer); +static void pstn_timeout(void *data); void recv_dtmf(void *priv, char digit, dtmf_meas_t __attribute__((unused)) *meas); static void pstn_new_state(pstn_t *pstn, enum pstn_state state) @@ -332,11 +332,6 @@ int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char pstn->ringing_type_hold = ringing_type_hold; pstn->tones_type = tones_type; - /* create ph socket */ - rc = ph_socket_init(&pstn->ph_socket, ph_socket_rx_msg, pstn, socketname, 0); - if (rc < 0) - return rc; - /* init DTMF detector */ rc = dtmf_decode_init(&pstn->dtmf_dec, pstn, recv_dtmf, 8000, db2level(6.0), db2level(-30.0)); if (rc < 0) @@ -365,6 +360,11 @@ int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char /* bring into service */ pstn_new_state(pstn, PSTN_STATE_BLOCKED); + /* create ph socket here because we get a reply from the function call */ + rc = ph_socket_init(&pstn->ph_socket, ph_socket_rx_msg, pstn, socketname, 0); + if (rc < 0) + return rc; + return 0; } @@ -385,17 +385,6 @@ void rtp_receive(struct osmo_cc_session_codec *codec, uint8_t __attribute__((unu jitter_save(&pstn->tx_dejitter, data, len, 1, sequence, timestamp, ssrc); } - -void rtp_work(pstn_t *pstn) -{ - int i; - - for (i = 0; i < 2; i++) { - if (pstn->call[i]->cc_session) - osmo_cc_session_handle(pstn->call[i]->cc_session, pstn->call[i]); - } -} - static void dtmf_on(pstn_t *pstn) { if (pstn->dtmf_on) @@ -1722,14 +1711,13 @@ static void v5_disc_req_and_cleanup(pstn_t *pstn) v5_send(pstn, PSTN_EVENT_DISC_REQ, NULL, 0); } - /* * timeout */ -static void pstn_timeout(struct timer *timer) +static void pstn_timeout(void *data) { - pstn_t *pstn = timer->priv; + pstn_t *pstn = data; switch (pstn->timer_ident) { case TIMER_IDENT_DIALING: @@ -1781,12 +1769,3 @@ static void pstn_timeout(struct timer *timer) } } -/* - * work - */ - -void pstn_work(pstn_t *pstn) -{ - ph_socket_work(&pstn->ph_socket); -} - diff --git a/src/pstn/pstn.h b/src/pstn/pstn.h index 9b79db5..4107328 100644 --- a/src/pstn/pstn.h +++ b/src/pstn/pstn.h @@ -1,5 +1,6 @@ #include "../libtimer/timer.h" +#include "../libselect/select.h" #include "../libosmocc/endpoint.h" #include "../libsample/sample.h" #include "../libjitter/jitter.h" @@ -157,5 +158,4 @@ pstn_t *pstn_create(void); int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char **subscribers, int subscriber_num, uint8_t serving_location, int tx_delay, enum pstn_cid_method clip, int cid_bell, int cid_dtmf, int clip_date, int enblock, int recall, int *ringing_types_incoming, int ringing_type_hold, enum tones_type tones_type, char law); void cc_message(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg); void rtp_work(pstn_t *pstn_ep); -void pstn_work(pstn_t *pstn_ep);