Browse Source

Removed Thread, moved code into Serial

Thomas Buck 9 years ago
parent
commit
fa409f2f03

+ 0
- 6
CaseLights.xcodeproj/project.pbxproj View File

11
 		E9109B151C2AAEFD00726111 /* SystemInfoKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = E9109B0B1C2AAC1B00726111 /* SystemInfoKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
11
 		E9109B151C2AAEFD00726111 /* SystemInfoKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = E9109B0B1C2AAC1B00726111 /* SystemInfoKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
12
 		E9109B191C2AAFE100726111 /* GPUStats.m in Sources */ = {isa = PBXBuildFile; fileRef = E9109B181C2AAFE100726111 /* GPUStats.m */; };
12
 		E9109B191C2AAFE100726111 /* GPUStats.m in Sources */ = {isa = PBXBuildFile; fileRef = E9109B181C2AAFE100726111 /* GPUStats.m */; };
13
 		E9AB18011C29F8CD00BF3C51 /* Serial.m in Sources */ = {isa = PBXBuildFile; fileRef = E9AB18001C29F8CD00BF3C51 /* Serial.m */; };
13
 		E9AB18011C29F8CD00BF3C51 /* Serial.m in Sources */ = {isa = PBXBuildFile; fileRef = E9AB18001C29F8CD00BF3C51 /* Serial.m */; };
14
-		E9AB18061C2A173500BF3C51 /* Thread.m in Sources */ = {isa = PBXBuildFile; fileRef = E9AB18051C2A173500BF3C51 /* Thread.m */; };
15
 		E9F13E031C28B3D3004C6B95 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F13E021C28B3D3004C6B95 /* AppDelegate.m */; };
14
 		E9F13E031C28B3D3004C6B95 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F13E021C28B3D3004C6B95 /* AppDelegate.m */; };
16
 		E9F13E061C28B3D3004C6B95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F13E051C28B3D3004C6B95 /* main.m */; };
15
 		E9F13E061C28B3D3004C6B95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F13E051C28B3D3004C6B95 /* main.m */; };
17
 		E9F13E081C28B3D3004C6B95 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E9F13E071C28B3D3004C6B95 /* Assets.xcassets */; };
16
 		E9F13E081C28B3D3004C6B95 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E9F13E071C28B3D3004C6B95 /* Assets.xcassets */; };
61
 		E9109B181C2AAFE100726111 /* GPUStats.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUStats.m; path = CaseLights/GPUStats.m; sourceTree = "<group>"; };
60
 		E9109B181C2AAFE100726111 /* GPUStats.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPUStats.m; path = CaseLights/GPUStats.m; sourceTree = "<group>"; };
62
 		E9AB17FF1C29F8CD00BF3C51 /* Serial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Serial.h; path = CaseLights/Serial.h; sourceTree = "<group>"; };
61
 		E9AB17FF1C29F8CD00BF3C51 /* Serial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Serial.h; path = CaseLights/Serial.h; sourceTree = "<group>"; };
63
 		E9AB18001C29F8CD00BF3C51 /* Serial.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Serial.m; path = CaseLights/Serial.m; sourceTree = "<group>"; };
62
 		E9AB18001C29F8CD00BF3C51 /* Serial.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Serial.m; path = CaseLights/Serial.m; sourceTree = "<group>"; };
64
-		E9AB18041C2A173500BF3C51 /* Thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Thread.h; sourceTree = "<group>"; };
65
-		E9AB18051C2A173500BF3C51 /* Thread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Thread.m; sourceTree = "<group>"; };
66
 		E9F13DFE1C28B3D3004C6B95 /* CaseLights.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CaseLights.app; sourceTree = BUILT_PRODUCTS_DIR; };
63
 		E9F13DFE1C28B3D3004C6B95 /* CaseLights.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CaseLights.app; sourceTree = BUILT_PRODUCTS_DIR; };
67
 		E9F13E011C28B3D3004C6B95 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
64
 		E9F13E011C28B3D3004C6B95 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
68
 		E9F13E021C28B3D3004C6B95 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
65
 		E9F13E021C28B3D3004C6B95 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
127
 			children = (
124
 			children = (
128
 				E9F13E011C28B3D3004C6B95 /* AppDelegate.h */,
125
 				E9F13E011C28B3D3004C6B95 /* AppDelegate.h */,
129
 				E9F13E021C28B3D3004C6B95 /* AppDelegate.m */,
126
 				E9F13E021C28B3D3004C6B95 /* AppDelegate.m */,
130
-				E9AB18041C2A173500BF3C51 /* Thread.h */,
131
-				E9AB18051C2A173500BF3C51 /* Thread.m */,
132
 				E9109B161C2AAFA200726111 /* LowLevel */,
127
 				E9109B161C2AAFA200726111 /* LowLevel */,
133
 				E9F13E071C28B3D3004C6B95 /* Assets.xcassets */,
128
 				E9F13E071C28B3D3004C6B95 /* Assets.xcassets */,
134
 				E9F13E091C28B3D3004C6B95 /* MainMenu.xib */,
129
 				E9F13E091C28B3D3004C6B95 /* MainMenu.xib */,
262
 				E9109B191C2AAFE100726111 /* GPUStats.m in Sources */,
257
 				E9109B191C2AAFE100726111 /* GPUStats.m in Sources */,
263
 				E9F13E061C28B3D3004C6B95 /* main.m in Sources */,
258
 				E9F13E061C28B3D3004C6B95 /* main.m in Sources */,
264
 				E9F13E031C28B3D3004C6B95 /* AppDelegate.m in Sources */,
259
 				E9F13E031C28B3D3004C6B95 /* AppDelegate.m in Sources */,
265
-				E9AB18061C2A173500BF3C51 /* Thread.m in Sources */,
266
 			);
260
 			);
267
 			runOnlyForDeploymentPostprocessing = 0;
261
 			runOnlyForDeploymentPostprocessing = 0;
268
 		};
262
 		};

+ 39
- 20
CaseLights/AppDelegate.m View File

79
         // TODO Enable item if it was last used
79
         // TODO Enable item if it was last used
80
     }
80
     }
81
     
81
     
82
+    JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
83
+    
84
+#ifdef DEBUG
85
+    JSKMCPUUsageInfo cpuUsageInfo = systemMonitor.cpuUsageInfo;
86
+    NSLog(@"CPU Usage: %.3f%%\n", cpuUsageInfo.usage);
87
+    
88
+    JSKMMemoryUsageInfo memoryUsageInfo = systemMonitor.memoryUsageInfo;
89
+    NSLog(@"Memory Usage: %.2fGB Free, %.2fGB Used, %.2fGB Active, %.2fGB Inactive, %.2fGB Compressed, %.2fGB Wired\n", memoryUsageInfo.freeMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.usedMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.activeMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.inactiveMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.compressedMemory / (1024.0 * 1024.0 * 1024.0), memoryUsageInfo.wiredMemory / (1024.0 * 1024.0 * 1024.0));
90
+#endif
91
+    
92
+    // Add CPU Usage menu item
93
+    NSMenuItem *cpuUsageItem = [[NSMenuItem alloc] initWithTitle:@"CPU Usage" action:@selector(selectedCPUVisualization:) keyEquivalent:@""];
94
+    [menuVisualizations addItem:cpuUsageItem];
95
+    
96
+    // TODO enable item if it was last used
97
+    
98
+    // Add Memory Usage item
99
+    NSMenuItem *memoryUsageItem = [[NSMenuItem alloc] initWithTitle:@"RAM Usage" action:@selector(selectedMemoryVisualization:) keyEquivalent:@""];
100
+    [menuVisualizations addItem:memoryUsageItem];
101
+    
102
+    // TODO enable item if it was last used
103
+    
82
     // Check available temperatures and add menu items
104
     // Check available temperatures and add menu items
83
     JSKSMC *smc = [JSKSMC smc];
105
     JSKSMC *smc = [JSKSMC smc];
84
     for (int i = 0; i < [[smc workingTempKeys] count]; i++) {
106
     for (int i = 0; i < [[smc workingTempKeys] count]; i++) {
85
         NSString *key = [smc.workingTempKeys objectAtIndex:i];
107
         NSString *key = [smc.workingTempKeys objectAtIndex:i];
86
-        //NSString *name = [smc humanReadableNameForKey:key];
87
         
108
         
88
-        //NSLog(@"%@: %@\n", key, name);
109
+#ifdef DEBUG
110
+        NSString *name = [smc humanReadableNameForKey:key];
111
+        NSLog(@"Sensor \"%@\": \"%@\"\n", key, name);
112
+#endif
89
         
113
         
90
         if ([key isEqualToString:@"TC0D"]) {
114
         if ([key isEqualToString:@"TC0D"]) {
91
             NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"CPU Temperature" action:@selector(selectedCPUVisualization:) keyEquivalent:@""];
115
             NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"CPU Temperature" action:@selector(selectedCPUVisualization:) keyEquivalent:@""];
94
             // TODO enable item if it was last used
118
             // TODO enable item if it was last used
95
         }
119
         }
96
         
120
         
97
-        // TODO add GPU temperature item
121
+        if ([key isEqualToString:@"TG0D"]) {
122
+            NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"GPU Temperature" action:@selector(selectedGPUVisualization:) keyEquivalent:@""];
123
+            [menuVisualizations addItem:item];
124
+            
125
+            // TODO enable item if it was last used
126
+        }
98
     }
127
     }
99
     
128
     
100
-    // Add CPU Usage menu item
101
-    NSMenuItem *cpuUsageItem = [[NSMenuItem alloc] initWithTitle:@"CPU Usage" action:@selector(selectedCPUVisualization:) keyEquivalent:@""];
102
-    [menuVisualizations addItem:cpuUsageItem];
103
-    
104
-    // TODO enable item if it was last used
105
-    
106
-    // Add Memory Usage item
107
-    NSMenuItem *memoryUsageItem = [[NSMenuItem alloc] initWithTitle:@"RAM Usage" action:@selector(selectedMemoryVisualization:) keyEquivalent:@""];
108
-    [menuVisualizations addItem:memoryUsageItem];
109
-    
110
-    // TODO enable item if it was last used
111
-    
112
-    JSKSystemMonitor *systemMonitor = [JSKSystemMonitor systemMonitor];
113
-    //JSKMCPUUsageInfo cpuUsageInfo = systemMonitor.cpuUsageInfo;
114
-    JSKMMemoryUsageInfo memoryUsageInfo = systemMonitor.memoryUsageInfo;
115
-    NSLog(@"Memory Usage: %lld Free, %lld Used, %lld Active, %lld Inactive, %lld Compressed, %lld Wired\n", memoryUsageInfo.freeMemory / 1000000, memoryUsageInfo.usedMemory / 1000000, memoryUsageInfo.activeMemory / 1000000, memoryUsageInfo.inactiveMemory / 1000000, memoryUsageInfo.compressedMemory / 1000000, memoryUsageInfo.wiredMemory / 1000000);
116
-    
117
     // Prepare serial port menu
129
     // Prepare serial port menu
118
     NSArray *ports = [Serial listSerialPorts];
130
     NSArray *ports = [Serial listSerialPorts];
119
     if ([ports count] > 0) {
131
     if ([ports count] > 0) {
237
         // TODO store new selection
249
         // TODO store new selection
238
         
250
         
239
         // TODO send command
251
         // TODO send command
252
+    } else if ([sender.title isEqualToString:@"GPU Temperature"]) {
253
+        // Turn on "off" menu item
254
+        [sender setState:NSOnState];
255
+        
256
+        // TODO store new selection
257
+        
258
+        // TODO send command
240
     } else {
259
     } else {
241
         NSLog(@"Unknown GPU Visualization selected!\n");
260
         NSLog(@"Unknown GPU Visualization selected!\n");
242
     }
261
     }

+ 4
- 3
CaseLights/GPUStats.m View File

43
                         CFNumberGetValue((CFNumberRef)gpuUsage, kCFNumberSInt64Type, &gpuUsageNum);
43
                         CFNumberGetValue((CFNumberRef)gpuUsage, kCFNumberSInt64Type, &gpuUsageNum);
44
                         CFNumberGetValue((CFNumberRef)freeVRAM, kCFNumberSInt64Type, &freeVRAMNum);
44
                         CFNumberGetValue((CFNumberRef)freeVRAM, kCFNumberSInt64Type, &freeVRAMNum);
45
                         CFNumberGetValue((CFNumberRef)usedVRAM, kCFNumberSInt64Type, &usedVRAMNum);
45
                         CFNumberGetValue((CFNumberRef)usedVRAM, kCFNumberSInt64Type, &usedVRAMNum);
46
-                        *usage = [NSNumber numberWithDouble:gpuUsageNum / (double)10000000];
46
+                        *usage = [NSNumber numberWithDouble:gpuUsageNum / 10000000.0];
47
                         *free = [NSNumber numberWithDouble:freeVRAMNum];
47
                         *free = [NSNumber numberWithDouble:freeVRAMNum];
48
                         *used = [NSNumber numberWithDouble:usedVRAMNum];
48
                         *used = [NSNumber numberWithDouble:usedVRAMNum];
49
                         
49
                         
50
-                        //NSLog(@"GPU: %.3f%% VRAM: %.3f%%\n", gpuUsageNum / (double)10000000,
51
-                              //usedVRAMNum / (double)(freeVRAMNum + usedVRAMNum) * 100.0);
50
+#ifdef DEBUG
51
+                        NSLog(@"GPU: %.3f%% VRAM: %.3f%% (%.2fMB)\n", gpuUsageNum / 10000000.0, ((double)usedVRAMNum) / (freeVRAMNum + usedVRAMNum) * 100.0, (usedVRAMNum + freeVRAMNum) / (1024.0 * 1024.0));
52
+#endif
52
                     }
53
                     }
53
                 }
54
                 }
54
                 CFRelease(services);
55
                 CFRelease(services);

+ 1
- 1
CaseLights/Info.plist View File

21
 	<key>CFBundleSignature</key>
21
 	<key>CFBundleSignature</key>
22
 	<string>????</string>
22
 	<string>????</string>
23
 	<key>CFBundleVersion</key>
23
 	<key>CFBundleVersion</key>
24
-	<string>52</string>
24
+	<string>61</string>
25
 	<key>LSApplicationCategoryType</key>
25
 	<key>LSApplicationCategoryType</key>
26
 	<string>public.app-category.utilities</string>
26
 	<string>public.app-category.utilities</string>
27
 	<key>LSMinimumSystemVersion</key>
27
 	<key>LSMinimumSystemVersion</key>

+ 6
- 0
CaseLights/Serial.h View File

10
 
10
 
11
 @interface Serial : NSObject
11
 @interface Serial : NSObject
12
 
12
 
13
+@property int fd;
14
+@property (strong) NSString *portName;
15
+
16
+- (NSInteger)openPort;
17
+- (NSInteger)hasData;
18
+
13
 + (NSArray *)listSerialPorts;
19
 + (NSArray *)listSerialPorts;
14
 
20
 
15
 @end
21
 @end

+ 75
- 0
CaseLights/Serial.m View File

13
 #import <IOKit/IOKitLib.h>
13
 #import <IOKit/IOKitLib.h>
14
 #import <IOKit/serial/IOSerialKeys.h>
14
 #import <IOKit/serial/IOSerialKeys.h>
15
 
15
 
16
+#import <termios.h>
17
+#import <fcntl.h>
18
+#import <unistd.h>
19
+#import <poll.h>
20
+#import <sys/ioctl.h>
21
+
16
 #import "Serial.h"
22
 #import "Serial.h"
17
 
23
 
18
 kern_return_t findSerialPorts(io_iterator_t *matches);
24
 kern_return_t findSerialPorts(io_iterator_t *matches);
20
 
26
 
21
 @implementation Serial
27
 @implementation Serial
22
 
28
 
29
+@synthesize fd, portName;
30
+
31
+- (NSInteger)openPort {
32
+    // We need a port name
33
+    if (portName == nil) {
34
+        NSLog(@"Can't open serial port without name!\n");
35
+        return 1;
36
+    }
37
+    
38
+    // Check if there was already a port opened
39
+    if (fd != -1) {
40
+        NSLog(@"Closing previously opened serial port \"%@\"!\n", portName);
41
+        close(fd);
42
+    }
43
+    
44
+    // Open port read-only, without controlling terminal, non-blocking
45
+    fd = open([portName UTF8String], O_RDONLY | O_NOCTTY | O_NONBLOCK);
46
+    if (fd == -1) {
47
+        NSLog(@"Error opening serial port \"%@\": %s (%d)!\n", portName, strerror(errno), errno);
48
+        return 1;
49
+    }
50
+    
51
+    // Prevent additional opens except by root-owned processes
52
+    if (ioctl(fd, TIOCEXCL) == -1) {
53
+        NSLog(@"Error enabling exclusive access on \"%@\": %s (%d)!\n", portName, strerror(errno), errno);
54
+        return 1;
55
+    }
56
+    
57
+    fcntl(fd, F_SETFL, 0); // Enable blocking I/O
58
+    
59
+    // Read current settings
60
+    struct termios options;
61
+    tcgetattr(fd, &options);
62
+    
63
+    // Clear all settings
64
+    options.c_lflag = 0;
65
+    options.c_oflag = 0;
66
+    options.c_iflag = 0;
67
+    options.c_cflag = 0;
68
+    
69
+    options.c_cflag |= CS8; // 8 data bits
70
+    options.c_cflag |= CREAD; // Enable receiver
71
+    options.c_cflag |= CLOCAL; // Ignore modem status lines
72
+    
73
+    // Set Baudrate
74
+    cfsetispeed(&options, B115200);
75
+    cfsetospeed(&options, B115200);
76
+    
77
+    options.c_cc[VMIN] = 0; // Return even with zero bytes...
78
+    options.c_cc[VTIME] = 1; // ...but only after .1 seconds
79
+    
80
+    // Set new settings
81
+    tcsetattr(fd, TCSANOW, &options);
82
+    tcflush(fd, TCIOFLUSH);
83
+    
84
+    return 0;
85
+}
86
+
87
+- (NSInteger)hasData {
88
+    struct pollfd fds;
89
+    fds.fd = fd;
90
+    fds.events = (POLLIN | POLLPRI); // Data may be read
91
+    if (poll(&fds, 1, 0) > 0) {
92
+        return 1;
93
+    } else {
94
+        return 0;
95
+    }
96
+}
97
+
23
 + (NSArray *)listSerialPorts {
98
 + (NSArray *)listSerialPorts {
24
     // Get Iterator with all serial ports
99
     // Get Iterator with all serial ports
25
     io_iterator_t serialPortIterator;
100
     io_iterator_t serialPortIterator;

+ 0
- 23
CaseLights/Thread.h View File

1
-//
2
-//  Thread.h
3
-//  SerialGamepad
4
-//
5
-//  Created by Thomas Buck on 15.12.15.
6
-//  Copyright © 2015 xythobuz. All rights reserved.
7
-//
8
-
9
-#import <Foundation/Foundation.h>
10
-
11
-@class AppDelegate;
12
-
13
-@interface Thread : NSThread
14
-
15
-@property BOOL running;
16
-@property int fd;
17
-@property (strong) NSString *portName;
18
-@property (weak) AppDelegate *appDelegate;
19
-
20
-- (id)initWithDelegate:(AppDelegate *)delegate;
21
-- (NSInteger)openPort;
22
-
23
-@end

+ 0
- 93
CaseLights/Thread.m View File

1
-//
2
-//  Thread.m
3
-//  SerialGamepad
4
-//
5
-//  Created by Thomas Buck on 15.12.15.
6
-//  Copyright © 2015 xythobuz. All rights reserved.
7
-//
8
-
9
-#import <termios.h>
10
-#import <fcntl.h>
11
-#import <unistd.h>
12
-#include <poll.h>
13
-
14
-#import "Thread.h"
15
-#import "AppDelegate.h"
16
-
17
-@implementation Thread
18
-
19
-@synthesize running, fd, portName, appDelegate;
20
-
21
-- (id)initWithDelegate:(AppDelegate *)delegate {
22
-    self = [super init];
23
-    if (self != nil) {
24
-        appDelegate = delegate;
25
-    }
26
-    return self;
27
-}
28
-
29
-- (NSInteger)openPort {
30
-    if (portName == nil) {
31
-        return 1;
32
-    }
33
-    
34
-    // Open port read-only, without controlling terminal, non-blocking
35
-    fd = open([portName UTF8String], O_RDONLY | O_NOCTTY | O_NONBLOCK);
36
-    if (fd == -1) {
37
-        NSLog(@"Error opening serial port \"%@\"!\n", portName);
38
-        return 1;
39
-    }
40
-    
41
-    fcntl(fd, F_SETFL, 0); // Enable blocking I/O
42
-    
43
-    // Read current settings
44
-    struct termios options;
45
-    tcgetattr(fd, &options);
46
-    
47
-    options.c_lflag = 0;
48
-    options.c_oflag = 0;
49
-    options.c_iflag = 0;
50
-    options.c_cflag = 0;
51
-    
52
-    options.c_cflag |= CS8; // 8 data bits
53
-    options.c_cflag |= CREAD; // Enable receiver
54
-    options.c_cflag |= CLOCAL; // Ignore modem status lines
55
-    
56
-    cfsetispeed(&options, B115200);
57
-    cfsetospeed(&options, B115200);
58
-    
59
-    options.c_cc[VMIN] = 0; // Return even with zero bytes...
60
-    options.c_cc[VTIME] = 1; // ...but only after .1 seconds
61
-    
62
-    // Set new settings
63
-    tcsetattr(fd, TCSANOW, &options);
64
-    tcflush(fd, TCIOFLUSH);
65
-    
66
-    return 0;
67
-}
68
-
69
-- (NSInteger)hasData {
70
-    struct pollfd fds;
71
-    fds.fd = fd;
72
-    fds.events = (POLLIN | POLLPRI); // Data may be read
73
-    if (poll(&fds, 1, 0) > 0) {
74
-        return 1;
75
-    } else {
76
-        return 0;
77
-    }
78
-}
79
-
80
-- (void)main {
81
-    NSLog(@"Connection running...\n");
82
-    
83
-    running = YES;
84
-    while (running) {
85
-        
86
-    }
87
-    
88
-    close(fd);
89
-    NSLog(@"Connection closed...\n");
90
-    fd = -1;
91
-}
92
-
93
-@end

Loading…
Cancel
Save