Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 3c83713 | 2011-11-15 12:07:43 +0000 | [diff] [blame] | 2 | * Copyright 2011 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 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 Ossman | 3c83713 | 2011-11-15 12:07:43 +0000 | [diff] [blame] | 27 | #include <sys/time.h> |
| 28 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 29 | #include <rdr/OutStream.h> |
| 30 | |
| 31 | namespace rdr { |
| 32 | |
| 33 | class FdOutStream : public OutStream { |
| 34 | |
| 35 | public: |
| 36 | |
Pierre Ossman | 4ce51ff | 2011-10-25 15:13:13 +0000 | [diff] [blame] | 37 | FdOutStream(int fd, bool blocking=true, int timeoutms=-1, int bufSize=0); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 38 | virtual ~FdOutStream(); |
| 39 | |
| 40 | void setTimeout(int timeoutms); |
Pierre Ossman | 4ce51ff | 2011-10-25 15:13:13 +0000 | [diff] [blame] | 41 | void setBlocking(bool blocking); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 42 | int getFd() { return fd; } |
| 43 | |
| 44 | void flush(); |
| 45 | int length(); |
| 46 | |
Pierre Ossman | 4ce51ff | 2011-10-25 15:13:13 +0000 | [diff] [blame] | 47 | int bufferUsage(); |
| 48 | |
Pierre Ossman | 3c83713 | 2011-11-15 12:07:43 +0000 | [diff] [blame] | 49 | unsigned getIdleTime(); |
| 50 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 51 | private: |
| 52 | int overrun(int itemSize, int nItems); |
Pierre Ossman | 4ce51ff | 2011-10-25 15:13:13 +0000 | [diff] [blame] | 53 | int writeWithTimeout(const void* data, int length, int timeoutms); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 54 | int fd; |
Pierre Ossman | 4ce51ff | 2011-10-25 15:13:13 +0000 | [diff] [blame] | 55 | bool blocking; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 56 | int timeoutms; |
| 57 | int bufSize; |
| 58 | int offset; |
| 59 | U8* start; |
Pierre Ossman | 4ce51ff | 2011-10-25 15:13:13 +0000 | [diff] [blame] | 60 | U8* sentUpTo; |
Pierre Ossman | 3c83713 | 2011-11-15 12:07:43 +0000 | [diff] [blame] | 61 | struct timeval lastWrite; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |