Last change
on this file since 5516 was
4882,
checked in by ldelgass, 10 years ago
|
set eol-style on new files
|
-
Property svn:eol-style set to
native
|
File size:
1.7 KB
|
Line | |
---|
1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2004-2012 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Author: George A. Howlett <gah@purdue.edu> |
---|
6 | */ |
---|
7 | |
---|
8 | #include <cstdlib> |
---|
9 | |
---|
10 | #include <RpBuffer.h> |
---|
11 | |
---|
12 | #ifndef NV_READBUFFER_H |
---|
13 | #define NV_READBUFFER_H |
---|
14 | |
---|
15 | namespace nv { |
---|
16 | |
---|
17 | /** |
---|
18 | * \brief Buffered input for reading socket |
---|
19 | */ |
---|
20 | class ReadBuffer |
---|
21 | { |
---|
22 | public: |
---|
23 | enum BufferStatus { |
---|
24 | ENDFILE=-1, |
---|
25 | OK, |
---|
26 | ERROR, |
---|
27 | CONTINUE, |
---|
28 | }; |
---|
29 | |
---|
30 | ReadBuffer(int fd, size_t bufferSize); |
---|
31 | |
---|
32 | virtual ~ReadBuffer(); |
---|
33 | |
---|
34 | BufferStatus getLine(size_t *numBytesPtr, unsigned char **bytesPtr); |
---|
35 | |
---|
36 | BufferStatus followingData(unsigned char *out, size_t numBytes); |
---|
37 | |
---|
38 | /** |
---|
39 | * \brief Check if buffer contains data ending in a newline |
---|
40 | * |
---|
41 | * \return bool indicating if getLine can be called without blocking |
---|
42 | */ |
---|
43 | bool isLineAvailable() |
---|
44 | { |
---|
45 | return (nextNewLine() > 0); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * \brief Get the file descriptor this object reads from |
---|
50 | */ |
---|
51 | int file() |
---|
52 | { |
---|
53 | return _fd; |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * \brief Get the status of the last read |
---|
58 | */ |
---|
59 | BufferStatus status() |
---|
60 | { |
---|
61 | return _lastStatus; |
---|
62 | } |
---|
63 | |
---|
64 | private: |
---|
65 | unsigned char *_bytes; /**< New-ed buffer to hold read |
---|
66 | * characters. */ |
---|
67 | size_t _bufferSize; /**< # of bytes allocated for buffer */ |
---|
68 | size_t _fill; /**< # of bytes used in the buffer */ |
---|
69 | size_t _mark; /**< Starting point of the unconsumed |
---|
70 | * data in the buffer. */ |
---|
71 | int _fd; /**< File descriptor to get data. */ |
---|
72 | BufferStatus _lastStatus; /**< Status of last read operation. */ |
---|
73 | |
---|
74 | BufferStatus doFill(); |
---|
75 | |
---|
76 | void flush() |
---|
77 | { |
---|
78 | _fill = _mark = 0; |
---|
79 | } |
---|
80 | |
---|
81 | size_t nextNewLine(); |
---|
82 | }; |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.