Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ruby-1.9.2-p180 :006 > s = s = %q<#include <sys/types.h>
- ruby-1.9.2-p180 :007'> #include <sys/time.h>
- ruby-1.9.2-p180 :008'> #include <sys/queue.h>#include <stdlib.h>
- ruby-1.9.2-p180 :009'>
- ruby-1.9.2-p180 :010'> #include <err.h>
- ruby-1.9.2-p180 :011'> #include <event.h>
- ruby-1.9.2-p180 :012'> #include <evhttp.h>
- ruby-1.9.2-p180 :013'>
- ruby-1.9.2-p180 :014'> void generic_handler(struct evhttp_request *req, void *arg)
- ruby-1.9.2-p180 :015'> {
- ruby-1.9.2-p180 :016'> struct evbuffer *buf;
- ruby-1.9.2-p180 :017'> buf = evbuffer_new();
- ruby-1.9.2-p180 :018'>
- ruby-1.9.2-p180 :019'> if (buf == NULL)
- ruby-1.9.2-p180 :020'> err(1, "failed to create response buffer");
- ruby-1.9.2-p180 :021'>
- ruby-1.9.2-p180 :022'> evbuffer_add_printf(buf, "Requested: %sn", evhttp_request_uri(req));
- ruby-1.9.2-p180 :023'> evhttp_send_reply(req, HTTP_OK, "OK", buf);
- ruby-1.9.2-p180 :024'> }
- ruby-1.9.2-p180 :025'>
- ruby-1.9.2-p180 :026'> int main(int argc, char **argv)
- ruby-1.9.2-p180 :027'> {
- ruby-1.9.2-p180 :028'> struct evhttp *httpd;
- ruby-1.9.2-p180 :029'>
- ruby-1.9.2-p180 :030'> event_init();
- ruby-1.9.2-p180 :031'> httpd = evhttp_start("0.0.0.0", 8080);
- ruby-1.9.2-p180 :032'>
- ruby-1.9.2-p180 :033'> /* Set a callback for requests to "/specific". */
- ruby-1.9.2-p180 :034'> /* evhttp_set_cb(httpd, "/specific", another_handler, NULL); */
- ruby-1.9.2-p180 :035'>
- ruby-1.9.2-p180 :036'> /* Set a callback for all other requests. */
- ruby-1.9.2-p180 :037'> evhttp_set_gencb(httpd, generic_handler, NULL);
- ruby-1.9.2-p180 :038'>
- ruby-1.9.2-p180 :039'> event_dispatch();
- ruby-1.9.2-p180 :040'>
- ruby-1.9.2-p180 :041'> /* Not reached in this code as it is now. */
- ruby-1.9.2-p180 :042'> evhttp_free(httpd);
- ruby-1.9.2-p180 :043'>
- ruby-1.9.2-p180 :044'> return 0;
- ruby-1.9.2-p180 :045'> }>
- => "#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}"
- ruby-1.9.2-p180 :046 > puts s
- #include <sys/types.h>
- #include <sys/time.h>
- #include <sys/queue.h>#include <stdlib.h>
- #include <err.h>
- #include <event.h>
- #include <evhttp.h>
- void generic_handler(struct evhttp_request *req, void *arg)
- {
- struct evbuffer *buf;
- buf = evbuffer_new();
- if (buf == NULL)
- err(1, "failed to create response buffer");
- evbuffer_add_printf(buf, "Requested: %sn", evhttp_request_uri(req));
- evhttp_send_reply(req, HTTP_OK, "OK", buf);
- }
- int main(int argc, char **argv)
- {
- struct evhttp *httpd;
- event_init();
- httpd = evhttp_start("0.0.0.0", 8080);
- /* Set a callback for requests to "/specific". */
- /* evhttp_set_cb(httpd, "/specific", another_handler, NULL); */
- /* Set a callback for all other requests. */
- evhttp_set_gencb(httpd, generic_handler, NULL);
- event_dispatch();
- /* Not reached in this code as it is now. */
- evhttp_free(httpd);
- return 0;
- }
- => nil
- ruby-1.9.2-p180 :047 >
Add Comment
Please, Sign In to add comment