Esempio n. 1
0
static void daemon_exit(int s)
{
	thr_channel_destroyall();
//	thr_list_destroy();

	mlib_freechnlist(list);
	if (s < 0) {
		syslog(LOG_ERR, "Daemon failure exit.");
		exit(1);
	}
	syslog(LOG_ERR, "Signal %d exit.", s);
	closelog();
	exit(0);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	struct mlib_chn_st *listptr;
	int listsize;
	int i, err;
	char buf[BUFSIZE];
	int len, ch;
	struct ip_mreqn req;

	/*conf处理*/
	while(1) {
		ch = getopt(argc, argv, "M:P:C:");
		if(ch < 0) {
			break;
		}
		switch(ch) {
			case 'M':
				server_conf.mgroup = optarg;
				break;
			case 'P':
				server_conf.rcvport = optarg;
				break;
			case 'C':
				server_conf.medpath = optarg;
			default:
				break;
		}
	}

	openlog("server", LOG_PID, LOG_DAEMON);
	//if(daemonize()) {
	//	syslog(LOG_ERR, "daemonize() is failed");
	//	exit(1);
	//}else
	//	syslog(LOG_INFO, "daemonize() is successed");

	/*socket init*/
	sd = socket(AF_INET, SOCK_DGRAM, 0);
	if(sd < 0) {
		perror("socket()");
		exit(1);
	}

	inet_pton(AF_INET, server_conf.mgroup, &req.imr_multiaddr);
	inet_pton(AF_INET, "0.0.0.0", &req.imr_address);
	req.imr_ifindex = if_nametoindex("eth0");
	if(setsockopt(sd, IPPROTO_IP, IP_MULTICAST_IF, &req, sizeof(req)) < 0) {
		perror("setsockopt()");
		exit(1);
	}

	raddr.sin_family = AF_INET;
	raddr.sin_port = htons(atoi(server_conf.rcvport));
	inet_pton(AF_INET, server_conf.mgroup, &raddr.sin_addr);

	/*获取频道列表信息(从medialib中)*/
	err = mlib_getchnlist(&listptr,&listsize);		
	for(i = 0; i < listsize; i++) {
		printf("%d: ", listptr[i].chnid);
		puts(listptr[i].desc);
	}
/*	if(err)
	{
		syslog();
	}*/

	/*创建thr_list*/
	err = thr_list_create(listptr, listsize);
	if(err < 0)
	{
		fprintf(stderr, "thr_list_create() is error\n");
		exit(1);
	}

	/*创建thr_channel*/
	/*1:200  100:200  4:200  200:200*/ 

	for(i = 1; i <= listsize; i++) {
		thr_channel_create(tid+i, (chnid_t)i);   //id会存在竞争
	}

	while(1)
		pause();
	
	thr_channel_destroyall(listsize);
	thr_list_destroy();
	mlib_freechnlist(&listptr, listsize);
	closelog();

	exit(0);
}