PageRenderTime 184ms CodeModel.GetById 175ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/streams/fd.h

http://github.com/mozy/mordor
C Header | 58 lines | 44 code | 13 blank | 1 comment | 0 complexity | e376b95613fc22300b5455223d35d18a MD5 | raw file
 1#ifndef __MORDOR_FD_STREAM_H__
 2#define __MORDOR_FD_STREAM_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include "stream.h"
 6
 7namespace Mordor {
 8
 9class IOManager;
10class Scheduler;
11
12class FDStream : public Stream
13{
14public:
15    typedef boost::shared_ptr<FDStream> ptr;
16
17protected:
18    FDStream();
19    void init(int fd, IOManager *ioManager = NULL, Scheduler *scheduler = NULL,
20        bool own = true);
21public:
22    FDStream(int fd, IOManager *ioManager = NULL, Scheduler *scheduler = NULL,
23        bool own = true)
24    { init(fd, ioManager, scheduler, own); }
25    ~FDStream();
26
27    bool supportsRead() { return true; }
28    bool supportsWrite() { return true; }
29    bool supportsSeek() { return true; }
30    bool supportsSize() { return true; }
31    bool supportsTruncate() { return true; }
32
33    void close(CloseType type = BOTH);
34    size_t read(Buffer &buffer, size_t length);
35    size_t read(void *buffer, size_t length);
36    size_t write(const Buffer &buffer, size_t length);
37    size_t write(const void *buffer, size_t length);
38    long long seek(long long offset, Anchor anchor = BEGIN);
39    long long size();
40    void truncate(long long size);
41    void flush(bool flushParent = true);
42
43    int fd() { return m_fd; }
44
45private:
46    IOManager *m_ioManager;
47    Scheduler *m_scheduler;
48    int m_fd;
49    bool m_own;
50};
51
52typedef FDStream NativeStream;
53typedef int NativeHandle;
54
55}
56
57#endif
58