Revision 4136911a

View differences:

dumbstreamer.c
64 64
  struct nodeID *myID;
65 65
  char *my_addr = iface_addr(my_iface);
66 66

  
67
  myID = create_socket(my_addr, port);
68
  if (myID == NULL || getFD(myID) == -1) {
67
  myID = net_helper_init(my_addr, port);
68
  if (myID == NULL) {
69 69
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
70 70
    free(my_addr);
71

  
71 72
    return NULL;
72 73
  }
73 74
  free(my_addr);
......
90 91
  if (srv_port != 0) {
91 92
    struct nodeID *srv;
92 93

  
93
    srv = create_socket(srv_ip, srv_port);
94
    srv = create_node(srv_ip, srv_port);
94 95
    if (srv == NULL) {
95 96
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
96 97

  
loop-mt.c
40 40
    struct nodeID *remote;
41 41
  static uint8_t buff[BUFFSIZE];
42 42

  
43
    len = recv_data(s, &remote, buff, BUFFSIZE);
43
    len = recv_from_peer(s, &remote, buff, BUFFSIZE);
44 44
    switch (buff[0] /* Message Type */) {
45 45
      case MSG_TYPE_TOPOLOGY:
46 46
        pthread_mutex_lock(&topology_mutex);
......
66 66
    struct nodeID *remote;
67 67
  static uint8_t buff[BUFFSIZE];
68 68

  
69
    len = recv_data(s, &remote, buff, BUFFSIZE);
69
    len = recv_from_peer(s, &remote, buff, BUFFSIZE);
70 70
    switch (buff[0] /* Message Type */) {
71 71
      case MSG_TYPE_TOPOLOGY:
72 72
        pthread_mutex_lock(&topology_mutex);
loop.c
31 31
  }
32 32
}
33 33

  
34
static int wait4data(struct nodeID *s)
35
{
36
  fd_set fds;
37
  int res;
38
  struct timeval tv;
39
  int fd = getFD(s);
40

  
41
  FD_ZERO(&fds);
42
  FD_SET(fd, &fds);
43
  tout_init(&tv);
44
  res = select(fd + 1, &fds, NULL, NULL, &tv);
45
  if (FD_ISSET(fd, &fds)) {
46
    return fd;
47
  }
48

  
49
  return -1;
50
}
51

  
52 34
void loop(struct nodeID *s, int csize, int buff_size)
53 35
{
54 36
  int done = 0;
......
61 43
  topParseData(NULL, 0);
62 44
  stream_init(buff_size, s);
63 45
  while (!done) {
64
    int len;
65
    int fd;
46
    int len, res;
47
    struct timeval tv;
66 48

  
67
    fd = wait4data(s);
68
    if (fd > 0) {
49
    tout_init(&tv);
50
    res = wait4data(s, tv);
51
    if (res > 0) {
69 52
      struct nodeID *remote;
70 53

  
71
      len = recv_data(s, &remote, buff, BUFFSIZE);
54
      len = recv_from_peer(s, &remote, buff, BUFFSIZE);
72 55
      switch (buff[0] /* Message Type */) {
73 56
        case MSG_TYPE_TOPOLOGY:
74 57
          topParseData(buff, len);
......
107 90
  
108 91
  source_init(fname, s);
109 92
  while (!done) {
110
    int len;
111
    int fd;
93
    int len, res;
94
    struct timeval tv;
112 95

  
113
    fd = wait4data(s);
114
    if (fd > 0) {
96
    tout_init(&tv);
97
    res = wait4data(s, tv);
98
    if (res > 0) {
115 99
      struct nodeID *remote;
116 100

  
117
      len = recv_data(s, &remote, buff, BUFFSIZE);
101
      len = recv_from_peer(s, &remote, buff, BUFFSIZE);
118 102
      switch (buff[0] /* Message Type */) {
119 103
        case MSG_TYPE_TOPOLOGY:
120 104
          fprintf(stderr, "Top Parse\n");

Also available in: Unified diff