Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hughkli committed Nov 11, 2023
1 parent 8b925e0 commit 6030404
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
9 changes: 0 additions & 9 deletions LookinDemo/OC_Pod/LookinDemoOC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ - (void)viewDidLoad {
[self.view addSubview:stackView];

stackView.frame = self.view.bounds;


NSLog(@"UIStackViewAlignmentLeading %@", @(UIStackViewAlignmentLeading));
NSLog(@"UIStackViewAlignmentTop %@", @(UIStackViewAlignmentTop));
NSLog(@"UIStackViewAlignmentFirstBaseline %@", @(UIStackViewAlignmentFirstBaseline));
NSLog(@"UIStackViewAlignmentCenter %@", @(UIStackViewAlignmentCenter));
NSLog(@"UIStackViewAlignmentTrailing %@", @(UIStackViewAlignmentTrailing));
NSLog(@"UIStackViewAlignmentBottom %@", @(UIStackViewAlignmentBottom));
NSLog(@"UIStackViewAlignmentLastBaseline %@", @(UIStackViewAlignmentLastBaseline));
}

@end
28 changes: 18 additions & 10 deletions Src/Main/Server/Connection/LKS_ConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ - (void)_handleWillResignActiveNotification {
}

- (void)_handleApplicationDidBecomeActive {
// NSLog(@"LookinServer(0.8.0) - UIApplicationDidBecomeActiveNotification");
self.applicationIsActive = YES;
if (self.peerChannel_ && (self.peerChannel_.isConnected || self.peerChannel_.isListening)) {
return;
[self tryToListenPorts];
}

- (void)tryToListenPorts {
if (self.peerChannel_) {
// 除了 connected 和 listenin 状态之外,还可能是 close 状态。如果连接了 client 端,而 client 端又关闭了,那么这里的 channel 就会变成 close
if ([self.peerChannel_ isConnected] || [self.peerChannel_ isListening]) {
// NSLog(@"LookinServer - Abort connect trying. Already has active channel.");
return;
}
}
NSLog(@"LookinServer - Trying to connect ...");
if ([self isiOSAppOnMac]) {
Expand Down Expand Up @@ -120,9 +127,6 @@ - (void)_tryToListenOnPortFrom:(int)fromPort to:(int)toPort current:(int)current
NSLog(@"LookinServer - Connected successfully on 127.0.0.1:%d", currentPort);
// 此时 peerChannel_ 状态为 listening
self.peerChannel_ = channel;

// UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@", @(currentPort)] message:nil preferredStyle:UIAlertControllerStyleAlert];
// [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}
}];
}
Expand Down Expand Up @@ -187,17 +191,21 @@ - (void)ioFrameChannel:(Lookin_PTChannel*)channel didReceiveFrameOfType:(uint32_

/// 当连接过 Lookin 客户端,然后 Lookin 客户端又被关闭时,会走到这里
- (void)ioFrameChannel:(Lookin_PTChannel*)channel didEndWithError:(NSError*)error {
// NSLog(@"LookinServer - didEndWithError:%@", channel);
[[NSNotificationCenter defaultCenter] postNotificationName:LKS_ConnectionDidEndNotificationName object:self];
[self tryToListenPorts];
}

/// 当 Client 端链接成功时,该方法会被调用,然后 channel 的状态会变成 connected
- (void)ioFrameChannel:(Lookin_PTChannel*)channel didAcceptConnection:(Lookin_PTChannel*)otherChannel fromAddress:(Lookin_PTAddress*)address {
if (self.peerChannel_) {
[self.peerChannel_ cancel];
}

// NSLog(@"LookinServer - didAcceptConnection:%@, current:%@", otherChannel, self.peerChannel_);
Lookin_PTChannel *previousChannel = self.peerChannel_;
self.peerChannel_ = otherChannel;
self.peerChannel_.userInfo = address;

if (previousChannel && previousChannel != self.peerChannel_) {
[previousChannel cancel];
}
}

#pragma mark - Handler
Expand Down
2 changes: 2 additions & 0 deletions Src/Main/Shared/Peertalk/Lookin_PTChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ - (BOOL)acceptIncomingConnection:(dispatch_fd_t)serverSocketFD {


- (void)close {
// NSLog(@"LookinServer - Channel will close: %@", self);
if ((connState_ == kConnStateConnecting || connState_ == kConnStateConnected) && dispatchObj_channel_) {
dispatch_io_close(dispatchObj_channel_, DISPATCH_IO_STOP);
[self setDispatchChannel:NULL];
Expand All @@ -434,6 +435,7 @@ - (void)close {


- (void)cancel {
// NSLog(@"LookinServer - Channel will cancel: %@", self);
if ((connState_ == kConnStateConnecting || connState_ == kConnStateConnected) && dispatchObj_channel_) {
dispatch_io_close(dispatchObj_channel_, 0);
[self setDispatchChannel:NULL];
Expand Down

0 comments on commit 6030404

Please sign in to comment.