Skip to content

Commit

Permalink
Merge pull request #1535 from nextcloud/add-optional-filedescriptor-l…
Browse files Browse the repository at this point in the history
…ogging

Add optional logging of socket file descriptors
  • Loading branch information
Ivansss authored Feb 15, 2024
2 parents 4e05f3e + c4f899c commit 722400b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions NextcloudTalk/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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<UIApplicationOpenURLOptionsKey,id> *)options
Expand Down
23 changes: 23 additions & 0 deletions NextcloudTalk/WebRTCCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<getdtablesize()).map { fd in
// Return "" for invalid file descriptors.
var flags: CInt = 0
guard fcntl(fd, F_GETFL, &flags) >= 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)
}
}
}

0 comments on commit 722400b

Please sign in to comment.