Revision 0ef85829

View differences:

chunk_puller_stdin.c
1
#include <pthread.h>
2
#include <stdint.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5

  
6
#define MAX_SIZE 512000
7

  
8
static void *receive(void *dummy)
9
{
10
  char msg[MAX_SIZE];
11
  while (1) {
12
    int32_t msg_size;
13
    int32_t p = 0;
14
    read(0, &msg, 5);
15
    read(0, &msg_size, sizeof(msg_size));
16
fprintf(stderr, "Reading chunk of size %d\n", msg_size);
17
    if (msg_size > MAX_SIZE) {
18
      fprintf(stderr, "chunk too big (%d bytes)\n", msg_size);
19
      exit(1);
20
    } else {
21
      while (p <  msg_size) {
22
        int r = read(0, &msg + p, msg_size - p);
23
        if (r >= 0) {
24
          p += r;
25
        }
26
      }
27
      enqueueBlock(msg, msg_size); //this might take some time
28
    }
29
  }
30
}
31

  
32
void *initChunkPuller() {
33
  pthread_t stdin_thread;
34
  pthread_create(&stdin_thread, NULL, receive, NULL); 
35
  pthread_join(stdin_thread, NULL);
36

  
37
}
38

  
39
void finalizeChunkPuller(void *d) {
40
}
41

  

Also available in: Unified diff