Run CLANGFORMAT on FlipperKit folder

Summary:
This diff runs CLANGFORMAT lint on FlipperKit. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT.
Ran `arc lint -a --paths-cmd "find ./iOS/FlipperKit -type f" --verbose`

Reviewed By: passy

Differential Revision: D19942170

fbshipit-source-id: af677323af4edb761f61f8f7e289cab743aa31f2
This commit is contained in:
Pritesh Nandgaonkar
2020-02-17 10:46:43 -08:00
committed by Facebook Github Bot
parent 127eec5fa1
commit ca513cf370
21 changed files with 510 additions and 360 deletions

View File

@@ -14,26 +14,27 @@
#import "FKPortForwardingCommon.h"
@interface FKPortForwardingServer () <PTChannelDelegate, GCDAsyncSocketDelegate>
{
__weak PTChannel *_serverChannel;
__weak PTChannel *_peerChannel;
@interface FKPortForwardingServer ()<
PTChannelDelegate,
GCDAsyncSocketDelegate> {
__weak PTChannel* _serverChannel;
__weak PTChannel* _peerChannel;
GCDAsyncSocket *_serverSocket;
NSMutableDictionary *_clientSockets;
GCDAsyncSocket* _serverSocket;
NSMutableDictionary* _clientSockets;
UInt32 _lastClientSocketTag;
dispatch_queue_t _socketQueue;
PTProtocol *_protocol;
PTProtocol* _protocol;
}
@end
@implementation FKPortForwardingServer
- (instancetype)init
{
- (instancetype)init {
if (self = [super init]) {
_socketQueue = dispatch_queue_create("FKPortForwardingServer", DISPATCH_QUEUE_SERIAL);
_socketQueue =
dispatch_queue_create("FKPortForwardingServer", DISPATCH_QUEUE_SERIAL);
_lastClientSocketTag = 0;
_clientSockets = [NSMutableDictionary dictionary];
_protocol = [[PTProtocol alloc] initWithDispatchQueue:_socketQueue];
@@ -41,24 +42,27 @@
return self;
}
- (void)dealloc
{
- (void)dealloc {
[self close];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)forwardConnectionsFromPort:(NSUInteger)port
{
- (void)forwardConnectionsFromPort:(NSUInteger)port {
[self _forwardConnectionsFromPort:port reportError:YES];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[self _forwardConnectionsFromPort:port reportError:NO];
}];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil
queue:nil
usingBlock:^(NSNotification* note) {
[self _forwardConnectionsFromPort:port reportError:NO];
}];
}
- (void)_forwardConnectionsFromPort:(NSUInteger)port reportError:(BOOL)shouldReportError
{
GCDAsyncSocket *serverSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_socketQueue];
NSError *listenError;
- (void)_forwardConnectionsFromPort:(NSUInteger)port
reportError:(BOOL)shouldReportError {
GCDAsyncSocket* serverSocket =
[[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_socketQueue];
NSError* listenError;
if ([serverSocket acceptOnPort:port error:&listenError]) {
_serverSocket = serverSocket;
} else {
@@ -68,31 +72,40 @@
}
}
- (void)listenForMultiplexingChannelOnPort:(NSUInteger)port
{
- (void)listenForMultiplexingChannelOnPort:(NSUInteger)port {
[self _listenForMultiplexingChannelOnPort:port reportError:YES];
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
[self _listenForMultiplexingChannelOnPort:port reportError:NO];
}];
[[NSNotificationCenter defaultCenter]
addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil
queue:nil
usingBlock:^(NSNotification* note) {
[self _listenForMultiplexingChannelOnPort:port reportError:NO];
}];
}
- (void)_listenForMultiplexingChannelOnPort:(NSUInteger)port reportError:(BOOL)shouldReportError
{
PTChannel *channel = [[PTChannel alloc] initWithProtocol:_protocol delegate:self];
[channel listenOnPort:port IPv4Address:INADDR_LOOPBACK callback:^(NSError *error) {
if (error) {
if (shouldReportError) {
FBPFLog(@"Failed to listen on 127.0.0.1:%lu: %@", (unsigned long)port, error);
}
} else {
FBPFTrace(@"Listening on 127.0.0.1:%lu", (unsigned long)port);
self->_serverChannel = channel;
}
}];
- (void)_listenForMultiplexingChannelOnPort:(NSUInteger)port
reportError:(BOOL)shouldReportError {
PTChannel* channel = [[PTChannel alloc] initWithProtocol:_protocol
delegate:self];
[channel
listenOnPort:port
IPv4Address:INADDR_LOOPBACK
callback:^(NSError* error) {
if (error) {
if (shouldReportError) {
FBPFLog(
@"Failed to listen on 127.0.0.1:%lu: %@",
(unsigned long)port,
error);
}
} else {
FBPFTrace(@"Listening on 127.0.0.1:%lu", (unsigned long)port);
self->_serverChannel = channel;
}
}];
}
- (void)close
{
- (void)close {
if (_serverChannel) {
[_serverChannel close];
_serverChannel = nil;
@@ -102,7 +115,9 @@
#pragma mark - PTChannelDelegate
- (void)ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)otherChannel fromAddress:(PTAddress *)address {
- (void)ioFrameChannel:(PTChannel*)channel
didAcceptConnection:(PTChannel*)otherChannel
fromAddress:(PTAddress*)address {
// Cancel any other connection. We are FIFO, so the last connection
// established will cancel any previous connection and "take its place".
if (_peerChannel) {
@@ -116,22 +131,27 @@
FBPFTrace(@"Connected to %@", address);
}
- (void)ioFrameChannel:(PTChannel *)channel didReceiveFrameOfType:(uint32_t)type tag:(uint32_t)tag payload:(PTData *)payload {
//NSLog(@"didReceiveFrameOfType: %u, %u, %@", type, tag, payload);
- (void)ioFrameChannel:(PTChannel*)channel
didReceiveFrameOfType:(uint32_t)type
tag:(uint32_t)tag
payload:(PTData*)payload {
// NSLog(@"didReceiveFrameOfType: %u, %u, %@", type, tag, payload);
if (type == FKPortForwardingFrameTypeWriteToPipe) {
GCDAsyncSocket *sock = _clientSockets[@(tag)];
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length] withTimeout:-1 tag:0];
GCDAsyncSocket* sock = _clientSockets[@(tag)];
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length]
withTimeout:-1
tag:0];
FBPFTrace(@"channel -> socket (%d), %zu bytes", tag, payload.length);
}
if (type == FKPortForwardingFrameTypeClosePipe) {
GCDAsyncSocket *sock = _clientSockets[@(tag)];
GCDAsyncSocket* sock = _clientSockets[@(tag)];
[sock disconnectAfterWriting];
}
}
- (void)ioFrameChannel:(PTChannel *)channel didEndWithError:(NSError *)error {
for (GCDAsyncSocket *sock in [_clientSockets objectEnumerator]) {
- (void)ioFrameChannel:(PTChannel*)channel didEndWithError:(NSError*)error {
for (GCDAsyncSocket* sock in [_clientSockets objectEnumerator]) {
[sock setDelegate:nil];
[sock disconnect];
}
@@ -139,11 +159,10 @@
FBPFTrace(@"Disconnected from %@, error = %@", channel.userInfo, error);
}
#pragma mark - GCDAsyncSocketDelegate
- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
{
- (void)socket:(GCDAsyncSocket*)sock
didAcceptNewSocket:(GCDAsyncSocket*)newSocket {
dispatch_block_t block = ^() {
if (!self->_peerChannel) {
[newSocket setDelegate:nil];
@@ -154,37 +173,60 @@
newSocket.userData = @(tag);
newSocket.delegate = self;
self->_clientSockets[@(tag)] = newSocket;
[self->_peerChannel sendFrameOfType:FKPortForwardingFrameTypeOpenPipe tag:self->_lastClientSocketTag withPayload:nil callback:^(NSError *error) {
FBPFTrace(@"open socket (%d), error = %@", (unsigned int)tag, error);
[newSocket readDataWithTimeout:-1 tag:0];
}];
[self->_peerChannel
sendFrameOfType:FKPortForwardingFrameTypeOpenPipe
tag:self->_lastClientSocketTag
withPayload:nil
callback:^(NSError* error) {
FBPFTrace(
@"open socket (%d), error = %@", (unsigned int)tag, error);
[newSocket readDataWithTimeout:-1 tag:0];
}];
};
if (_peerChannel) {
block();
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), _socketQueue, block);
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
_socketQueue,
block);
}
}
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)_
{
- (void)socket:(GCDAsyncSocket*)sock didReadData:(NSData*)data withTag:(long)_ {
UInt32 tag = [[sock userData] unsignedIntValue];
FBPFTrace(@"Incoming data on socket (%d) - %lu bytes", (unsigned int)tag, (unsigned long)data.length);
[_peerChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe tag:tag withPayload:NSDataToGCDData(data) callback:^(NSError *error) {
FBPFTrace(@"socket (%d) -> channel %lu bytes, error = %@", (unsigned int)tag, (unsigned long)data.length, error);
[sock readDataWithTimeout:-1 tag:_];
}];
FBPFTrace(
@"Incoming data on socket (%d) - %lu bytes",
(unsigned int)tag,
(unsigned long)data.length);
[_peerChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe
tag:tag
withPayload:NSDataToGCDData(data)
callback:^(NSError* error) {
FBPFTrace(
@"socket (%d) -> channel %lu bytes, error = %@",
(unsigned int)tag,
(unsigned long)data.length,
error);
[sock readDataWithTimeout:-1 tag:_];
}];
}
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
{
- (void)socketDidDisconnect:(GCDAsyncSocket*)sock withError:(NSError*)err {
UInt32 tag = [sock.userData unsignedIntValue];
[_clientSockets removeObjectForKey:@(tag)];
[_peerChannel sendFrameOfType:FKPortForwardingFrameTypeClosePipe tag:tag withPayload:nil callback:^(NSError *error) {
FBPFTrace(@"socket (%d) disconnected, err = %@, peer error = %@", (unsigned int)tag, err, error);
}];
[_peerChannel
sendFrameOfType:FKPortForwardingFrameTypeClosePipe
tag:tag
withPayload:nil
callback:^(NSError* error) {
FBPFTrace(
@"socket (%d) disconnected, err = %@, peer error = %@",
(unsigned int)tag,
err,
error);
}];
}
@end