{"action":"created","issue":{"url":"https://api.github.com/repos/libevent/libevent/issues/203","labels_url":"https://api.github.com/repos/libevent/libevent/issues/203/labels{/name}","comments_url":"https://api.github.com/repos/libevent/libevent/issues/203/comments","events_url":"https://api.github.com/repos/libevent/libevent/issues/203/events","html_url":"https://github.com/libevent/libevent/issues/203","id":53541069,"number":203,"title":"HTTP Server - streaming bug","user":{"login":"RomainGiraud","id":357799,"avatar_url":"https://avatars.githubusercontent.com/u/357799?v=3","gravatar_id":"","url":"https://api.github.com/users/RomainGiraud","html_url":"https://github.com/RomainGiraud","followers_url":"https://api.github.com/users/RomainGiraud/followers","following_url":"https://api.github.com/users/RomainGiraud/following{/other_user}","gists_url":"https://api.github.com/users/RomainGiraud/gists{/gist_id}","starred_url":"https://api.github.com/users/RomainGiraud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RomainGiraud/subscriptions","organizations_url":"https://api.github.com/users/RomainGiraud/orgs","repos_url":"https://api.github.com/users/RomainGiraud/repos","events_url":"https://api.github.com/users/RomainGiraud/events{/privacy}","received_events_url":"https://api.github.com/users/RomainGiraud/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-06T17:41:51Z","updated_at":"2015-06-06T11:06:43Z","closed_at":null,"body":"Hello,\r\n\r\nI made a MJPEG streamer, and I think I have found a bug with the HTTP server.\r\n\r\nEDIT: I fix fps to 30, and I only use new release 2.0.22.\r\n\r\nI have the following error `bufferevent_enable at bufferevent.c:422` when I send two reply chunk in the same frame.\r\n\r\nThank you for your help.\r\nIf you need more information, don't hesitate to contact me.\r\n\r\n```C++\r\n#include <iostream>\r\n#include <fstream>\r\n#include <string>\r\n#include <vector>\r\n#include <cstring>\r\n\r\n#include <unistd.h>\r\n#include <dirent.h>\r\n#include <sys/types.h>\r\n#include <sys/stat.h>\r\n#include <pthread.h>\r\n\r\n#include <evhttp.h>\r\n#include <event2/event.h>\r\n\r\nusing namespace std;\r\n\r\nnamespace\r\n{\r\n\r\nvoid* callback_run(void* attr)\r\n{\r\n    struct evhttp_request *req = (struct evhttp_request*)attr;\r\n\r\n    static int count = 0;\r\n    cout << \"Start streaming...\" << endl;\r\n\r\n    const size_t size = 1024 * 1000;\r\n    char *data = new char[size];\r\n\r\n    while (true)\r\n    {\r\n        //struct evbuffer* ebuf = req->output_buffer;\r\n        struct evbuffer* ebuf = evbuffer_new();\r\n\r\n        evbuffer_add(ebuf, data, size);\r\n        evhttp_send_reply_chunk(req, ebuf);\r\n\r\n        evbuffer_add(ebuf, data, size);\r\n        evhttp_send_reply_chunk(req, ebuf);\r\n\r\n        evbuffer_free(ebuf);\r\n\r\n        ++count;\r\n        cout << \"sending: \" << count << endl;\r\n\r\n        usleep(33 * 1000);\r\n    }\r\n\r\n    delete[] data;\r\n\r\n    evhttp_send_reply_end(req);\r\n\r\n    return 0;\r\n}\r\n\r\nvoid process_request(struct evhttp_request *req, void *arg)\r\n{\r\n    (void)arg;\r\n    cout << \"Request received\" << endl;\r\n\r\n    evhttp_add_header(evhttp_request_get_output_headers(req), \"Cache-Control\", \"no-cache\");\r\n    evhttp_send_reply_start(req, 200, \"OK\");\r\n\r\n    pthread_t thr;\r\n    pthread_create(&thr, 0, callback_run, req);\r\n};\r\n\r\nvoid* main_thread(void* attr)\r\n{\r\n    struct event_base* pebase = (struct event_base*)attr;\r\n\r\n    cout << \"Server started...\" << endl;\r\n    event_base_dispatch(pebase);\r\n\r\n    cout << \"Server stopped...\" << endl;\r\n    event_base_free(pebase);\r\n\r\n    return 0;\r\n}\r\n\r\n}\r\n\r\nint main()\r\n{\r\n    /* Event base */\r\n    struct event_base* ebase = event_base_new();\r\n\r\n    /* HTTP server */\r\n    struct evhttp* httpd = evhttp_new(ebase);\r\n\r\n    /* Binding */\r\n    if (evhttp_bind_socket(httpd, \"0.0.0.0\", 8080) == -1)\r\n    {\r\n        evhttp_free(httpd);\r\n        event_base_free(ebase);\r\n        return 1;\r\n    }\r\n\r\n    /* Default callback */\r\n    evhttp_set_gencb(httpd, process_request, NULL);\r\n\r\n    pthread_t mth;\r\n    pthread_create(&mth, 0, main_thread, ebase);\r\n\r\n    while (true);\r\n\r\n    return 0;\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/libevent/libevent/issues/comments/109565025","html_url":"https://github.com/libevent/libevent/issues/203#issuecomment-109565025","issue_url":"https://api.github.com/repos/libevent/libevent/issues/203","id":109565025,"user":{"login":"ellzey","id":125894,"avatar_url":"https://avatars.githubusercontent.com/u/125894?v=3","gravatar_id":"","url":"https://api.github.com/users/ellzey","html_url":"https://github.com/ellzey","followers_url":"https://api.github.com/users/ellzey/followers","following_url":"https://api.github.com/users/ellzey/following{/other_user}","gists_url":"https://api.github.com/users/ellzey/gists{/gist_id}","starred_url":"https://api.github.com/users/ellzey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellzey/subscriptions","organizations_url":"https://api.github.com/users/ellzey/orgs","repos_url":"https://api.github.com/users/ellzey/repos","events_url":"https://api.github.com/users/ellzey/events{/privacy}","received_events_url":"https://api.github.com/users/ellzey/received_events","type":"User","site_admin":false},"created_at":"2015-06-06T11:06:43Z","updated_at":"2015-06-06T11:06:43Z","body":"[Check out the section on threading](http://www.wangafu.net/~nickm/libevent-book/Ref1_libsetup.html)\r\n\r\nMight also want to check out [libevhtp](http://github.com/ellzey/libevhtp) "}}