view examples/filesend/reader.c @ 85:d0d8aeaebccf

add routing table
author one
date Mon, 08 Feb 2010 11:07:57 +0900
parents ad401b7c97bb
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <arpa/inet.h>

#include "lindaapi.h"

#define PORT 10000

void
mainLoop(unsigned int tid, int read_id, FILE* out)
{
	unsigned int rd_seq;
	unsigned char *tuple, *data;
	int len;

	/* すでにデータが書き込まれた状態で動くこと  */
	rd_seq = psx_rd(tid, read_id);
	psx_sync_n();

	while (1) {
		int count;
		tuple = psx_reply(rd_seq);
		if (tuple) {
			len = psx_get_datalength(tuple);
			data = tuple+LINDA_HEADER_SIZE;

			count=0;
			while (count<len) {
				count += fwrite(data+count, 1, len-count, out);
			}
			free(tuple);
			break;

		}
		usleep(500000);
	}

	return;
}


int
main(int argc, char *argv[]) {
	int len = 0;
	int tspace;

	init_linda();
	tspace = open_linda_java("localhost", PORT);
	//printf("open socket (tupple space id) = %d\n", tspace);

	mainLoop(tspace, 10, stdout);

	//printf("mainLoop finished\n");
	exit(EXIT_SUCCESS);
}