Tip: default behavior used when ace_svc_handler is disabled

Source: Internet
Author: User

Tip: default behavior used when ace_svc_handler is disabled

Stone Jiang

In the previous article, we saw some tips about the default behavior provided by the ace_svc_handler: open () hook function. In most cases, it completes all the things required for service creation: registering a new processor and returning for the input event.

The default act of disabling an operation in ace_svc_handler is better than that initialized in open ().CodeMore complex. This is because the hook function when it is disabled contains two scenarios: reactive shutdown and active-object shutdown.

They have the same effect: delete all events registered in the reactors and ensure that the objects of the ace_svc_handler Derived classes are deleted.

 

Handle_close (): called when the following conditions occur:
1) when the Event Callback Function (: handle_xxxx () returns-1, or
2) Call ace_reactor: remove_handler (). When the passed mark does not include dont_call
The reactor framework will call the handle_close () hook function. The default act of ace_svc_handler: handle_close () is to call ace_svc_handler: Destroy () to destroy the event processor.

Active Object close (): when an object derived from ace_svc_handler is converted to an active object through the activate () function, the SVC () of the processor () method is called back after running in the thread it generates. When SVC () returns, the thread

But when it is about to exit, it is still in the context of the thread to be exited. The ace_task Framework calls its close () method. The ace_svc_handler: Close () method calls handle_close () to clear the service processor.

Therefore, whether the ace_svc_handler object is reactive or active, the cleaning work at the end is in the same place: ace_svc_handler: Destroy (). If the object is dynamically allocated and is not a component of the ace_stream framework

Minute, destroy () will delete this object. If the object is not dynamically allocated, the responsibility of the Destructor is the closed range of the object at the time of creation. If the object is an integral part of the ace_stream module, the code of the stream and/or control flow is responsible for management.

Object lifecycle. The destroy () function must comply with such rules to avoid resource leaks.

Whether ace_svc_handler object is reactive or active, the same thing will happen :~ Ace_svc_handler () (processor's destructor) Call ace_svc_handler: Shutdown () function completion Service

Cleanup of the handler. The following cleanup operations are performed by Shutdown:

 

If the processor is associated with the reactor:
Cancels all timers associated with the processor.
Deletes all registered events for stream objects (such as sockets) of the processor.
If the processor is related to the recycler, remove the processor from the recycler.
Close the stream object.
Therefore, in most cases, the service processor needs to clean up through the framework through shutdown, which simply allows the default hook function to be called. If your applicationProgramMore close/clear rules are required.

The recommended method is the handle_close () Hook method of your processor. Make sure that the ace_svc_handler: Destroy () function person is used as the last action of your handle_close (), which is in line with the remaining actions of the Framework cleanup.

And.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.