Skip to content

Commit

Permalink
Assign MID before register observation.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@bosch-si.com>
  • Loading branch information
Achim Kraus committed Oct 3, 2018
1 parent e9953f5 commit 35cc5a6
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* Achim Kraus (Bosch Software Innovations GmbH) - change ExchangeObserver
* to RemoveHandler
* remove "is last", not longer meaningful
* Achim Kraus (Bosch Software Innovations GmbH) - assign mid before register observation
******************************************************************************/
package org.eclipse.californium.core.network;

Expand Down Expand Up @@ -112,7 +113,13 @@ public void sendRequest(final Exchange exchange) {
// for observe request.
Request request = exchange.getCurrentRequest();
if (request.isObserve() && 0 == exchange.getFailedTransmissionCount()) {
registerObserve(request);
if (exchangeStore.assignMessageId(request) != Message.NONE) {
registerObserve(request);
} else {
LOGGER.warn("message IDs exhausted, could not register outbound observe request for tracking");
request.setSendError(new IllegalStateException("automatic message IDs exhausted"));
return;
}
}

try {
Expand Down Expand Up @@ -255,7 +262,7 @@ public Exchange receiveResponse(final Response response) {
EndpointContext context = exchange.getEndpointContext();
Request currentRequest = exchange.getCurrentRequest();
int requestMid = currentRequest.getMID();
if (context == null || requestMid == Message.NONE) {
if (context == null) {
LOGGER.debug("ignoring response {}, request pending to sent!", response);
return null;
}
Expand Down

0 comments on commit 35cc5a6

Please sign in to comment.