Repository: incubator-mynewt-newt Updated Branches: refs/heads/master 25d87344e -> ca783a7dd
unixchild - fail rather than hang if not rdy to tx Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/ca783a7d Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/ca783a7d Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/ca783a7d Branch: refs/heads/master Commit: ca783a7dd6f58cae1ef129d1c212e1f1eda2f877 Parents: 25d8734 Author: Christopher Collins <ccoll...@apache.org> Authored: Wed May 10 18:20:43 2017 -0700 Committer: Christopher Collins <ccoll...@apache.org> Committed: Wed May 10 18:20:43 2017 -0700 ---------------------------------------------------------------------- util/unixchild/unixchild.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/ca783a7d/util/unixchild/unixchild.go ---------------------------------------------------------------------- diff --git a/util/unixchild/unixchild.go b/util/unixchild/unixchild.go index 91930c0..3474424 100644 --- a/util/unixchild/unixchild.go +++ b/util/unixchild/unixchild.go @@ -72,8 +72,8 @@ const ( type Client struct { FromChild chan []byte - ToChild chan []byte ErrChild chan error + toChild chan []byte childPath string sockPath string childArgs []string @@ -91,8 +91,8 @@ func New(conf Config) *Client { childArgs: conf.ChildArgs, maxMsgSz: conf.MaxMsgSz, FromChild: make(chan []byte, conf.Depth), - ToChild: make(chan []byte, conf.Depth), ErrChild: make(chan error), + toChild: make(chan []byte, conf.Depth), acceptTimeout: conf.AcceptTimeout, stop: make(chan bool), stopped: make(chan bool), @@ -181,7 +181,7 @@ func (c *Client) handleChild(con net.Conn) { defer wg.Done() for { select { - case buf := <-c.ToChild: + case buf := <-c.toChild: mlen := uint16(len(buf)) err := binary.Write(con, binary.BigEndian, mlen) if err != nil { @@ -290,3 +290,12 @@ func (c *Client) Start() error { return nil } + +func (c *Client) TxToChild(data []byte) error { + if c.state != CLIENT_STATE_STARTED { + return fmt.Errorf("transmit over unixchild before it is fully started") + } + + c.toChild <- data + return nil +}