我使用这个小技巧来获取evhttp_connection的文件描述符,它就在你想要的指针旁边。这是一件令人讨厌的黑客攻击,但它很简单,而且更容易重建自由派。它已经在x86_64下测试并且运行良好。
static void
send_document_cb(struct evhttp_request *req, void *arg)
{
// ....
struct evhttp_connection *this_connection;
this_connection = evhttp_request_get_connection(req);
int *tricky;
tricky = (((int *)this_connection) + 4);
int fd = *tricky;
printf("fd: %i\n", fd);
// ....
}
综观(下)的结构定义,看来你想应该是使用(((无效*)this_connection)+ 8)或非常类似的东西访问的bufev。
struct evhttp_connection {
TAILQ_ENTRY(evhttp_connection) next;
evutil_socket_t fd;
struct bufferevent *bufev;
...
}
这几乎是AFAICT。如果你干净地做了#2,我很乐意为它应用一个补丁。 libevent邮件列表中的一些人最近开始讨论重构evhttp后端:如果您仍然对黑客入侵感兴趣,您可能想加入其中。 – nickm 2011-04-29 06:07:40