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 2019/03/22 19:43:48 UTC

[mynewt-newtmgr] branch master updated: nmserial: Don't attempt to open serial port twice

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


The following commit(s) were added to refs/heads/master by this push:
     new 67dcd52  nmserial: Don't attempt to open serial port twice
     new af9044f  Merge pull request #116 from ccollins476ad/nmserial-open
67dcd52 is described below

commit 67dcd521ad7213e426ea0b56306934497fa13efd
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Fri Mar 22 12:23:06 2019 -0700

    nmserial: Don't attempt to open serial port twice
    
    If the port is already open, a second attempt is now a no-op.
---
 nmxact/nmserial/serial_xport.go | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/nmxact/nmserial/serial_xport.go b/nmxact/nmserial/serial_xport.go
index 62bdfc1..261e088 100644
--- a/nmxact/nmserial/serial_xport.go
+++ b/nmxact/nmserial/serial_xport.go
@@ -101,6 +101,11 @@ func (sx *SerialXport) acceptServerSesn(sl *SerialSesn) (*SerialSesn, error) {
 }
 
 func (sx *SerialXport) Start() error {
+	if sx.port != nil {
+		// Already started.
+		return nil
+	}
+
 	c := &serial.Config{
 		Name:        sx.cfg.DevPath,
 		Baud:        sx.cfg.Baud,
@@ -221,7 +226,12 @@ func (sx *SerialXport) Stop() error {
 	err := sx.port.Close()
 	sx.wg.Wait()
 
+	if err == nil {
+		sx.port = nil
+	}
+
 	sx.closing = false
+
 	return err
 }