Revision 4cdd16a7 src/Chunkiser/input-stream-dumb.c

View differences:

src/Chunkiser/input-stream-dumb.c
16 16
#include "config.h"
17 17

  
18 18
struct chunkiser_ctx {
19
  int fd;
20 19
  int chunk_size;
20
  int fds[2];
21 21
};
22 22
#define DEFAULT_CHUNK_SIZE 2 * 1024
23 23

  
......
31 31
    return NULL;
32 32
  }
33 33

  
34
  res->fd = open(fname, O_RDONLY);
35
  if (res->fd < 0) {
34
  res->fds[0] = open(fname, O_RDONLY);
35
  if (res->fds[0] < 0) {
36 36
    free(res);
37 37

  
38 38
    return NULL;
39 39
  }
40
  res->fds[1] = -1;
40 41

  
41 42
  *period = 0;
42 43
  res->chunk_size = DEFAULT_CHUNK_SIZE;
......
47 48
    config_value_int(cfg_tags, "chunk_size", &res->chunk_size);
48 49
    access_mode = config_value_str(cfg_tags, "mode");
49 50
    if (!strcmp(access_mode, "nonblock")) {
50
      fcntl(res->fd, F_SETFL, O_NONBLOCK);
51
      fcntl(res->fds[0], F_SETFL, O_NONBLOCK);
51 52
    }
52 53
  }
53 54
  free(cfg_tags);
......
57 58

  
58 59
static void dumb_close(struct chunkiser_ctx *s)
59 60
{
60
  close(s->fd);
61
  close(s->fds[0]);
61 62
  free(s);
62 63
}
63 64

  
......
72 73
    return NULL;
73 74
  }
74 75
  *ts = 0;
75
  *size = read(s->fd, res, s->chunk_size);
76
  *size = read(s->fds[0], res, s->chunk_size);
76 77

  
77 78
  return res;
78 79
}
79 80

  
81
const int *dumb_get_fds(const struct chunkiser_ctx *s)
82
{
83
  return s->fds;
84
}
85

  
80 86
struct chunkiser_iface in_dumb = {
81 87
  .open = dumb_open,
82 88
  .close = dumb_close,
83 89
  .chunkise = dumb_chunkise,
90
  .get_fds = dumb_get_fds,
84 91
};
85 92

  
86 93

  

Also available in: Unified diff