From: http://blog.csdn.net/mjp_mjp/article/details/4406059
1. in multiple threads, The ace_reactor: eventloop. When calling eventloop in multiple threads (pools), note that the reactor () method must be used in acceptor/eventhandler () to obtain the ace_reactor pointer, do not use ace_reactor: instance, the principle is very simple. However, you must note that the reactor () class method is much better than the single-piece method in programming. At least it is safe and will not damage encapsulation.
2. The msg_queue class in ace_task is indeed charming, but it should be noted that both getq and putq may cause blocking. Therefore, it is best to call them through timeout, especially when this task is completed. Because you need to clear the msg_queue. If it does not time out, you may not be able to exit the thread safely.
3. ace_svc_handler. This class is very good. It inherits from ace_task. Therefore, it has msg_queue and can be used in the component configuration model of ACE. For handle_output, note that it is not automatically called by the framework, unless you use the policy class ace_reactor_icationication_strategy (msg_queue needs it, and the port is used in Windows ), it uses the stream control method to notify you to write. In handle_output, do not hesitate. You must use while to retrieve the message_block in msg_queue as much as possible and then send it out (until sending returns-1, errono = ewouldblock ).
4. acceptor/handler should be cleared before end_event_loop. If a new acceptor is used to create an acceptor, it is recommended to log out before end_event_loop, that is, to log out with the dont_call parameter during handle_close and delete it. If you delete it after end_event_loop, Ace ensures that you will encounter fatal errors such as crash assertions that cannot calm you down. One idea is that if the new object pointer remains unchanged before the program exits, that is, if the object is still under your control, you do not need to delete it, this is not called Memory leakage. Because the operating system clears the space used by the process after the process is killed.
5. Excellent local classes (classes declared in the function body). Strictly speaking, this is not an ace category. Local class objects can share global/static data, but cannot directly use the data in the function body; or the variables in the class where the member function is located, but can use the class pointer, private member of the usage class. This is very powerful and can be done in a very private way. In addition, you can use this to return a partial Class Object Pointer (of course void *), while C ++ ensures that the outside world cannot access it, and cannot delete it.
6. emsgsize, this errorcode, which I did not understand at the beginning, is encountered in practice. This error occurs when the length of the requested data is smaller than the actual data length. At this time, we can adopt the agreed method, that is, we cannot send packets whose data length exceeds MTU each time, and the received packets will certainly not exceed this value. This error is not reported. In addition, it is advantageous to prevent others from maliciously sending large packets to attack you. More importantly, data smaller than MTU will not be transferred through subcontracting, and the data is secure and reliable. This is also applicable to TCP/UDP.
7. When Ace is used in the MFC environment, or for shared libraries (DLL, so, etc.), it is best to use ACE: init to initialize it before use, and use ACE: Before exiting :: fini.
[Switch] Ace programming Summary