Savagedlight / libifconfig

A C API to do most things done by the FreeBSD 'ifconfig' program today
Other
26 stars 7 forks source link

todo: Keep a non-global state #1

Closed Savagedlight closed 8 years ago

Savagedlight commented 8 years ago

Currently, the error feedback is done through a global variable. This is very hostile towards multi-threading.

Instead, create a struct which keeps state for the current thread. This struct should also contain the socket cache. Applications would have to pass an instance of this struct to the API by reference.

This makes it easier to keep track of state, and applications can use libifconfig in a multithreaded way even though libifconfig is not aware of threading, so long as they use a separate instance of the state struct per thread.

Idea by: Adrian Chadd

Savagedlight commented 8 years ago

Feedback from Kristof Provost:

libifc_handle_t* libifc_open();
void libifc_close(libifc_handle_t *h);

int libifc_set_mtu(libifc_handle_t *h, const char *name, int mtu);

Possibly also: int libifc_get_error(libifc_handle_t *h);

If the definition of libifc_handle_t is kept opaque (so the headers only have ‘struct libifc_handle; typedef struct libifc_handle libifc_handle_t;’) you can get away with changing the size or contents of the struct without breaking any of the users. (Because they’ll only have a pointer to keep track of, the size of the object it points to doesn’t matter to them.)