You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/08/21 21:12:59 UTC

[mynewt-newtmgr] 01/02: nmxact - Send CoAP responses in Go routine.

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git

commit 22a29a4fb8780ff322ca32f4b87852aa7b6c9e20
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Aug 21 14:08:53 2017 -0700

    nmxact - Send CoAP responses in Go routine.
    
    This unblocks blehostd while nmxact is generating its CoAP response.
    Prior to this change, the host is waiting for an ATT error code to send
    in response to the incoming characteristic write.  Now, nmxact
    immediately indicates an error code of 0, and the notification
    containing the CoAP response gets sent later.
---
 nmxact/nmble/ble_oic_svr.go | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/nmxact/nmble/ble_oic_svr.go b/nmxact/nmble/ble_oic_svr.go
index c0c6d9f..9cdbed3 100644
--- a/nmxact/nmble/ble_oic_svr.go
+++ b/nmxact/nmble/ble_oic_svr.go
@@ -30,31 +30,31 @@ func (b *BleOicSvr) AddResource(r oic.Resource) error {
 	return b.s.AddResource(r)
 }
 
-func (b *BleOicSvr) Rx(access BleGattAccess) uint8 {
+func (b *BleOicSvr) processCoap(access BleGattAccess) {
+	s := b.x.findSesn(access.ConnHandle)
+	if s == nil {
+		// The sender is no longer connected.
+		log.Debugf("Failed to send CoAP response; peer no longer "+
+			"connected (conn_handle=%d)", access.ConnHandle)
+		return
+	}
+
 	ml, err := b.s.Rx(access.Data)
 	if err != nil {
 		log.Debugf("Error processing incoming CoAP message: %s", err.Error())
-		return 0
+		return
 	}
 
 	if ml == nil {
 		// Partial CoAP message; remainder forthcoming.
-		return 0
-	}
-
-	s := b.x.findSesn(access.ConnHandle)
-	if s == nil {
-		// The sender is no longer connected.
-		log.Debugf("Failed to send CoAP response; peer no longer "+
-			"connected (conn_handle=%d)", access.ConnHandle)
-		return ERR_CODE_ATT_UNLIKELY
+		return
 	}
 
 	data, err := ml.MarshalBinary()
 	if err != nil {
 		log.Debugf("Failed to send CoAP response; error marshalling "+
 			"response: %s", err.Error())
-		return ERR_CODE_ATT_UNLIKELY
+		return
 	}
 
 	_, valHandle, err := FindChrXact(b.x, b.rspSvcUuid, b.rspChrUuid)
@@ -62,20 +62,27 @@ func (b *BleOicSvr) Rx(access BleGattAccess) uint8 {
 		log.Debugf("Failed to send CoAP response; cannot find response "+
 			"characteristic: (s=%s c=%s)",
 			b.rspSvcUuid.String(), b.rspChrUuid.String())
-		return ERR_CODE_ATT_UNLIKELY
+		return
 	}
 
 	mtu := s.MtuOut()
 	frags := nmxutil.Fragment(data, mtu)
-	for _, frag := range frags {
+	for i, frag := range frags {
 		if err := NotifyXact(b.x, access.ConnHandle, valHandle,
 			frag); err != nil {
 
 			log.Debugf("Failed to send CoAP response; failed to send "+
-				"fragment: %s", err.Error())
-			return ERR_CODE_ATT_UNLIKELY
+				"fragment %d/%d: %s", err.Error(), i, len(frags))
+			return
 		}
 	}
+}
+
+func (b *BleOicSvr) Rx(access BleGattAccess) uint8 {
+	// Process the CoAP request and send a response via notification in the
+	// background.
+	go b.processCoap(access)
 
+	// Indicate success to BLE server.
 	return 0
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@mynewt.apache.org" <co...@mynewt.apache.org>.