I need to write a C code using libevent.
This is briefly what I expect to do. From stdin, a character will go through in_read_cb
. in_read_cb
will sent to master_read_cb
. master_read_cb
will then send to the system to process. These 2 function are set by libevent. So the type of variable passes to them are fix.
void in_read_cb(struct bufferevent *bev, void *data)
{
//do something
}
void master_read_cb(struct bufferevent *bev, void *data)
{
//do something
}
The problem is, I need to put that void *data
into a structure, while adding a new variable as identifier for the master_read_cb
when to start processing. It look something like this:
typedef struct _new_data
{
void *data;
int start;
} new_data;
void in_read_cb(struct bufferevent *bev, struct new_data->data)
{
//do something
//when it meets a condition, new_data->start = 1;
}
void master_read_cb(struct bufferevent *bev, struct new_data->data)
{
//check new_Data->start
//will sent the character for processing if start = 1
}
This is totally wrong because of how I pass in the function. How can I do it the correct way?