Example #1
0
int main(int argc, char **argv)
{
	struct minipc_ch *client;
	struct stat stbuf;
	int ret;
	char s[80];

	client = minipc_client_create("mbox", 0);
	if (!client) {
		fprintf(stderr, "%s: client_create(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}
	minipc_set_logfile(client, stderr);

	while (fgets(s, sizeof(s), stdin)) {
		/* strip trailing newline */
		s[strlen(s)-1] = '\0';
		ret = minipc_call(client, CLIENT_TIMEOUT, &rpc_stat,
				  &stbuf, s);
		if (ret < 0) {
			fprintf(stderr, "stat(%s): %s\n", s, strerror(errno));
			continue;
		}
		printf("%s:\n", s);
		printf("mode %o, size %li, owner %i, atime %li\n",
		       stbuf.st_mode, (long)stbuf.st_size, stbuf.st_uid,
		       stbuf.st_atime);
	}
	return 0;
}
Example #2
0
int halexp_client_init()
{
	hal_ch = minipc_client_create(WRSW_HAL_SERVER_ADDR, 0);
	if (!hal_ch)
		return -1;
	else
	  return 0;
}
Example #3
0
int main(int argc, char **argv)
{
	struct minipc_ch *client;
	int a, b, c, ret;
	struct timeval tv;
	double rt_in, rt_out;

	client = minipc_client_create("sample", 0);
	if (!client) {
		fprintf(stderr, "%s: client_create(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}
	minipc_set_logfile(client, stderr);

	/*
	 * gettod, sum, sum, gettod
	 * pause a while in-between, so several clients can be run
	 * concurrently as a load test on the server
	 */
	ret = minipc_call(client, TRIVIAL_TIMEOUT, &ss_tod_struct, &tv, NULL);
	if (ret < 0) {
		goto error;
	}
	printf("tv: %li.%06li\n", tv.tv_sec, tv.tv_usec);
	usleep(500*1000);

	a = 345; b = 628;
	ret = minipc_call(client, TRIVIAL_TIMEOUT, &ss_sum_struct, &c, a, b);
	if (ret < 0) {
		goto error;
	}
	printf("%i + %i = %i\n", a, b, c);
	usleep(500*1000);

	a = 10; b = 20;
	ret = minipc_call(client, TRIVIAL_TIMEOUT, &ss_sum_struct, &c, a, b);
	if (ret < 0) {
		goto error;
	}
	printf("%i + %i = %i\n", a, b, c);
	usleep(500*1000);

	rt_in = 2.0;
	ret = minipc_call(client, TRIVIAL_TIMEOUT, &ss_sqrt_struct, &rt_out, rt_in);
	if (ret < 0) {
		goto error;
	}
	printf("sqrt(%lf) = %lf\n", rt_in, rt_out);
	usleep(500*1000);

	return 0;

 error:
	fprintf(stderr, "Error in rpc: %s\n", strerror(errno));
	exit(1);
}
Example #4
0
int halexp_client_try_connect(int retries, int timeout)
{
	hexp_port_list_t plist;
	
	for(;;) {
		hal_ch = minipc_client_create(WRSW_HAL_SERVER_ADDR, MINIPC_FLAG_VERBOSE);
		if (hal_ch == 0)
			retries--;
		else 
			return 0;
		
		if(!retries)
			return -1;
			
		usleep(timeout);
	}

	return -1;
}
Example #5
0
/* No arguments */
int main(int argc, char **argv)
{
	struct minipc_ch *server;
	struct minipc_ch *client;
	void *shmem;
	int ret;

	if (argc > 1) {
		fprintf(stderr, "%s: no arguments please\n", argv[0]);
		exit(1);
	}

	/* Create your shared memory and/or attach to it */
	ret = shmget(MINIPC_SHM, sizeof(struct minipc_mbox_info),
		     IPC_CREAT | 0666);
	if (ret < 0) {
		fprintf(stderr, "%s: shmget(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}
	shmem = shmat(ret, NULL, SHM_RND);
	if (shmem == (void *)-1) {
		fprintf(stderr, "%s: shmat(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}
	info = shmem;

	/* Create a server socket for mini-ipc */
	server = minipc_server_create("mbox", 0);
	if (!server) {
		fprintf(stderr, "%s: server_create(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}
	minipc_set_logfile(server, stderr);
	minipc_export(server, &mb_stat_struct);

	/* Connect as a client to the trivial-server */
	client = minipc_client_create("trivial", 0);
	if (!client) {
		fprintf(stderr, "%s: client_create(): %s\n", argv[0],
			strerror(errno));
		exit(1);
	}

	/* Loop serving both mini-ipc and the mailbox */
	while (1) {
		fd_set set;
		struct timeval to = {
			MBOX_POLL_US / (1000*1000),
			MBOX_POLL_US % (1000*1000)
		};

		minipc_server_get_fdset(server, &set);

		/* Wait for any server, with the defined timeout */
		ret = select(16 /* hack */, &set, NULL, NULL, &to);

		if (ret > 0) {
			if (minipc_server_action(server, 0) < 0) {
				fprintf(stderr, "%s: server_action(): %s\n",
					argv[0], strerror(errno));
				exit(1);
			}
		}

		/* No IPC request: if needed act as IPC client */
		if (info->proc_req) {
			memset(&info->tv, 0, sizeof(info->tv));
			minipc_call(client, 100 /* ms */,
				    &mb_tod_struct, &info->tv, NULL);
			info->proc_req = 0;
		}
	}
}