Skip to content

Commit

Permalink
fix(ObjC): fix multiple issues on close conn
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Dec 13, 2018
1 parent 11d4e85 commit 9f17286
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
5 changes: 4 additions & 1 deletion core/network/ble/ble.m
Expand Up @@ -58,7 +58,10 @@ void init() {
}

void addService() {
[peripheralManager addService:[BertyUtils sharedUtils].bertyService];
if ([BertyUtils sharedUtils].serviceAdded == NO) {
[BertyUtils sharedUtils].serviceAdded = YES;
[peripheralManager addService:[BertyUtils sharedUtils].bertyService];
}
}

void setMa(char *ma) {
Expand Down
8 changes: 0 additions & 8 deletions core/network/ble/conn.go
Expand Up @@ -84,14 +84,6 @@ func BytesToConn(bleUUID string, b []byte) {
}

func ConnClosed(bleUUID string) {
if conn, ok := getConn(bleUUID); ok {
conns.Delete(bleUUID)
conn.closed = true
conn.sess.Close()
}
}

func ConnClose(bleUUID string) {
if conn, ok := getConn(bleUUID); ok {
conns.Delete(bleUUID)
conn.sess.Close()
Expand Down
15 changes: 6 additions & 9 deletions core/network/ble/darwin.go
Expand Up @@ -35,12 +35,6 @@ func setConnClosed(bleUUID *C.char) {
ConnClosed(goBleUUID)
}

//export callConnClose
func callConnClose(bleUUID *C.char) {
goBleUUID := C.GoString(bleUUID)
ConnClose(goBleUUID)
}

func (b *Conn) IsClosed() bool {
val, err := b.rAddr.ValueForProtocol(PBle)
if err != nil {
Expand All @@ -54,9 +48,11 @@ func (b *Conn) IsClosed() bool {
}

func (b *Conn) Close() error {
logger().Debug("BLEConn Close")
b.closed = true
close(b.closer)
logger().Debug("BLEConn Close", zap.Bool("CLOSED ", b.closed))
if (b.closed != true) {
close(b.closer)
b.closed = true
}
_, err := b.rAddr.ValueForProtocol(PBle)
if err != nil {
logger().Debug("BLEConn close", zap.Error(err))
Expand Down Expand Up @@ -177,6 +173,7 @@ func (t *Transport) Dial(ctx context.Context, rAddr ma.Multiaddr, p peer.ID) (tp

if conn, ok := getConn(s); ok {
conn.closed = false
conn.closer = make(chan struct{})
return conn, nil
}
c := NewConn(t, t.MySelf.ID(), p, t.lAddr, rAddr, 0)
Expand Down
1 change: 1 addition & 0 deletions core/network/ble/java.go
Expand Up @@ -36,6 +36,7 @@ func (t *Transport) Dial(ctx context.Context, rAddr ma.Multiaddr, p peer.ID) (tp

if conn, ok := getConn(s); ok {
conn.closed = false
conn.closer = make(chan struct{})
return conn, nil
}
c := NewConn(t, t.MySelf.ID(), p, t.lAddr, rAddr, 0)
Expand Down

0 comments on commit 9f17286

Please sign in to comment.