示例#1
0
static void launch_channel(int channo)
{
	pid_t pid;
	ZAP *z;
	char ch[80];

	/* Make sure hangup state is reset */
	chans[channo].needhangup = 0;
	chans[channo].alreadyhungup = 0;

	pid = fork();
	if (pid < 0) {
		fprintf(stderr, "--!! Unable to fork\n");
		chans[channo].needhangup = 1;
	}
	if (pid) {
		printf("-- Launching process %d to handle channel %d\n", pid, channo);
		chans[channo].pid = pid;
	} else {
		sprintf(ch, "%d", channo + offset);
		z = zap_open(ch, 0);
		if (z) {
			do_channel(z);
			exit(0);
		} else {
			fprintf(stderr, "--!! Unable to open channel %d\n", channo);
			exit(1);
		}
	}
	
}
示例#2
0
int main(int argc, char *argv[])
{
	int fds[2];
	struct ss7 *ss7;
	pthread_t tmp, tmp2;

	if (argc == 2) {
		if (!strcasecmp(argv[1], "socketpair")) {
			if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, fds)) {
				perror("socketpair");
				exit(1);
			}
#ifdef LINUX
		} else if (!strcasecmp(argv[1], "live")) {
			fds[0] = zap_open(24);
			if (fds[0] < 0)
				return -1;

			fds[1] = zap_open(48);
			if (fds[1] < 0)
				return -1;
#endif
		} else
			return -1;
	} else
		return -1;

	if (!(ss7 = ss7_new(SS7_ITU))) {
		perror("ss7_new");
		exit(1);
	}
	linkset[0].ss7 = ss7;
	linkset[0].fd = fds[0];
	linkset[0].linkno = 0;

	ss7_set_message(myprintf);
	ss7_set_error(myprintf);

	ss7_set_debug(ss7, 0xffffffff);
	if ((ss7_add_link(ss7, SS7_TRANSPORT_DAHDIDCHAN, fds[0]))) {
		perror("ss7_add_link");
		exit(1);
	}

	if (pthread_create(&tmp, NULL, ss7_run, &linkset[0])) {
		perror("thread(0)");
		exit(1);
	}

	if (!(ss7 = ss7_new(SS7_ITU))) {
		perror("ss7_new");
		exit(1);
	}
	ss7_set_debug(ss7, 0xffffffff);
	linkset[1].linkno = 1;

	if ((ss7_add_link(ss7, SS7_TRANSPORT_DAHDIDCHAN, fds[1]))) {
		perror("ss7_add_link");
		exit(1);
	}

	linkset[1].ss7 = ss7;
	linkset[1].fd = fds[1];

	if (pthread_create(&tmp2, NULL, ss7_run, &linkset[1])) {
		perror("thread(0)");
		exit(1);
	}


	pthread_join(tmp, NULL);
	pthread_join(tmp2, NULL);

	return 0;
}