• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: dispatch_source does not work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dispatch_source does not work


  • Subject: Re: dispatch_source does not work
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Wed, 05 Nov 2014 16:28:20 +0700

> On 5 Nov 2014, at 14:08, Peter <email@hidden> wrote:
>
> http://stackoverflow.com/questions/12343833/cocoa-monitor-a-file-for-modifications/26304208#26304208
>
> has some info on this.

Thanks a lot. Got it working now.

Mit freundlichen Grüßen

Gerriet.

>
> ___ Peter Hartmann ________
>
> mailto:email@hidden
>
>
> Am 05.11.2014 um 07:50 schrieb Gerriet M. Denkmann <email@hidden>:
>
>> I want to monitor a file for changed content.
>> Polling is generally not a good idea, so I tried dispatch_source.
>>
>> But it does not work.
>>
>> Here the code:
>>
>> static NSString *const kTestPath 	= @"/tmp/a.test";
>>
>> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
>> {
>> 	const char *filename = kTestPath.fileSystemRepresentation;
>> 	int fd = open(filename, O_RDONLY);
>> 	fcntl(fd, F_SETFL, O_NONBLOCK);
>> 	uintptr_t fD = (uintptr_t)fd;
>> 	dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
>> 	const uint64_t flags = DISPATCH_VNODE_WRITE | DISPATCH_VNODE_LINK;
>> 	dispatch_source_t my_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fD, flags, queue);
>> 	dispatch_source_set_event_handler(my_source, ^{ [self fileDidChange]; } );
>> 	dispatch_resume(my_source);
>> }
>>
>> - (void)fileDidChange
>> {
>> 	NSLog(@"%s",__FUNCTION__);	//	never seen
>> }
>>
>> - (IBAction)buttonClicked: sender
>> {
>> 	static NSUInteger seqq = 0;
>> 	seqq++;
>>
>> 	const char *stats_temp_file = "/tmp/a.temp";
>> 	FILE *fp = fopen(stats_temp_file, "w");
>> 	fprintf(fp, "%lu\n", seqq);
>> 	(void)fclose(fp);
>>
>> 	const char *filename = kTestPath.fileSystemRepresentation;
>> 	int a = rename(stats_temp_file, filename);
>> }
>>
>> What am I doing wrong? (Writing directly to kTestPath without rename() also does not work).
>>
>> Gerriet.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >dispatch_source does not work (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: dispatch_source does not work (From: Peter <email@hidden>)

  • Prev by Date: Re: Editing NSOutlineView Group Item
  • Next by Date: Re: Editing NSOutlineView Group Item
  • Previous by thread: Re: dispatch_source does not work
  • Next by thread: Re: dispatch_source does not work
  • Index(es):
    • Date
    • Thread