Statistics
| Branch: | Revision:

chunker-player / chunker_player / chunk_puller_nh.c @ 3262ed44

History | View | Annotate | Download (1.83 KB)

1
/*
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
#include <pthread.h>
9
#include <stdint.h>
10
#include <stdio.h>
11
#include <stdlib.h>
12

    
13
#include <net_helper.h>
14
#include <msg_types.h>
15

    
16
#define MY_IP "127.0.0.1"
17
#define MY_PORT 8888
18

    
19
#define BUFFSIZE 1024000
20

    
21
static struct nodeID *myID;
22

    
23
int init_net_helper() {
24
  myID = net_helper_init(MY_IP,MY_PORT);
25
  if(! myID) {
26
    fprintf(stderr,"Error initializing net_helper: port %d used by something else?", MY_PORT);
27
    return -1;
28
  }
29
  bind_msg_type(MSG_TYPE_CHUNK);
30
  return 1;
31
}
32

    
33
static void *receive(void *dummy)
34
{
35
fprintf(stderr,"receive called\n");
36
  while (1) {
37
    int len;
38
    struct nodeID *remote;
39
    static uint8_t buff[BUFFSIZE];
40

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

    
65
  return NULL;
66
}
67

    
68
void *initChunkPuller() {
69
  pthread_t stdin_thread;
70
  if (! init_net_helper()) {
71
    return;
72
  }
73
  pthread_create(&stdin_thread, NULL, receive, NULL); 
74
//  pthread_join(stdin_thread, NULL);
75

    
76
}
77

    
78
void finalizeChunkPuller(void *d) {
79
}
80