Esempio n. 1
0
void *cs_connect_servers(void *param)
{
	struct cs_server_data *srv;

	//prg.pid_srv = syscall(SYS_gettid);

	while (1) {
		pthread_mutex_lock(&prg.locksrvth);
			uint ticks = GetTickCount();
			srv = cfg.server;
			while (srv) {
				if (!srv->disabled)
				if ( (srv->handle==INVALID_SOCKET) ) {
					if ( (srv->host->ip)||(srv->host->clip) ){
						if ( (srv->keepalivetime+srv->keepalivesent) < ticks ) {
							pthread_t srv_tid;
							create_prio_thread(&srv_tid, (threadfn)cs_connect_srv_th, srv, 50); // Lock server
							//usleep(50000);
						}
					}
					else {
						static char msg[]= "Invalid Address";
						srv->statmsg = msg;
					}
				}
				srv = srv->next;
			}

		pthread_mutex_unlock(&prg.locksrvth);
		sleep(5);
	}
	END_PROCESS = 1;
}
Esempio n. 2
0
void *cs_connect_cli_thread(void *param)
{
	int clientsock;
	struct sockaddr_in clientaddr;
	socklen_t socklen = sizeof(struct sockaddr);
	// Connect Clients 
	pthread_t srv_tid;

	while (1) {
		pthread_mutex_lock(&prg.locksrvcs);

		struct pollfd pfd[MAX_CSPORTS];
		int pfdcount = 0;

		struct cardserver_data *cs = cfg.cardserver;
		while(cs) {
			if (cs->handle>0) {
				cs->ipoll = pfdcount;
				pfd[pfdcount].fd = cs->handle;
				pfd[pfdcount++].events = POLLIN | POLLPRI;
			} else cs->ipoll = -1;
			cs = cs->next;
		}

		int retval = poll(pfd, pfdcount, 3000);

		if (retval>0) {
			struct cardserver_data *cs = cfg.cardserver;
			while(cs) {
				if ( (cs->handle>0) && (cs->ipoll>=0) && (cs->handle==pfd[cs->ipoll].fd) ) {
					if ( pfd[cs->ipoll].revents & (POLLIN|POLLPRI) ) {
						clientsock = accept(cs->handle, (struct sockaddr*)&clientaddr, &socklen );
						if (clientsock<=0) {
							//if (errno == EAGAIN || errno == EINTR) continue;
							//else {
								debugf(" newcamd: Accept failed (errno=%d)\n",errno);
							//}
						}
						else {
							//debugf(" New Client Connection...%s\n", ip2string(clientaddr.sin_addr.s_addr) );
						SetSocketKeepalive(clientsock); 
							struct cs_clicon *clicondata = malloc( sizeof(struct cs_clicon) );
							clicondata->cs = cs; 
							clicondata->sock = clientsock; 
							clicondata->ip = clientaddr.sin_addr.s_addr;
							//while(EAGAIN==pthread_create(&srv_tid, NULL, th_cs_connect_cli,clicondata)) usleep(1000); pthread_detach(&srv_tid);
							create_prio_thread(&srv_tid, (threadfn)th_cs_connect_cli,clicondata, 50);
						}
					}
				}
				cs = cs->next;
			}
		}
		pthread_mutex_unlock(&prg.locksrvcs);
		usleep(3000);
	}
	END_PROCESS = 1;
}
Esempio n. 3
0
void *freecc_connect_cli_thread(void *param)
{
	SOCKET client_sock =-1;
	struct sockaddr_in client_addr;
	socklen_t socklen = sizeof(client_addr);

	pthread_t srv_tid;

	while(1) {
		pthread_mutex_lock(&prg.locksrvfreecc);
		if (cfg.freecccam.handle>0) {
			struct pollfd pfd;
			pfd.fd = cfg.freecccam.handle;
			pfd.events = POLLIN | POLLPRI;
			int retval = poll(&pfd, 1, 3000);
			if ( retval>0 ) {
				client_sock = accept( cfg.freecccam.handle, (struct sockaddr*)&client_addr, /*(socklen_t*)*/&socklen);
				if ( client_sock<0 ) {
					debugf(" FreeCCcam: Accept failed (errno=%d)\n",errno);
					usleep(30000);
				}
				else {
					//debugf(" FreeCCcam: new connection...\n");
					struct struct_clicon *clicondata = malloc( sizeof(struct struct_clicon) );
					SetSocketKeepalive(client_sock); 
					clicondata->sock = client_sock; 
					clicondata->ip = client_addr.sin_addr.s_addr;
					create_prio_thread(&srv_tid, (threadfn)freecc_connect_cli,clicondata, 50);
				}
			}
			else if (retval<0) usleep(30000);
		} else usleep(100000);
		pthread_mutex_unlock(&prg.locksrvfreecc);
		usleep(3000);
	}// While
}
Esempio n. 4
0
int start_thread_dns()
{
	create_prio_thread(&prg.tid_dns, (threadfn)dns_thread, NULL, 50);
	return 0;
}
Esempio n. 5
0
void start_thread_date()
{
	create_prio_thread(&prg.tid_date, (threadfn)thread_enddate, NULL, 50);
}
Esempio n. 6
0
int start_thread_srv()
{
	create_prio_thread(&prg.tid_srv, (threadfn)cs_connect_servers,NULL, 50);
	return 0;
}