diff --git a/features/cellular/framework/mux/cellular_mux.cpp b/features/cellular/framework/mux/cellular_mux.cpp index d419aa7aa7..3d32cf92cf 100644 --- a/features/cellular/framework/mux/cellular_mux.cpp +++ b/features/cellular/framework/mux/cellular_mux.cpp @@ -1238,4 +1238,16 @@ ssize_t Mux::user_data_rx(void* buffer, size_t size) } +short Mux::poll() +{ + _mutex.lock(); + + const bool writable = (_tx_context.tx_state == TX_IDLE); + const bool readable = (_rx_context.rx_state == RX_SUSPEND); + + _mutex.unlock(); + + return ((readable ? POLLIN : 0) | (writable ? POLLOUT : 0)); +} + } // namespace mbed diff --git a/features/cellular/framework/mux/cellular_mux.h b/features/cellular/framework/mux/cellular_mux.h index 273b5771d9..1bfeef6754 100644 --- a/features/cellular/framework/mux/cellular_mux.h +++ b/features/cellular/framework/mux/cellular_mux.h @@ -72,6 +72,18 @@ public: */ virtual ssize_t read(void *buffer, size_t size); + /** Check for poll event flags + * + * The input parameter can be used or ignored - could always return all events, or could check just the events + * listed in events. + * + * Call is non-blocking - returns instantaneous state of events. + * + * @param events Bitmask of poll events we're interested in - POLLIN/POLLOUT etc. + * @return Bitmask of poll events that have occurred. + */ + virtual short poll(short events) const; + /** Not supported by the implementation. */ virtual off_t seek(off_t offset, int whence = SEEK_SET); @@ -434,6 +446,12 @@ private: */ static ssize_t user_data_rx(void* buffer, size_t size); + /** Check for poll event flags + * + * @return Bitmask of poll events that have occurred - POLLIN/POLLOUT. + */ + static short poll(); + /** Clear TX callback pending bit. * * @param bit Bit to clear. diff --git a/features/cellular/framework/mux/cellular_mux_data_service.cpp b/features/cellular/framework/mux/cellular_mux_data_service.cpp index 915779fd91..3a381881f8 100644 --- a/features/cellular/framework/mux/cellular_mux_data_service.cpp +++ b/features/cellular/framework/mux/cellular_mux_data_service.cpp @@ -31,6 +31,12 @@ ssize_t MuxDataService::read(void *buffer, size_t size) } +short MuxDataService::poll(short events) const +{ + return Mux::poll(); +} + + off_t MuxDataService::seek(off_t offset, int whence) { MBED_ASSERT(false);