this repo has no description
at fixPythonPipStalling 148 lines 3.9 kB view raw
1/* 2 * Copyright (c) 2013, 2015, 2018 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* 25 * main.c 26 * - test harness to test IPMonitorControl client and server 27 */ 28 29/* 30 * Modification History 31 * 32 * December 16, 2013 Dieter Siegmund (dieter@apple.com) 33 * - initial revision 34 */ 35 36#include <stdlib.h> 37#include <CoreFoundation/CoreFoundation.h> 38#include <SystemConfiguration/SCPrivate.h> 39 40#include "IPMonitorControl.h" 41#include "IPMonitorControlServer.h" 42#include "symbol_scope.h" 43 44STATIC void 45AssertionsChanged(void * info) 46{ 47 CFDictionaryRef assertions = NULL; 48 CFArrayRef changes; 49 50 changes = IPMonitorControlServerCopyInterfaceRankInformation(&assertions); 51 SCPrint(TRUE, stdout, CFSTR("Changed interfaces %@\n"), changes); 52 if (assertions == NULL) { 53 SCPrint(TRUE, stdout, CFSTR("No assertions\n")); 54 } 55 else { 56 SCPrint(TRUE, stdout, CFSTR("Assertions = %@\n"), assertions); 57 CFRelease(assertions); 58 } 59 if (changes != NULL) { 60 CFRelease(changes); 61 } 62 return; 63} 64 65int 66main(int argc, char * argv[]) 67{ 68 if (argc >= 2) { 69 int ch; 70 IPMonitorControlRef control; 71 SCNetworkServicePrimaryRank rank; 72 Boolean rank_set = FALSE; 73 Boolean wait = FALSE; 74 75 rank = kSCNetworkServicePrimaryRankDefault; 76 control = IPMonitorControlCreate(); 77 if (control == NULL) { 78 fprintf(stderr, "failed to allocate IPMonitorControl\n"); 79 exit(1); 80 } 81 82 while ((ch = getopt(argc, argv, "i:r:w")) != EOF) { 83 CFStringRef ifname; 84 SCNetworkServicePrimaryRank existing_rank; 85 86 switch ((char)ch) { 87 case 'i': 88 ifname = CFStringCreateWithCString(NULL, optarg, 89 kCFStringEncodingUTF8); 90 existing_rank = IPMonitorControlGetInterfacePrimaryRank(control, 91 ifname); 92 printf("%s rank was %u\n", optarg, existing_rank); 93 if (IPMonitorControlSetInterfacePrimaryRank(control, 94 ifname, 95 rank)) { 96 printf("%s rank set to %u\n", optarg, rank); 97 rank_set = TRUE; 98 } 99 else { 100 fprintf(stderr, "failed to set rank\n"); 101 } 102 CFRelease(ifname); 103 break; 104 case 'r': 105 rank = strtoul(optarg, NULL, 0); 106 break; 107 case 'w': 108 wait = TRUE; 109 break; 110 default: 111 fprintf(stderr, "unexpected option '%c'\n", (char)ch); 112 exit(1); 113 break; 114 } 115 } 116 argc -= optind; 117 argv += optind; 118 if (argc > 0) { 119 fprintf(stderr, "ignoring additional parameters\n"); 120 } 121 if (!rank_set) { 122 exit(1); 123 } 124 if (wait) { 125 CFRunLoopRun(); 126 } 127 } 128 else { 129 CFRunLoopSourceContext context; 130 CFRunLoopSourceRef rls; 131 STATIC Boolean verbose = TRUE; 132 133 memset(&context, 0, sizeof(context)); 134 context.info = (void *)NULL; 135 context.perform = AssertionsChanged; 136 rls = CFRunLoopSourceCreate(NULL, 0, &context); 137 CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, 138 kCFRunLoopDefaultMode); 139 if (!IPMonitorControlServerStart(CFRunLoopGetCurrent(), rls, &verbose)) { 140 fprintf(stderr, "failed to create connection\n"); 141 exit(1); 142 } 143 CFRunLoopRun(); 144 } 145 exit(0); 146 return (0); 147} 148