8. 1. 2013., u 18:19, Marcus Müller <[email protected]> je napisao:

> 
> I don't understand what you mean by "connected to a notification".

David is, if I understand correctly, referring to using methods such as 
-[NSFileHandle acceptConnectionInBackgroundAndNotify] after creating the file 
handle with -[NSFileHandle initWithFileDescriptor:closeOnDealloc:].

Once one of these observation methods is used, the method actually schedules 
observing for file events on the runloop, and upon noticing an event that you 
scheduled observing for, sends a notification through NSNotificationCenter.

For example, having created a socket...
    NSSocketPort* serverSock = [[NSSocketPort alloc] initWithTCPPort: 1234];
...wrap its file handle into a file handle...
    socketHandle = [[NSFileHandle alloc] initWithFileDescriptor: [serverSock 
socket]
                                                 closeOnDealloc: NO];
...begin observing for notifications...
    [[NSNotificationCenter defaultCenter] addObserver: self selector: 
@selector(newConnection:) 
                                                 name: 
NSFileHandleConnectionAcceptedNotification
                                               object: socketHandle];
... and finally schedule observing the event (and dispatching the 
notifications):
    [socketHandle acceptConnectionInBackgroundAndNotify];

Taken from this (broken) piece of code:
  
http://stackoverflow.com/questions/4677724/nsfilehandle-function-acceptconnectioninbackgroundandnotify-not-working-when-cal
The relevant piece of code that I described does not seem broken, and the 
general idea seems to be sound. If the relevant code is fundamentally broken, 
someone please shame me. I didn't use this API before.

Looking at NSFileHandle documentation will probably be the best course of 
action.

> 
>> This is easy from anything that allows you to get the underlying file 
>> descriptor for the socket, and if it's already encapsulated in an object 
>> then you can either use associative references or just create an 
>> NSDictionary indexed by the file handles.
> 
> if I understand you correctly, you're describing the way how to get back from 
> the native file handle encapsulated in a notification (userInfo) towards my 
> original object?

No, David is just talking about the fact that, if you already have access to a 
file handle for a socket (that is, the return value of the socket() call) in 
whatever underlying library you use or if you use the BSD sockets directly, you 
can use NSFileHandle quite easily.

> 
> What I don't understand: how exactly do you schedule an "NSFileHandle 
> connected to a notification" in a NSRunLoop?
> 

Via -[NSFileHandle acceptConnectionInBackgroundAndNotify] and other similar 
...InBackgroundAndNotify methods.

--
Ivan Vučica
[email protected] - http://ivan.vucica.net/

_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to