Statistics
| Branch: | Revision:

streamers / dumbstreamer.c @ f858e682

History | View | Annotate | Download (2.17 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_iface = "eth0";
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
static int buff_size = 8;
25
static const char *fname = "input.mpg";
26

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

    
31
  while ((o = getopt(argc, argv, "b:c:t:p:i:P:I:")) != -1) {
32
    switch(o) {
33
      case 'b':
34
        buff_size = atoi(optarg);
35
        break;
36
      case 'c':
37
        chunks_per_second = atoi(optarg);
38
        break;
39
      case 't':
40
        period = atoi(optarg);
41
        break;
42
      case 'p':
43
        srv_port = atoi(optarg);
44
        break;
45
      case 'i':
46
        srv_ip = strdup(optarg);
47
        break;
48
      case 'P':
49
        port =  atoi(optarg);
50
        break;
51
      case 'I':
52
        my_iface = strdup(optarg);
53
        break;
54
      default:
55
        fprintf(stderr, "Error: unknown option %c\n", o);
56

    
57
        exit(-1);
58
    }
59
  }
60
}
61

    
62
static struct nodeID *init(void)
63
{
64
  struct nodeID *myID;
65
  char *my_addr = iface_addr(my_iface);
66

    
67
  if (my_addr == NULL) {
68
    fprintf(stderr, "Cannot find network interface %s\n", my_iface);
69

    
70
    return NULL;
71
  }
72

    
73
  myID = net_helper_init(my_addr, port);
74
  if (myID == NULL) {
75
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
76
    free(my_addr);
77

    
78
    return NULL;
79
  }
80
  free(my_addr);
81
  topInit(myID);
82

    
83
  return myID;
84
}
85

    
86

    
87
int main(int argc, char *argv[])
88
{
89
  struct nodeID *my_sock;
90

    
91
  cmdline_parse(argc, argv);
92

    
93
  my_sock = init();
94
  if (my_sock == NULL) {
95
    return -1;
96
  }
97
  if (srv_port != 0) {
98
    struct nodeID *srv;
99

    
100
    srv = create_node(srv_ip, srv_port);
101
    if (srv == NULL) {
102
      fprintf(stderr, "Cannot resolve remote address %s:%d\n", srv_ip, srv_port);
103

    
104
      return -1;
105
    }
106
    topAddNeighbour(srv);
107

    
108
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
109
  }
110

    
111
  source_loop(fname, my_sock, period * 1000, chunks_per_second * period / 1000);
112

    
113
  return 0;
114
}