• 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
dispatch_source does not work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dispatch_source does not work


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

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


  • Follow-Ups:
    • Re: dispatch_source does not work
      • From: Kyle Sluder <email@hidden>
    • Re: dispatch_source does not work
      • From: Peter <email@hidden>
  • Prev by Date: Re: Background CIFilter processing?
  • Next by Date: Re: Background CIFilter processing?
  • Previous by thread: Re: NSImage glowing
  • Next by thread: Re: dispatch_source does not work
  • Index(es):
    • Date
    • Thread