new style
[wmaker-crm.git] / WINGs / Documentation / README.connection
blob1176782b1f79d6ec26f848c7477c3e81395fdd76
1 Methods of handling WMConnectionDidDieNotification notification events
2 (same for WMConnectionDidTimeoutNotification)
3 ----------------------------------------------------------------------
5 Once your program got this notification (you need to install an observer for 
6 it), there are some ways to handle it:
8 1. Make your observer enqueue a new notification in the ASAP queue, and the 
9    observer for this new notification (it can be the same function if you 
10    arrange to distinguish between the two cases), should remove the connection. 
11    You can also close the connection before enqueuing the new notification to
12    the ASAP queue, but is not strictly necessarily, since it will be closed 
13    when the observer for the new enqueued notification will be called and you 
14    will call the close/remove function there. This is just to make sure your 
15    connection will be silent, and won't generate new events until you reach 
16    that point.
17    This is by far the best method, since it will assure you that if you 
18    enqueue more than one notification to remove the same connection, they will
19    be coalesced, and called only once.
20 2. In your observer, put the died/closed connection in a bag, and destroy all
21    the connections present in the bag, in your main loop, after you call the 
22    WHandleEvents()/WMHandleEvent(). Also closing the connection can be done
23    before putting the connection in the bag, but is optional as noted above.
24    In this case you need to make sure you don't put in the bag the same
25    connection more than once, in case the DieNotification is sent more that
26    once to you. This is automagically solved by method 1.
27 3. In case it's your only connection, and you plan to exit if it was closed or
28    died, then you can safely close/remove it, and exit. As long as you no 
29    longer access it, there is no problem.
31 4. Make you observer remove the connection. Then make sure that after that
32    point your code no longer tries to access that connection (this usually
33    means until your code gets back to the main loop). This is almost always
34    very hard to achive and subject to hidden errors. I do not recommend this
35    way of handling the died notification. It is ugly and very complicated to
36    handle. If you use it and get plenty of SIGSEGVs then you know why.
37    This method was not presented here to be used, but to show what should
38    be avoided in dealing with the died notification, in case someone gets the
39    idea to try it this way.
42 Note:  read/write operations means to use our read/write functions (like 
43        WMGetMessage()/WMSendMessage()), not the C library ones read()/write().
44 Note2: removing a connection is done by WMDestroyConnection(), while
45        WMCloseConnection() only closes the socket, and removed any pending
46        queues and timers on the connection.