Statistics
| Branch: | Revision:

chunker-player / chunker_player / chunk_puller_stdin.c @ 74564eb3

History | View | Annotate | Download (1.05 KB)

1 01f952d0 GiuseppeTropea
/*
2
 *  Copyright (c) 2009-2011 Carmelo Daniele, Dario Marchese, Diego Reforgiato, Giuseppe Tropea
3
 *  developed for the Napa-Wine EU project. See www.napa-wine.eu
4
 *
5
 *  This is free software; see lgpl-2.1.txt
6
 */
7
8 0ef85829 CsabaKiraly
#include <pthread.h>
9
#include <stdint.h>
10
#include <stdio.h>
11
#include <stdlib.h>
12
13
#define MAX_SIZE 512000
14
15
static void *receive(void *dummy)
16
{
17
  char msg[MAX_SIZE];
18
  while (1) {
19
    int32_t msg_size;
20
    int32_t p = 0;
21
    read(0, &msg, 5);
22
    read(0, &msg_size, sizeof(msg_size));
23
fprintf(stderr, "Reading chunk of size %d\n", msg_size);
24
    if (msg_size > MAX_SIZE) {
25
      fprintf(stderr, "chunk too big (%d bytes)\n", msg_size);
26
      exit(1);
27
    } else {
28
      while (p <  msg_size) {
29
        int r = read(0, &msg + p, msg_size - p);
30
        if (r >= 0) {
31
          p += r;
32
        }
33
      }
34
      enqueueBlock(msg, msg_size); //this might take some time
35
    }
36
  }
37
}
38
39
void *initChunkPuller() {
40
  pthread_t stdin_thread;
41
  pthread_create(&stdin_thread, NULL, receive, NULL); 
42
  pthread_join(stdin_thread, NULL);
43
44
}
45
46
void finalizeChunkPuller(void *d) {
47
}