00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Mark Elendt 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_NamedPipe.h ( UT Library, C++) 00015 * 00016 * COMMENTS: This is a read pipe which gets around the problem of having a 00017 * broken pipe if you close before reading all of the input from 00018 * the pipe command. 00019 */ 00020 00021 #ifndef __UT_NamedPipe__ 00022 #define __UT_NamedPipe__ 00023 00024 #include "UT_API.h" 00025 #include "UT_String.h" 00026 00027 #if defined(LINUX) || defined(MBSD) 00028 #include <stdio.h> 00029 #endif 00030 00031 class UT_API UT_NamedPipe { 00032 public: 00033 explicit UT_NamedPipe(int *filehandle); 00034 00035 // If the pipe is open and destructed, the process will be killed. 00036 ~UT_NamedPipe(); 00037 00038 // Returns 1 if the pipe is open, 0 otherwise. 00039 int isOpen(); 00040 00041 // Create a named pipe of the given name. Returns 0 on error, 1 on success. 00042 // Created pipes are all write-only. 00043 int create(const char *filename); 00044 00045 // Open a named pipe ofh the given name. Returns 0 on error, 1 on success. 00046 // Opened pipes are all read only. 00047 int open(const char *filename); 00048 00049 // Close the pipe. 00050 void close(); 00051 00052 // Read up to the specified number of bytes. Returns the number of bytes 00053 // actually read. This call never blocks. 00054 int read(char *data, int len); 00055 00056 // Prepare named pipe for writing. Call this before doing a block 00057 // of writes. Under NT it makes sure the pipe is connected. Does 00058 // nothing under SGI. 00059 void prepWrite(); 00060 00061 // Write the specified number of bytes. Returns the number of bytes 00062 // actually read. This call blocks until all bytes have been written. 00063 int write(const char *data, int len); 00064 00065 // Flush input or output. 00066 void flush(); 00067 00068 // Returns 1 if there is data to be read, 0 if not, and less 00069 // than 0 if error. 00070 int dataAvailable(); 00071 00072 private: 00073 00074 int *myFileHandle; 00075 00076 int myCreated; 00077 UT_String myFileName; 00078 int myBytePending; 00079 char myNextByte; 00080 #ifndef WIN32 00081 FILE *myPipe; 00082 #endif 00083 }; 00084 00085 #endif
1.5.9