Statistics
| Branch: | Revision:

streamers / dumbstreamer.c @ 568bd1bd

History | View | Annotate | Download (2.08 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
  myID = create_socket(my_addr, port);
68
  if (myID == NULL || getFD(myID) == -1) {
69
    fprintf(stderr, "Error creating my socket (%s:%d)!\n", my_addr, port);
70
    free(my_addr);
71
    return NULL;
72
  }
73
  free(my_addr);
74
  topInit(myID);
75

    
76
  return myID;
77
}
78

    
79

    
80
int main(int argc, char *argv[])
81
{
82
  struct nodeID *my_sock;
83

    
84
  cmdline_parse(argc, argv);
85

    
86
  my_sock = init();
87
  if (my_sock == NULL) {
88
    return -1;
89
  }
90
  if (srv_port != 0) {
91
    struct nodeID *srv;
92

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

    
97
      return -1;
98
    }
99
    topAddNeighbour(srv);
100

    
101
    loop(my_sock, 1000000 / chunks_per_second, buff_size);
102
  }
103

    
104
  source_loop(fname, my_sock, period * 1000, chunks_per_second * period / 1000);
105

    
106
  return 0;
107
}