This seems like an easy problem to fix, but i’m doing something wrong. I’ve been through all the similar threads and didn’t find anything that solved my problem, so any help would be appreciated!
Basically: C program, and i’m trying to create an array of bufferevents.
#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
extern struct bufferevent bev[8];
//Then, my accept functions -- well, one of them...
static void accept1(struct evconnlistener *listener,
evutil_socket_t fd, struct sockaddr *address, int socklen,
void *ctx) {
/* A new connection was received on this port */
struct event_base *base = evconnlistener_get_base(listener);
bev[0] = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);
/* Callback for when (*bufevent, data READ, data WRITTEN, event OCCURRED, *void) */
bufferevent_setcb(bev[0], read1, NULL, echo_event_cb, NULL);
}
When i attempt to compile (WITH -levent, i might add) i get this error:
src/mix/mix1.c:57:34: error: array type has incomplete element type
Any ideas? 🙁
Note: I am defining the bufferevents outside of main to make them accessible everywhere in my code without passing them. I have other #define’s in the area, so i’m sure it’s something to do with the way i’m building them??
struct buffereventis only declared as an incomplete type in libevent’s public headers; its contents are hidden to users of the public API. All the libevent functions that operate on bufferevents take a pointer to a bufferevent, so what you want here isNote further that you do NOT want to put
externon that declaration or you’ll get an undefined symbol error at link time. If it is only ever referred to in that file, you should usestaticinstead. Otherwise there should be a declaration withexternin one of your application’s header files in addition to theextern-less declaration in the file you showed.