Statistics
| Branch: | Revision:

chunker-player / chunk_puller_nh.c @ bd209760

History | View | Annotate | Download (1.62 KB)

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

    
6
#include <net_helper.h>
7
#include <msg_types.h>
8

    
9
#define MY_IP "127.0.0.1"
10
#define MY_PORT 8888
11

    
12
#define BUFFSIZE 1024000
13

    
14
static struct nodeID *myID;
15

    
16
int init_net_helper() {
17
  myID = net_helper_init(MY_IP,MY_PORT);
18
  if(! myID) {
19
    fprintf(stderr,"Error initializing net_helper: port %d used by something else?", MY_PORT);
20
    return -1;
21
  }
22
  bind_msg_type(MSG_TYPE_CHUNK);
23
  return 1;
24
}
25

    
26
static void *receive(void *dummy)
27
{
28
fprintf(stderr,"receive called\n");
29
  while (1) {
30
    int len;
31
    struct nodeID *remote;
32
    static uint8_t buff[BUFFSIZE];
33

    
34
//fprintf(stderr,"calling recv_from_peer\n");
35
    len = recv_from_peer(myID, &remote, buff, BUFFSIZE);
36
//fprintf(stderr,"recv_from_peer returned\n");
37
    if (len < 0) {
38
      fprintf(stderr,"Error receiving message. Maybe larger than %d bytes\n", BUFFSIZE);
39
      nodeid_free(remote);
40
      continue;
41
    }
42
    //dprintf("Received message (%c) from %s\n", buff[0], node_addr(remote));
43
//fprintf(stderr,"msglen: %d\n", len);
44
//fprintf(stderr,"msgtype: %x\n", buff[0]);
45
    switch (buff[0] /* Message Type */) {
46
      case MSG_TYPE_CHUNK:
47
if(len>510000) {
48
fprintf(stderr,"warning: big message %d\n", len);
49
}
50
        enqueueBlock(buff+1, len-1);
51
        break;
52
      default:
53
        fprintf(stderr, "Unknown Message Type %x\n", buff[0]);
54
    }
55
    nodeid_free(remote);
56
  }
57

    
58
  return NULL;
59
}
60

    
61
void *initChunkPuller() {
62
  pthread_t stdin_thread;
63
  if (! init_net_helper()) {
64
    return;
65
  }
66
  pthread_create(&stdin_thread, NULL, receive, NULL); 
67
//  pthread_join(stdin_thread, NULL);
68

    
69
}
70

    
71
void finalizeChunkPuller(void *d) {
72
}
73