Skip to content

Commit 0c697f4

Browse files
author
Ari Parkkila
committed
Cellular: Fix sigio to be released in ATHandler destructor
1 parent 883b8b8 commit 0c697f4

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,6 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
328328
filehandle_stub_table = NULL;
329329
}
330330

331-
TEST_F(TestATHandler, test_ATHandler_set_filehandle_sigio)
332-
{
333-
EventQueue que;
334-
FileHandle_stub fh1;
335-
336-
ATHandler at(&fh1, que, 0, ",");
337-
at.set_filehandle_sigio();
338-
}
339-
340331
TEST_F(TestATHandler, test_ATHandler_flush)
341332
{
342333
EventQueue que;

UNITTESTS/stubs/FileHandle_stub.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class FileHandle_stub : public FileHandle {
8080

8181
virtual void sigio(Callback<void()> func)
8282
{
83-
func();
83+
if (func) {
84+
func();
85+
}
8486
}
8587

8688
short short_value;

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static const uint8_t map_3gpp_errors[][2] = {
6262

6363
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
6464
_nextATHandler(0),
65-
_fileHandle(fh),
65+
_fileHandle(NULL), // filehandle is set by set_file_handle()
6666
_queue(queue),
6767
_last_err(NSAPI_ERROR_OK),
6868
_last_3gpp_error(0),
@@ -74,7 +74,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
7474
_last_response_stop(0),
7575
_oob_queued(false),
7676
_ref_count(1),
77-
_is_fh_usable(true),
77+
_is_fh_usable(false),
7878
_stop_tag(NULL),
7979
_delimiter(DEFAULT_DELIMITER),
8080
_prefix_matched(false),
@@ -114,6 +114,8 @@ void ATHandler::set_debug(bool debug_on)
114114

115115
ATHandler::~ATHandler()
116116
{
117+
set_file_handle(NULL);
118+
117119
while (_oobs) {
118120
struct oob_t *oob = _oobs;
119121
_oobs = oob->next;
@@ -146,17 +148,26 @@ FileHandle *ATHandler::get_file_handle()
146148

147149
void ATHandler::set_file_handle(FileHandle *fh)
148150
{
151+
if (_fileHandle) {
152+
set_is_filehandle_usable(false);
153+
}
149154
_fileHandle = fh;
150-
_fileHandle->set_blocking(false);
151-
set_filehandle_sigio();
155+
if (_fileHandle) {
156+
set_is_filehandle_usable(true);
157+
}
152158
}
153159

154160
void ATHandler::set_is_filehandle_usable(bool usable)
155161
{
156-
_is_fh_usable = usable;
157-
if (usable) {
158-
// set file handle sigio and blocking mode back
159-
set_file_handle(_fileHandle);
162+
if (_fileHandle) {
163+
if (usable) {
164+
_fileHandle->set_blocking(false);
165+
_fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
166+
} else {
167+
_fileHandle->set_blocking(true); // set back to default state
168+
_fileHandle->sigio(NULL);
169+
}
170+
_is_fh_usable = usable;
160171
}
161172
}
162173

@@ -308,11 +319,6 @@ void ATHandler::process_oob()
308319
unlock();
309320
}
310321

311-
void ATHandler::set_filehandle_sigio()
312-
{
313-
_fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
314-
}
315-
316322
void ATHandler::reset_buffer()
317323
{
318324
_recv_pos = 0;

features/cellular/framework/AT/ATHandler.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ class ATHandler {
190190
*/
191191
void process_oob();
192192

193-
/** Set sigio for the current file handle. Sigio event goes through eventqueue so that it's handled in current thread.
194-
*/
195-
void set_filehandle_sigio();
196-
197193
/** Set file handle, which is used for reading AT responses and writing AT commands
198194
*
199195
* @param fh file handle used for reading AT responses and writing AT commands

0 commit comments

Comments
 (0)