Revision 54b631d9

View differences:

Makefile
26 26
LDFLAGS = -L$(GRAPES)/som/TopologyManager -L$(GRAPES)/som/ChunkTrading -L$(GRAPES)/som/ChunkBuffer
27 27
LDLIBS = -ltrading -lcb -ltopman
28 28

  
29
OBJS = dumbstreamer.o streaming.o output.o net_helpers.o input.o
29
OBJS = dumbstreamer.o streaming.o output.o net_helpers.o input.o out-stream.o
30 30
ifdef THREADS
31 31
OBJS += loop-mt.o
32 32
CFLAGS += -pthread
out-stream.c
1
#include <unistd.h>
2
#include <stdint.h>
3
#include <stdio.h>
4

  
5
#include "out-stream.h"
6
#include "dbg.h"
7

  
8
static int outfd = 1;
9

  
10
void chunk_write(int id, const uint8_t *data, int size)
11
{
12
#ifdef DEBUG
13
#define buff_size 8 // HACK!
14
    fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", id, id % buff_size, data);
15
#else
16
    write(outfd, data, size);
17
#endif
18
}
out-stream.h
1
void chunk_write(int id, const uint8_t *data, int size);
2

  
output.c
6 6

  
7 7
#include <chunk.h>
8 8

  
9
#include "out-stream.h"
9 10
#include "dbg.h"
10 11

  
11 12
#define SIZE 8
12 13

  
13 14
static int next_chunk;
14
static int outfd = 1;
15 15
static int buff_size = SIZE;
16 16

  
17 17
static struct {
......
22 22

  
23 23
void buffer_free(int i)
24 24
{
25
#ifdef DEBUG
26
  fprintf(stderr, "\t\tFlush Buf %d: %s\n", i, buff[i].data);
27
#else
28
  write(outfd, buff[i].data, buff[i].size);
29
#endif
25
  dprintf(stderr, "\t\tFlush Buf %d: %s\n", i, buff[i].data);
26
  chunk_write(i, buff[i].data, buff[i].size);
30 27
  free(buff[i].data);
31 28
  buff[i].data = NULL;
32 29
  dprintf("Next Chunk: %d -> %d\n", next_chunk, buff[i].id + 1);
......
72 69

  
73 70
  dprintf("%d == %d?\n", c->id, next_chunk);
74 71
  if (c->id == next_chunk) {
75
#ifdef DEBUG
76
    fprintf(stderr, "\tOut Chunk[%d] - %d: %s\n", c->id, c->id % buff_size, c->data);
77
#else
78
    write(outfd, c->data, c->size);
79
#endif
72
    chunk_write(c->id, c->data, c->size);
80 73
    next_chunk++;
81 74
    buffer_flush(next_chunk);
82 75
  } else {

Also available in: Unified diff