diff rvinterf/lowlevel/rvifmain.c @ 195:549e6cd1e77d

rvinterf: support for socketpair invokation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 26 Nov 2013 20:23:38 +0000
parents cf8583923dc4
children 2f285f20d617
line wrap: on
line diff
--- a/rvinterf/lowlevel/rvifmain.c	Mon Nov 25 06:17:04 2013 +0000
+++ b/rvinterf/lowlevel/rvifmain.c	Tue Nov 26 20:23:38 2013 +0000
@@ -22,11 +22,12 @@
 extern size_t rxpkt_len;
 
 struct client *client_head;
+int socketpair_fd;
 
 char *logfname;
 FILE *logF;
 time_t logtime;
-int background;
+int background, no_output;
 int max_fd;
 
 char *socket_pathname = "/tmp/rvinterf_socket";
@@ -42,10 +43,13 @@
 	fd_set fds;
 	struct client *cli, **clip;
 
-	while ((c = getopt(argc, argv, "bB:d:l:s:w:")) != EOF)
+	while ((c = getopt(argc, argv, "bB:d:l:ns:S:w:")) != EOF)
 		switch (c) {
 		case 'b':
 			background++;
+			/* FALL THRU */
+		case 'n':
+			no_output++;
 			continue;
 		case 'B':
 			baudrate_name = optarg;
@@ -59,6 +63,9 @@
 		case 's':
 			socket_pathname = optarg;
 			continue;
+		case 'S':
+			socketpair_fd = atoi(optarg);
+			continue;
 		case 'w':
 			wakeup_after_sec = strtoul(optarg, 0, 0);
 			continue;
@@ -86,7 +93,10 @@
 		fprintf(logF, "*** Log of rvinterf session ***\n");
 		setlinebuf(logF);
 	}
-	create_listener_socket();
+	if (socketpair_fd)
+		create_socketpair_client();
+	else
+		create_listener_socket();
 	if (background) {
 		c = fork();
 		if (c < 0) {
@@ -102,7 +112,8 @@
 	for (;;) {
 		FD_ZERO(&fds);
 		FD_SET(target_fd, &fds);
-		FD_SET(listener, &fds);
+		if (listener)
+			FD_SET(listener, &fds);
 		for (clip = &client_head; cli = *clip; ) {
 			if (cli->rx_state == 2) {
 				close(cli->fd);
@@ -113,6 +124,8 @@
 			FD_SET(cli->fd, &fds);
 			clip = &cli->next;
 		}
+		if (socketpair_fd && !client_head)
+			exit(0);
 		c = select(max_fd+1, &fds, 0, 0, 0);
 		time(&logtime);
 		if (c < 0) {
@@ -123,7 +136,7 @@
 		}
 		if (FD_ISSET(target_fd, &fds))
 			process_serial_rx();
-		if (FD_ISSET(listener, &fds))
+		if (listener && FD_ISSET(listener, &fds))
 			handle_listener_select();
 		for (cli = client_head; cli; cli = cli->next)
 			if (FD_ISSET(cli->fd, &fds))
@@ -137,25 +150,25 @@
 	case RVT_RV_HEADER:
 		if (rxpkt_len < 6)
 			goto unknown;
-		if (!background || logF)
+		if (!no_output || logF)
 			print_rv_trace();
 		if (client_head)
 			forward_rv_trace();
 		return;
 	case RVT_L1_HEADER:
-		if (!background || logF)
+		if (!no_output || logF)
 			print_l1_trace();
 		if (client_head)
 			forward_nonrvt_pkt();
 		return;
 	case RVT_L23_HEADER:
-		if (!background || logF)
+		if (!no_output || logF)
 			print_g23_trace();
 		if (client_head)
 			forward_nonrvt_pkt();
 		return;
 	case RVT_TM_HEADER:
-		if (!background || logF)
+		if (!no_output || logF)
 			print_etm_output_raw();
 		if (client_head)
 			forward_nonrvt_pkt();