Commit 731710e9 authored by Josh Lubawy's avatar Josh Lubawy Committed by Kevin
Browse files

Add Conn method to Client interface (#26)

* Add ability to get RxMTU from a connection

* Fix race detector warning

* Fix compiler error
parent 11b1dad1
......@@ -66,4 +66,7 @@ type Client interface {
// Disconnected returns a receiving channel, which is closed when the client disconnects.
Disconnected() <-chan struct{}
// Conn returns the client's current connection.
Conn() Conn
}
......@@ -320,6 +320,11 @@ func (cln *Client) Disconnected() <-chan struct{} {
return cln.conn.Disconnected()
}
// Conn returns the client's current connection.
func (cln *Client) Conn() ble.Conn {
return cln.conn
}
type sub struct {
fn ble.NotificationHandler
char *ble.Characteristic
......
......@@ -9,10 +9,10 @@ import (
"github.com/raff/goble/xpc"
)
func newConn(d *Device, a ble.Addr) *conn {
func newConn(d *Device, a ble.Addr, rxMTU int) *conn {
return &conn{
dev: d,
rxMTU: 23,
rxMTU: rxMTU,
txMTU: 23,
addr: a,
done: make(chan struct{}),
......@@ -77,7 +77,9 @@ func (c *conn) TxMTU() int {
}
func (c *conn) SetTxMTU(mtu int) {
c.Lock()
c.txMTU = mtu
c.Unlock()
}
func (c *conn) Read(b []byte) (int, error) {
......
......@@ -546,7 +546,7 @@ func (d *Device) conn(m msg) *conn {
d.connLock.Lock()
c, ok := d.conns[a.String()]
if !ok {
c = newConn(d, a)
c = newConn(d, a, m.attMTU())
d.conns[a.String()] = c
}
d.connLock.Unlock()
......
......@@ -371,6 +371,11 @@ func (p *Client) Disconnected() <-chan struct{} {
return p.conn.Disconnected()
}
// Conn returns the client's current connection.
func (p *Client) Conn() ble.Conn {
return p.conn
}
// HandleNotification ...
func (p *Client) HandleNotification(req []byte) {
p.Lock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment