README 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ASYNC Module
  2. Daniel-Constantin Mierla
  3. <[email protected]>
  4. Edited by
  5. Daniel-Constantin Mierla
  6. <[email protected]>
  7. Copyright © 2011 asipto.com
  8. __________________________________________________________________
  9. Table of Contents
  10. 1. Admin Guide
  11. 1. Overview
  12. 2. Dependencies
  13. 2.1. Kamailio Modules
  14. 2.2. External Libraries or Applications
  15. 3. Parameters
  16. 3.1. workers (int)
  17. 4. Functions
  18. 4.1. async_route(routename, seconds)
  19. 4.2. async_sleep(seconds)
  20. 4.3. async_task_route(routename)
  21. List of Examples
  22. 1.1. Set workers parameter
  23. 1.2. async_route usage
  24. 1.3. async_sleep usage
  25. 1.4. async_task_route usage
  26. Chapter 1. Admin Guide
  27. Table of Contents
  28. 1. Overview
  29. 2. Dependencies
  30. 2.1. Kamailio Modules
  31. 2.2. External Libraries or Applications
  32. 3. Parameters
  33. 3.1. workers (int)
  34. 4. Functions
  35. 4.1. async_route(routename, seconds)
  36. 4.2. async_sleep(seconds)
  37. 4.3. async_task_route(routename)
  38. 1. Overview
  39. This module provides asynchronous operations for handling SIP requests
  40. in the configuration file.
  41. Async uses t_suspend() and t_continue() from the TM and TMX modules.
  42. Note that after invoking the asynchronous operation, the processing
  43. will continue later in another application process. Therefore variables
  44. stored in private memory should not be used, try to use shared memory
  45. if you want to get values after the processing is resumed (e.g.,
  46. $avp(...), $xavp(...), $shv(...), htable $sht(...)).
  47. 2. Dependencies
  48. 2.1. Kamailio Modules
  49. 2.2. External Libraries or Applications
  50. 2.1. Kamailio Modules
  51. The following modules must be loaded before this module:
  52. * tm - transaction management.
  53. tmx - transaction management extensions.
  54. 2.2. External Libraries or Applications
  55. The following libraries or applications must be installed before
  56. running Kamailio with this module loaded:
  57. * None
  58. 3. Parameters
  59. 3.1. workers (int)
  60. 3.1. workers (int)
  61. Number of worker processes to be started to handle the asynchronous
  62. tasks.
  63. Default value is 1.
  64. Example 1.1. Set workers parameter
  65. ...
  66. modparam("async", "workers", 2)
  67. ...
  68. 4. Functions
  69. 4.1. async_route(routename, seconds)
  70. 4.2. async_sleep(seconds)
  71. 4.3. async_task_route(routename)
  72. 4.1. async_route(routename, seconds)
  73. Simulate a sleep of 'seconds' and then continue the processing of the
  74. SIP request with the route[routename]. In case of internal errors, the
  75. function returns false, otherwise the function exits the execution of
  76. the script at that moment (return 0 behaviour).
  77. The routename parameter can be a static string or a dynamic string
  78. value with config variables.
  79. The sleep parameter represent the number of seconds to suspend the
  80. processing of a SIP request. Maximum value is 100. The parameter can be
  81. a static integer or a variable holding an integer.
  82. Since the SIP request handling is resumed in another process, the
  83. config file execution state is practically lost. Therefore beware that
  84. the execution of config after resume will end once the route[routename]
  85. is finished.
  86. This function can be used from REQUEST_ROUTE.
  87. Example 1.2. async_route usage
  88. ...
  89. async_route("RESUME", "4");
  90. ...
  91. route[RESUME] {
  92. send_reply("404", "Not found");
  93. exit;
  94. }
  95. ...
  96. 4.2. async_sleep(seconds)
  97. Simulate a sleep of 'seconds' and then continue the processing of SIP
  98. request with the next action. In case of internal errors, the function
  99. returns false.
  100. The sleep parameter represent the number of seconds to suspend the
  101. processing of SIP request. Maximum value is 100. The parameter can be a
  102. static integer or a variable holding an integer.
  103. This function can be used from REQUEST_ROUTE.
  104. Example 1.3. async_sleep usage
  105. ...
  106. async_sleep("4");
  107. send_reply("404", "Not found");
  108. exit;
  109. ...
  110. 4.3. async_task_route(routename)
  111. Continue the processing of the SIP request with the route[routename] in
  112. one of the processes from core asynchronous framework. The core
  113. parameter async_workers has to be set to enable asynchronous framework.
  114. The task is executed as soon as a process from asynchronous framework
  115. is idle, there is no wait time for the task like for async_route(...).
  116. In case of internal errors, the function returns false, otherwise the
  117. function exits the execution of the script at that moment (return 0
  118. behaviour).
  119. The routename parameter can be a static string or a dynamic string
  120. value with config variables.
  121. Since the SIP request handling is resumed in another process, the
  122. config file execution state is practically lost. Therefore beware that
  123. the execution of config after resume will end once the route[routename]
  124. is finished.
  125. This function can be used from REQUEST_ROUTE.
  126. Example 1.4. async_task_route usage
  127. ...
  128. async_task_route("RESUME");
  129. ...
  130. route[RESUME] {
  131. t_relay();
  132. exit;
  133. }
  134. ...