Statistics
| Branch: | Tag: | Revision:

dvbd / src / inputbuffer.cpp @ e386e4be

History | View | Annotate | Download (1.41 KB)

1 bfdb7446 jak
/*
2
  Copyright 2003 John Knottenbelt
3
  
4
  This program is free software; you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation; either version 2 of the License, or
7
  (at your option) any later version.
8
 
9
  This program is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
 
14
  You should have received a copy of the GNU General Public License
15
  along with this program; if not, write to the Free Software
16
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17
*/
18
19
#include "inputbuffer.h"
20
#include <unistd.h>
21 e386e4be jak
#include <cerrno>
22 bfdb7446 jak
23
InputBuffer::InputBuffer(int fd, int initSize, int maxSize)
24
  : CircularBuffer(initSize, maxSize), fd(fd)
25
{
26
}
27
28
InputBuffer::~InputBuffer()
29
{
30
}
31
32
void InputBuffer::addSelectFDs(Select &s) const
33
{
34
  s.addReadFD(fd);
35
}
36
37
bool InputBuffer::isReady(const Select &s) const
38
{
39
  return s.readyToRead(fd);
40
}
41
42
bool InputBuffer::process()
43
{
44
  int spaceAvailable = getMaxSize() - getUsed();
45
46
  if (spaceAvailable == 0) {
47
    setOverflowed();
48
    return true;
49
  }
50
51
  char data[spaceAvailable];
52 e386e4be jak
  int bytesRead;
53
54
  bytesRead = ::read(fd, data, spaceAvailable);
55 bfdb7446 jak
  if (bytesRead <= 0)
56 e386e4be jak
    return errno == EAGAIN;
57 bfdb7446 jak
58
  write(data, bytesRead);
59
  return true;
60
}