PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/mordor/streams/namedpipe.h

http://github.com/mozy/mordor
C Header | 54 lines | 29 code | 15 blank | 10 comment | 0 complexity | 4a0792f975c38096b59c48019d3f409c MD5 | raw file
 1#ifndef __MORDOR_NAMEDPIPE_STREAM_H__
 2#define __MORDOR_NAMEDPIPE_STREAM_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include "handle.h"
 6
 7namespace Mordor {
 8
 9class NamedPipeStream : public HandleStream
10{
11public:
12    typedef boost::shared_ptr<NamedPipeStream> ptr;
13
14    enum Flags {
15        READ = PIPE_ACCESS_INBOUND,
16        WRITE = PIPE_ACCESS_OUTBOUND,
17        READWRITE = PIPE_ACCESS_DUPLEX
18    };
19
20public:
21
22    // Currently this class only supports the Server side of a named pipe connection
23    // It creates a new pipe based on the passed name argument.
24    // By default a byte-mode pipe is created (PIPE_TYPE_BYTE), but the pipeModeFlags
25    // argument can be used to create a message-mode pipe.
26    NamedPipeStream(const std::string &name, Flags flags = READWRITE, IOManager *ioManager = NULL, Scheduler *scheduler = NULL, DWORD pipeModeFlags = (DWORD)-1);
27    NamedPipeStream(const std::wstring &name, Flags flags = READWRITE, IOManager *ioManager = NULL, Scheduler *scheduler = NULL, DWORD pipeModeFlags = (DWORD)-1);
28
29    bool supportsRead() { return m_supportsRead; }
30    bool supportsWrite() { return m_supportsWrite; }
31    bool supportsSeek() { return false; }
32
33    void close(CloseType type = BOTH);
34
35    // Close a connected client if any, but leave the named pipe open.
36    // Should be called after processing a client request and before
37    // calling accept to wait for the next connection.
38    void disconnectClient();
39
40    // Accept will put the fiber to sleep until a client connection arrives
41    // Throws OperationAbortedException if another fiber calls cancelAccept()
42    void accept();
43
44    void cancelAccept();
45
46private:
47    void init(const std::wstring &name, Flags flags, DWORD pipeModeFlags, IOManager *ioManager, Scheduler *scheduler);
48
49    bool m_supportsRead, m_supportsWrite;
50};
51
52}
53
54#endif