source: trunk/packages/vizservers/geovis/ReadBuffer.h @ 3998

Last change on this file since 3998 was 3998, checked in by ldelgass, 11 years ago

Add prelimilary skeleton for geovis map rendering server. Not functional, not
integrated into configure, etc.

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