diff options
Diffstat (limited to 'src/mt/mread.h')
| -rw-r--r-- | src/mt/mread.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/mt/mread.h b/src/mt/mread.h new file mode 100644 index 0000000..11516a2 --- /dev/null +++ b/src/mt/mread.h | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifndef MREADH | ||
| 21 | #define MREADH | ||
| 22 | |||
| 23 | // These functions work with nonblocking pipes | ||
| 24 | // as well as normal devices, and does not produce | ||
| 25 | // any signals on pipe errors | ||
| 26 | |||
| 27 | #include <mt/mstring.h> | ||
| 28 | #include <unistd.h> | ||
| 29 | #include <fcntl.h> | ||
| 30 | |||
| 31 | class mread { | ||
| 32 | public: | ||
| 33 | mread(); | ||
| 34 | mread(int f); | ||
| 35 | |||
| 36 | void setfd(int f) { clear(); fd=f; } | ||
| 37 | int getfd() const { return fd; } | ||
| 38 | |||
| 39 | void setflag(int f) { fcntl(fd,F_SETFL,f); } | ||
| 40 | int getflag() const { return fcntl(fd,F_GETFL,0); } | ||
| 41 | |||
| 42 | // Basic, pipe-safe, normally non-blocking, reads | ||
| 43 | void clear(); | ||
| 44 | int poll(); | ||
| 45 | int read(char* s,int n); | ||
| 46 | void putback(const sref& s); | ||
| 47 | |||
| 48 | // Buffered reads | ||
| 49 | int readx(char* s,int n); // may timeout and return less than wanted | ||
| 50 | int readln(char* s,int n); | ||
| 51 | int readpara(char* s,int n); | ||
| 52 | |||
| 53 | private: | ||
| 54 | int fd; | ||
| 55 | mstring buf; | ||
| 56 | }; | ||
| 57 | |||
| 58 | // All functions return number of bytes written, or -1 on error. | ||
| 59 | // Note that although ln and para continues to read until | ||
| 60 | // it finds a newline or a paragraph, it may read more than that. | ||
| 61 | // Use clear() to restore reading state | ||
| 62 | |||
| 63 | #endif | ||
