Connect to multi networks with one call (with threads)
Connect to and manage some teo-networks in one time (with using threads). The networks are divided by the host port number.
Created on July 22, 2015, 11:23 AM
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#define TMULTI_T_VERSION VERSION
#define TEONET_NUM 3
size_t n_num;
size_t num_nets;
int argc;
char** argv;
int options;
int port;
const char *name;
#define teonet ((teonet_multi *)teo)
return NULL;
#undef teonet
}
int main(
int argc,
char** argv) {
int i;
teonet[i].ke = NULL;
teonet[i].n_num = i;
teonet[i].argc = argc;
teonet[i].argv = argv;
teonet[i].event_cb = NULL;
if(i) teonet[i].n_prev = teonet[i-1].ke;
else teonet[i].n_prev = NULL;
teonet[i].n_next = NULL;
int err = pthread_create(&teonet[i].
tid, NULL, &
teonet_t, &teonet[i]);
if (err != 0) printf("\nCan't create thread :[%s]", strerror(err));
else printf("\nThread created successfully\n");
while(teonet[i].
ke == NULL || teonet[i].
ke->runEventMgr != 1) {
}
if(i) teonet[i-1].ke->n_next = teonet[i].ke;
}
for(;;) {
int isRunning = 1;
if(!teonet[i].
ke->runEventMgr) {
isRunning = 0;
break;
}
}
if(!isRunning) break;
}
}
return (EXIT_SUCCESS);
}