rfortune.usp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!--#
  2. Test type 4: Fortunes
  3. TechEmpower Web Framework Benchmarks
  4. -->
  5. <!--#declaration
  6. #include "fortune.h"
  7. static UString* pencoded;
  8. static UREDISClient_Base* rc;
  9. static Fortune* pfortune2add;
  10. static UVector<Fortune*>* pvfortune;
  11. static void usp_fork_rfortune()
  12. {
  13. U_TRACE(5, "::usp_fork_rfortune()")
  14. U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);
  15. if (rc->connect() == false)
  16. {
  17. U_WARNING("usp_fork_rfortune(): %V", rc->UClient_Base::getResponse().rep);
  18. return;
  19. }
  20. U_NEW(UString, pencoded, UString(100U));
  21. U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>);
  22. U_NEW(Fortune, pfortune2add, Fortune(0, U_STRING_FROM_CONSTANT("Additional fortune added at request time.")));
  23. }
  24. #ifdef DEBUG
  25. static void usp_end_rfortune()
  26. {
  27. U_TRACE(5, "::usp_end_rfortune()")
  28. delete rc;
  29. if (pencoded)
  30. {
  31. delete pencoded;
  32. delete pvfortune;
  33. delete pfortune2add;
  34. }
  35. }
  36. #endif
  37. -->
  38. <!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr><!--#code
  39. Fortune* item;
  40. uint32_t i, n;
  41. U_NEW(Fortune, item, Fortune(*pfortune2add));
  42. pvfortune->push_back(item);
  43. (void) rc->lrange(U_CONSTANT_TO_PARAM("fortunes 0 -1"));
  44. for (i = 0, n = rc->vitem.size(); i < n; ++i)
  45. {
  46. U_NEW(Fortune, item, Fortune(i+1, rc->vitem[i]));
  47. pvfortune->push_back(item);
  48. }
  49. pvfortune->sort(Fortune::cmp_obj);
  50. for (i = 0, ++n; i < n; ++i)
  51. {
  52. Fortune* elem = (*pvfortune)[i];
  53. UXMLEscape::encode(elem->message, *pencoded);
  54. USP_PRINTF_ADD(
  55. "<tr>"
  56. "<td>%u</td>"
  57. "<td>%v</td>"
  58. "</tr>",
  59. elem->id, pencoded->rep);
  60. }
  61. pvfortune->clear();
  62. --></table></body></html>