Guest User

Untitled

a guest
Oct 22nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. ruby-1.9.2-p180 :006 > s = s = %q<#include <sys/types.h>
  2. ruby-1.9.2-p180 :007'> #include <sys/time.h>
  3. ruby-1.9.2-p180 :008'> #include <sys/queue.h>#include <stdlib.h>
  4. ruby-1.9.2-p180 :009'>
  5. ruby-1.9.2-p180 :010'> #include <err.h>
  6. ruby-1.9.2-p180 :011'> #include <event.h>
  7. ruby-1.9.2-p180 :012'> #include <evhttp.h>
  8. ruby-1.9.2-p180 :013'>
  9. ruby-1.9.2-p180 :014'> void generic_handler(struct evhttp_request *req, void *arg)
  10. ruby-1.9.2-p180 :015'> {
  11. ruby-1.9.2-p180 :016'> struct evbuffer *buf;
  12. ruby-1.9.2-p180 :017'> buf = evbuffer_new();
  13. ruby-1.9.2-p180 :018'>
  14. ruby-1.9.2-p180 :019'> if (buf == NULL)
  15. ruby-1.9.2-p180 :020'> err(1, "failed to create response buffer");
  16. ruby-1.9.2-p180 :021'>
  17. ruby-1.9.2-p180 :022'> evbuffer_add_printf(buf, "Requested: %sn", evhttp_request_uri(req));
  18. ruby-1.9.2-p180 :023'> evhttp_send_reply(req, HTTP_OK, "OK", buf);
  19. ruby-1.9.2-p180 :024'> }
  20. ruby-1.9.2-p180 :025'>
  21. ruby-1.9.2-p180 :026'> int main(int argc, char **argv)
  22. ruby-1.9.2-p180 :027'> {
  23. ruby-1.9.2-p180 :028'> struct evhttp *httpd;
  24. ruby-1.9.2-p180 :029'>
  25. ruby-1.9.2-p180 :030'> event_init();
  26. ruby-1.9.2-p180 :031'> httpd = evhttp_start("0.0.0.0", 8080);
  27. ruby-1.9.2-p180 :032'>
  28. ruby-1.9.2-p180 :033'> /* Set a callback for requests to "/specific". */
  29. ruby-1.9.2-p180 :034'> /* evhttp_set_cb(httpd, "/specific", another_handler, NULL); */
  30. ruby-1.9.2-p180 :035'>
  31. ruby-1.9.2-p180 :036'> /* Set a callback for all other requests. */
  32. ruby-1.9.2-p180 :037'> evhttp_set_gencb(httpd, generic_handler, NULL);
  33. ruby-1.9.2-p180 :038'>
  34. ruby-1.9.2-p180 :039'> event_dispatch();
  35. ruby-1.9.2-p180 :040'>
  36. ruby-1.9.2-p180 :041'> /* Not reached in this code as it is now. */
  37. ruby-1.9.2-p180 :042'> evhttp_free(httpd);
  38. ruby-1.9.2-p180 :043'>
  39. ruby-1.9.2-p180 :044'> return 0;
  40. ruby-1.9.2-p180 :045'> }>
  41. => "#include <sys/types.h>\n#include <sys/time.h>\n#include <sys/queue.h>#include <stdlib.h>\n\n#include <err.h>\n#include <event.h>\n#include <evhttp.h>\n\nvoid generic_handler(struct evhttp_request *req, void *arg)\n{\n struct evbuffer *buf;\n buf = evbuffer_new();\n\n if (buf == NULL)\n err(1, \"failed to create response buffer\");\n\n evbuffer_add_printf(buf, \"Requested: %sn\", evhttp_request_uri(req));\n evhttp_send_reply(req, HTTP_OK, \"OK\", buf);\n}\n\nint main(int argc, char **argv)\n{\n struct evhttp *httpd;\n\n event_init();\n httpd = evhttp_start(\"0.0.0.0\", 8080);\n\n /* Set a callback for requests to \"/specific\". */\n /* evhttp_set_cb(httpd, \"/specific\", another_handler, NULL); */\n\n /* Set a callback for all other requests. */\n evhttp_set_gencb(httpd, generic_handler, NULL);\n\n event_dispatch();\n\n /* Not reached in this code as it is now. */\n evhttp_free(httpd);\n\n return 0;\n}"
  42. ruby-1.9.2-p180 :046 > puts s
  43. #include <sys/types.h>
  44. #include <sys/time.h>
  45. #include <sys/queue.h>#include <stdlib.h>
  46.  
  47. #include <err.h>
  48. #include <event.h>
  49. #include <evhttp.h>
  50.  
  51. void generic_handler(struct evhttp_request *req, void *arg)
  52. {
  53. struct evbuffer *buf;
  54. buf = evbuffer_new();
  55.  
  56. if (buf == NULL)
  57. err(1, "failed to create response buffer");
  58.  
  59. evbuffer_add_printf(buf, "Requested: %sn", evhttp_request_uri(req));
  60. evhttp_send_reply(req, HTTP_OK, "OK", buf);
  61. }
  62.  
  63. int main(int argc, char **argv)
  64. {
  65. struct evhttp *httpd;
  66.  
  67. event_init();
  68. httpd = evhttp_start("0.0.0.0", 8080);
  69.  
  70. /* Set a callback for requests to "/specific". */
  71. /* evhttp_set_cb(httpd, "/specific", another_handler, NULL); */
  72.  
  73. /* Set a callback for all other requests. */
  74. evhttp_set_gencb(httpd, generic_handler, NULL);
  75.  
  76. event_dispatch();
  77.  
  78. /* Not reached in this code as it is now. */
  79. evhttp_free(httpd);
  80.  
  81. return 0;
  82. }
  83. => nil
  84. ruby-1.9.2-p180 :047 >
Add Comment
Please, Sign In to add comment