6 years ago.

Using TCPSocket::sigio member function to register callback

I am trying to use TCPSocket::sigio member function to register callback and trying to access socket.connect inside the callback. When executed it is giving assert failed. mbed assertation failed: _ptr == (T *)&_data, file: ./mbed-os/platform/SingletonPtr.h, line 10

TCPSocket socket; EventFlags completed;

void main() { socket.open(&wifi); EventQueue *queue = mbed_event_queue();

Event<void()> handler = queue->event(handle_socket_sigio);

socket.set_blocking(false); socket.sigio(handler); handler(); Kick the state machine to start connecting

completed.wait_any(1); }

void handle_socket_sigio() { static enum { CONNECTING, SEND, RECEIVE, CLOSE, } next_state = CONNECTING; printf("socket callback called...\r\n"); socket>close(); switch (next_state) { case CONNECTING: switch(socket.connect("10.1.30.17", 5060)) { case NSAPI_ERROR_IN_PROGRESS: printf("connecting to server...\r\n"); /* Connecting to server*/ break; case NSAPI_ERROR_ALREADY: printf("connected..send data\r\n"); /* Now connected to server*/ next_state = SEND; break; default: printf("error in connecting..\r\n"); /* Error in connection phase*/ next_state = CLOSE; } case SEND: if (send_query() > 0){ printf("receive\r\n"); next_state = RECEIVE;} else { printf("close in send\r\n"); next_state = CLOSE; Error } break; case RECEIVE: if (receive_data() == NSAPI_ERROR_WOULD_BLOCK) break; printf("close in receive\r\n"); next_state = CLOSE; break; case CLOSE: printf("close in close\r\n"); socket.close(); completed.set(1); /* Signal the main thread*/ break; } }

Be the first to answer this question.