blob: b7f6cb01548bbb1e6699664a6b1fdb2b955c4e19 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossman3c837132011-11-15 12:07:43 +00002 * Copyright 2011 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20//
21// FdOutStream streams to a file descriptor.
22//
23
24#ifndef __RDR_FDOUTSTREAM_H__
25#define __RDR_FDOUTSTREAM_H__
26
Pierre Ossman3c837132011-11-15 12:07:43 +000027#include <sys/time.h>
28
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000029#include <rdr/OutStream.h>
30
31namespace rdr {
32
33 class FdOutStream : public OutStream {
34
35 public:
36
Pierre Ossman4ce51ff2011-10-25 15:13:13 +000037 FdOutStream(int fd, bool blocking=true, int timeoutms=-1, int bufSize=0);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000038 virtual ~FdOutStream();
39
40 void setTimeout(int timeoutms);
Pierre Ossman4ce51ff2011-10-25 15:13:13 +000041 void setBlocking(bool blocking);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000042 int getFd() { return fd; }
43
44 void flush();
45 int length();
46
Pierre Ossman4ce51ff2011-10-25 15:13:13 +000047 int bufferUsage();
48
Pierre Ossman3c837132011-11-15 12:07:43 +000049 unsigned getIdleTime();
50
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000051 private:
52 int overrun(int itemSize, int nItems);
Pierre Ossman4ce51ff2011-10-25 15:13:13 +000053 int writeWithTimeout(const void* data, int length, int timeoutms);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000054 int fd;
Pierre Ossman4ce51ff2011-10-25 15:13:13 +000055 bool blocking;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000056 int timeoutms;
57 int bufSize;
58 int offset;
59 U8* start;
Pierre Ossman4ce51ff2011-10-25 15:13:13 +000060 U8* sentUpTo;
Pierre Ossman3c837132011-11-15 12:07:43 +000061 struct timeval lastWrite;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000062 };
63
64}
65
66#endif