diff --git a/NextcloudTalk/AppDelegate.m b/NextcloudTalk/AppDelegate.m index cdd85b67d..21fe6400a 100644 --- a/NextcloudTalk/AppDelegate.m +++ b/NextcloudTalk/AppDelegate.m @@ -52,6 +52,7 @@ @interface AppDelegate () @property (nonatomic, strong) BGTaskHelper *keepAliveBGTask; @property (nonatomic, strong) UILabel *debugLabel; @property (nonatomic, strong) NSTimer *debugLabelTimer; +@property (nonatomic, strong) NSTimer *fileDescriptorTimer; @end @@ -107,6 +108,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( }]; } + // Comment out the following code to log the number of open socket file descriptors + /* + self.fileDescriptorTimer = [NSTimer scheduledTimerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) { + [[WebRTCCommon shared] printNumberOfOpenSocketDescriptors]; + }]; + */ + // When we include VLCKit we need to manually call this because otherwise, device rotation might not work [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; @@ -167,6 +175,8 @@ - (void)applicationWillTerminate:(UIApplication *)application // Invalidate a potentially existing label timer [self.debugLabelTimer invalidate]; + + [self.fileDescriptorTimer invalidate]; } - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options diff --git a/NextcloudTalk/WebRTCCommon.swift b/NextcloudTalk/WebRTCCommon.swift index 427d8c56f..92f657577 100644 --- a/NextcloudTalk/WebRTCCommon.swift +++ b/NextcloudTalk/WebRTCCommon.swift @@ -51,4 +51,27 @@ import Foundation public func assertQueue() { dispatchPrecondition(condition: .onQueue(webrtcClientDispatchQueue)) } + + public func printNumberOfOpenSocketDescriptors() { + print("File descriptors: \(self.openFilePaths().filter { $0 == "?" }.count)") + } + + private func openFilePaths() -> [String] { + // from https://developer.apple.com/forums/thread/655225?answerId=623114022#623114022 + (0..= 0 else { + return "" + } + // Return "?" for file descriptors not associated with a path, for + // example, a socket. + var path = [CChar](repeating: 0, count: Int(MAXPATHLEN)) + guard fcntl(fd, F_GETPATH, &path) >= 0 else { + return "?" + } + + return String(cString: path) + } + } }