This compiles and works OK but I want to check I've done it right.
I have no control over the definition of MYSTRUCT but I do have control over the rest. There is one MYSTRUCT handle for all processes to share and use thread safely.
I have to pass a copy of the client descritor and the shared MYSTRUCT handle to each connection thread.
Problem is the server is falling over after about a day.
Thanks for your help, rotis23
//in /usr/include header file
typedef void* MYSTRUCT;
//in local header file
//in main program
int serverloop(MYSTRUCT working_struct)
struct thread_data *myTD = NULL;
//initiased other stuff
cli_size = sizeof(cli);
client = accept(s,(struct sockaddr*)&cli,(socklen_t*)&cli_size);
if(client == -1)
myTD = (struct thread_data*)malloc(sizeof *myTD);
myTD->mainstruct = working_struct;
myTD->client_socket = client;
res = pthread_create(&tid,&thread_attr,HandleRequest,myTD);
if (res != 0)
void *HandleRequest(void *argp)
struct thread_data *myTTD;
myTTD = (struct thread_data*)argp;
//do stuff with (int)myTTD->client_socket and (MYSTRUCT)myTTD->mainstruct