/** * Processes one event. Retrieves the type of the event processed, or NONE if no event processed. * If an error occurs, the event type is undefined. */ ProtocolError Protocol::event_loop(CoAPMessageType::Enum& message_type) { Message message; message_type = CoAPMessageType::NONE; ProtocolError error = channel.receive(message); if (!error) { if (message.length()) { error = handle_received_message(message, message_type); } else { error = event_loop_idle(); } } if (error) { // bail if and only if there was an error chunkedTransfer.cancel(); WARN("Event loop error %d", error); return error; } return error; }
int HtiStifMsg::SendReceiveMsg(struct soap* soap, int timeout) { //dump(msgBody, msgBodyLen); BYTE commandCode = msgBody[0]; // Send the message to symbian side HtiSoapHandlerInterface* handler = static_cast<HtiSoapHandlerInterface*>(soap->user); handler->SendHtiMessage(HTI_STIF_UID, msgBody, msgBodyLen); // Clean these up for received HTI message delete msgBody; msgBody = NULL; msgBodyLen = 0; while(1) { if (handler->WaitForHtiMessage(timeout)) { int err = handle_received_message(handler, TRUE); // NOTE: this will be destroyed by gateway msgBody = (BYTE*) handler->ReceivedHtiMessageBody(); msgBodyLen = handler->ReceivedHtiMessageBodySize(); // Received a HTI initiated msg // Start waiting again if( (err == HTI_RECV_ASYNC_CALL_SERVICED) || (err == HTI_RECV_ASYNC_CALL_SERVICE_ERROR) ) { continue; } if( err == HTI_RECV_ERROR_MESSAGE ) SetSoapFaultFromReceivedHtiError(soap, msgBody, msgBodyLen); return err; } else { // timeout soap->error = soap_receiver_fault(soap, "HtiGateway", "No response from symbian side"); return HTI_RECV_TIMEOUT; } } }
//********************************************************************************** // hti_serve //********************************************************************************** int hti_serve(HtiSoapHandlerInterface* handler) { return handle_received_message(handler, FALSE); }
// Returns true if no errors and still connected. // Returns false if there was an error, and we are probably disconnected. bool SparkProtocol::event_loop(void) { int bytes_received = callbacks.receive(queue, 2); if (2 <= bytes_received) { bool success = handle_received_message(); if (!success) { if (updating) { // was updating but had an error, inform the client serial_dump("handle received message failed - aborting transfer"); callbacks.finish_firmware_update(file, 0, NULL); updating = false; } // bail if and only if there was an error return false; } } else { if (0 > bytes_received) { // error, disconnected return false; } if (updating) { system_tick_t millis_since_last_chunk = callbacks.millis() - last_chunk_millis; if (3000 < millis_since_last_chunk) { if (updating==2) { // send missing chunks serial_dump("timeout - resending missing chunks"); if (!send_missing_chunks(MISSED_CHUNKS_TO_SEND)) return false; } /* Do not resend chunks since this can cause duplicates on the server. else { queue[0] = 0; queue[1] = 16; chunk_missed(queue + 2, chunk_index); if (0 > blocking_send(queue, 18)) { // error return false; } } */ last_chunk_millis = callbacks.millis(); } } else { system_tick_t millis_since_last_message = callbacks.millis() - last_message_millis; if (expecting_ping_ack) { if (10000 < millis_since_last_message) { // timed out, disconnect expecting_ping_ack = false; last_message_millis = callbacks.millis(); return false; } } else { if (15000 < millis_since_last_message) { queue[0] = 0; queue[1] = 16; ping(queue + 2); blocking_send(queue, 18); expecting_ping_ack = true; last_message_millis = callbacks.millis(); } } } } // no errors, still connected return true; }