Esempio n. 1
0
File: daemon.c Progetto: numpad/ipc
int main(int argc, char *argv[]) {
	
	ipc_server srv = ipc_create("echo_socket");
	
	char buf[128];
	while (1) {
		/* call accept */
		puts("waiting for connection");
		ipc_server_accept(&srv);
		puts("connected!");

		/* handle connection and loop back to accept*/
		while (ipc_server_read(&srv, buf, 128)) {
			printf("-> '%.*s'\n", srv.msglen - 1, buf);
			if (!strncmp(buf, "end", 3)) {
				puts("closing");
				ipc_server_close(srv);
				exit(0);
			}

			ipc_server_send(&srv, buf, srv.msglen);
		}
		puts("client closed connection");
	}

	return 0;
}
Esempio n. 2
0
/* For reading data from a socket - use it in the module task. */
int ipc_accept_buf_read(int server_fd, void *data, int data_len)
{
    int fd, rc;
    
    if ((fd = ipc_accept(server_fd)) < 0)
	return -1;
    rc = ipc_read(fd, data, data_len);
    ipc_server_close(fd, rc);
    return rc;
}