source: trunk/packages/vizservers/vtkvis/ReadBuffer.h @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • 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#ifndef _READBUFFER_H
11#define _READBUFFER_H
12
13namespace Rappture {
14namespace VtkVis {
15
16/**
17 * \brief Buffered input for reading socket
18 */
19class ReadBuffer
20{
21public:
22    enum BufferStatus {
23        ENDFILE=-1,
24        OK,
25        ERROR,
26        CONTINUE,
27    };
28
29    ReadBuffer(int fd, size_t bufferSize);
30
31    virtual ~ReadBuffer();
32
33    BufferStatus getLine(size_t *numBytesPtr, unsigned char **bytesPtr);
34
35    BufferStatus followingData(unsigned char *out, size_t numBytes);
36
37    /**
38     * \brief Check if buffer contains data ending in a newline
39     *
40     * \return bool indicating if getLine can be called without blocking
41     */
42    bool isLineAvailable()
43    {
44        return (nextNewLine() > 0);
45    }
46
47    /**
48     * \brief Get the file descriptor this object reads from
49     */
50    int file()
51    {
52        return _fd;
53    }
54
55    /**
56     * \brief Get the status of the last read
57     */
58    BufferStatus status()
59    {
60        return _lastStatus;
61    }
62
63private:
64    unsigned char *_bytes;              /**< New-ed buffer to hold read
65                                         * characters. */
66    size_t _bufferSize;                 /**< # of bytes allocated for buffer */
67    size_t _fill;                       /**< # of bytes used in the buffer */
68    size_t _mark;                       /**< Starting point of the unconsumed
69                                         * data in the buffer. */
70    int _fd;                            /**< File descriptor to get data. */
71    BufferStatus _lastStatus;           /**< Status of last read operation. */
72
73    BufferStatus doFill();
74
75    void flush()
76    {
77        _fill = _mark = 0;
78    }
79
80    size_t nextNewLine();
81};
82
83}
84}
85
86#endif /* _READBUFFER_H */
Note: See TracBrowser for help on using the repository browser.