'How do I avoid open sockets using libevent evhttp client?
I have a fairly simple http client using libevent's evhttp functions. It works almost perfectly, but it eventually fails with 'too many open files'. The client reads data from multiple http sources (less than a dozen) every 15 seconds. The framework is as follows (actual code is much longer):
callbackHandler {
Process results
Free connection with evhttp_connection_free()
}
doCycle {
Create base using event_base_new()
For each http data source {
Create connection using evhttp_connection_base_new() with callbackHandler
Create request using evhttp_request_new()
Register connection and request using evhttp_make_request()
}
Start loop with event_base_dispatch()
}
main {
call doCycle() every 15 seconds
}
Since everything is created in the doCycle() function that returns after event_base_dispatch(), I'm assuming that the base, all of the related events, and all the sockets should be cleaned up after the last event completes or times out. What do I need to do to close/free the sockets? Attempting to use evhttp_request_free() in the callback results in a 'double free' error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|