예제 #1
0
smcp_status_t smcp_outbound_begin_response(coap_code_t code) {
	smcp_status_t ret = SMCP_STATUS_OK;
	smcp_t const self = smcp_get_current_instance();

	require_action_string(!self->did_respond,
		bail,
		ret = SMCP_STATUS_RESPONSE_NOT_ALLOWED,
		"Attempted to send more than one response!"
	);

	// If we have already started responding, don't bother.
	require(!self->is_responding,bail);

	if(self->is_processing_message)
		self->outbound.next_tid = smcp_inbound_get_msg_id();
	smcp_outbound_begin(self,code,(self->inbound.packet->tt==COAP_TRANS_TYPE_NONCONFIRMABLE)?COAP_TRANS_TYPE_NONCONFIRMABLE:COAP_TRANS_TYPE_ACK);
	self->is_responding = true;

	if(self->is_processing_message)
		smcp_outbound_set_msg_id(smcp_inbound_get_msg_id());

	if(self->is_processing_message) {
#if SMCP_USE_BSD_SOCKETS
		ret = smcp_outbound_set_destaddr(
			self->inbound.saddr,
			self->inbound.socklen
		);
#elif CONTIKI
		ret = smcp_outbound_set_destaddr(
			&self->inbound.toaddr,
			self->inbound.toport
		);
#endif
		require_noerr(ret, bail);
	}
bail:
	return ret;
}
예제 #2
0
smcp_status_t smcp_outbound_begin_response(coap_code_t code) {
	smcp_status_t ret;
	smcp_t const self = smcp_get_current_instance();

	ret = SMCP_STATUS_OK;

	require_action_string(!self->did_respond,
		bail,
		ret = SMCP_STATUS_RESPONSE_NOT_ALLOWED,
		"Attempted to send more than one response!"
	);

	// If we have already started responding, don't bother.
	require_quiet(!self->is_responding, bail);

	if (self->is_processing_message) {
		self->outbound.next_tid = smcp_inbound_get_msg_id();
	}

	ret = smcp_outbound_begin(
		self,
		code,
		(self->inbound.packet->tt==COAP_TRANS_TYPE_NONCONFIRMABLE)?COAP_TRANS_TYPE_NONCONFIRMABLE:COAP_TRANS_TYPE_ACK
	);
	require_noerr(ret, bail);

	self->is_responding = true;

	if (self->is_processing_message) {
		require_noerr(ret=smcp_outbound_set_msg_id(smcp_inbound_get_msg_id()),bail);
	}
bail:
	if (ret != SMCP_STATUS_OK) {
		self->is_responding = false;
	}
	return ret;
}