Statistics
| Branch: | Revision:

streamers / dumbstreamer.c @ 89e893e2

History | View | Annotate | Download (1.52 KB)

1
/*
2
 *  Copyright (c) 2009 Luca Abeni
3
 *
4
 *  This is free software; see GPL.txt
5
 */
6
#include <stdlib.h>
7
#include <stdint.h>
8
#include <stdio.h>
9
#include <string.h>
10
#include <getopt.h>
11

    
12
#include <net_helper.h>
13
#include <topmanager.h>
14

    
15
#include "net_helpers.h"
16
#include "loop.h"
17

    
18
static const char *my_addr = "127.0.0.1";
19
static int port = 6666;
20
static int srv_port;
21
static const char *srv_ip;
22
static int period = 500;
23
static int chunks_per_second = 4;
24

    
25
static void cmdline_parse(int argc, char *argv[])
26
{
27
  int o;
28

    
29
  while ((o = getopt(argc, argv, "p:i:P:I:")) != -1) {
30
    switch(o) {
31
      case 'p':
32
        srv_port = atoi(optarg);
33
        break;
34
      case 'i':
35
        srv_ip = strdup(optarg);
36
        break;
37
      case 'P':
38
        port =  atoi(optarg);
39
        break;
40
      case 'I':
41
        my_addr = iface_addr(optarg);
42
        break;
43
      default:
44
        fprintf(stderr, "Error: unknown option %c\n", o);
45

    
46
        exit(-1);
47
    }
48
  }
49
}
50

    
51
static struct nodeID *init(void)
52
{
53
  struct nodeID *myID;
54

    
55
  myID = create_socket(my_addr, port);
56
  if (myID == NULL) {
57
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
58
  }
59
  topInit(myID);
60

    
61
  return myID;
62
}
63

    
64

    
65
int main(int argc, char *argv[])
66
{
67
  struct nodeID *my_sock;
68

    
69
  cmdline_parse(argc, argv);
70

    
71
  my_sock = init();
72
  if (srv_port != 0) {
73
    struct nodeID *srv;
74

    
75
    srv = create_socket(srv_ip, srv_port);
76
    topAddNeighbour(srv);
77

    
78
    loop(my_sock, 1000000 / chunks_per_second);
79
  }
80

    
81
  source_loop(my_sock, period * 1000, chunks_per_second * period / 1000);
82

    
83
  return 0;
84
}