2 /// \file brawchannel.h
3 /// Directs a named raw channel over STDIN/STDOUT or TCP
7 Copyright (C) 2010-2012, RealVNC Ltd.
9 Some parts are inspired from bjavaloader.cc
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #ifndef __BARRY_TOOLS_BRAWCHANNEL_H__
25 #define __BARRY_TOOLS_BRAWCHANNEL_H__
27 #include <sys/types.h>
31 // How long, in seconds, to wait between reads before checking if should shutdown
32 #define READ_TIMEOUT_SECONDS 1
34 /* Defined generic stream reading and writing classes.
36 * It'd be great to use iostream, but they don't provide non-blocking reads.
45 virtual ~InputStream() {};
46 virtual ssize_t
read(unsigned char* ptr
, size_t size
, int timeout
) = 0;
51 virtual ~OutputStream() {};
52 virtual ssize_t
write(const unsigned char* ptr
, size_t size
) = 0;
55 class StdOutStream
: public OutputStream
{
57 virtual ssize_t
write(const unsigned char* ptr
, size_t size
);
60 class StdInStream
: public InputStream
{
62 virtual ssize_t
read(unsigned char* ptr
, size_t size
, int timeout
);
65 // Forward declaration of platform implementation details
68 class TcpStream
: public Stream
{
70 std::auto_ptr
<TcpStreamImpl
> mImpl
;
72 TcpStream(const std::string
& addr
, long port
);
77 class TcpInStream
: public InputStream
{
81 TcpInStream(TcpStream
& stream
)
83 virtual ssize_t
read(unsigned char* ptr
, size_t size
, int timeout
);
86 class TcpOutStream
: public OutputStream
{
90 TcpOutStream(TcpStream
& stream
)
93 virtual ssize_t
write(const unsigned char* ptr
, size_t size
);
96 #endif // __BARRY_TOOLS_BRAWCHANNEL_H__