Statistics
| Branch: | Tag: | Revision:

dvbd / inputbuffer.cpp @ bfdb7446

History | View | Annotate | Download (1.37 KB)

1
/*
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

    
22
InputBuffer::InputBuffer(int fd, int initSize, int maxSize)
23
  : CircularBuffer(initSize, maxSize), fd(fd)
24
{
25
}
26

    
27
InputBuffer::~InputBuffer()
28
{
29
}
30

    
31
void InputBuffer::addSelectFDs(Select &s) const
32
{
33
  s.addReadFD(fd);
34
}
35

    
36
bool InputBuffer::isReady(const Select &s) const
37
{
38
  return s.readyToRead(fd);
39
}
40

    
41
bool InputBuffer::process()
42
{
43
  int spaceAvailable = getMaxSize() - getUsed();
44

    
45
  if (spaceAvailable == 0) {
46
    setOverflowed();
47
    return true;
48
  }
49

    
50
  char data[spaceAvailable];
51
  int bytesRead = ::read(fd, data, spaceAvailable);
52
  if (bytesRead <= 0)
53
    return false;
54

    
55
  write(data, bytesRead);
56
  return true;
57
}