And I have to create a thread inside a function, that is (the thread) in an infinite loop waiting for connections and accepting messages from another process (so, the thread is going to work as a tcp server), and whenever a message comes, it has to ¿use? or call or whatever the function that's passed as a parameter, to the function the thread is created in.
So this is the function header
int init(void (*notif)(const char *, const char *),
void (*parameter1)(const char *),
void (*parameter2)(const char *));
So I've seen this post How do you pass a function as a parameter in C? and it kind of helps to get the idea but I'm completly unsure how would I do it inside a thread.
And the reason for that is because I have little to no experience with servers inside threads, I found this code which is really helpful https://gist.github.com/silv3rm00n/5821760
But the way it works, all of the code is in the function (so outside the thread) and the thread takes as the only parameter the socket used for connections. I've seen it used similar to this a few times already.
And then I doubt: does it make sense to put all of the code of the server inside the thread? Or it would make little sense and the thread would be too "heavy" and it would be better to fork in that case.
I'm sorry if the question is poorly worded or I'm not explaining myself properly, I have little experience with threads and 0 experience with this type of problems.
edit: this is all I've got so far but I'm missing something, it does not work:
void (*funcionParametroThread)(const char *, const char *);
funcionParametroThread=(*notif_evento)(const char *, const char *);
pthread_create(&thid, &atrib_th, tcp_server, funcionParametroThread);
I tried making it similar to this code that is an answer from the linked question above
int dosomethingwithchar(char a) { return 1; }
functiontype2 func2 = &dosomethingwithchar
int result = func2('a');