sprint 1-alpha
sprint/thread/pipe.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *   sprint::pipe
00003 *
00004 *   Copyright (C) 2003-2011  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at your option) any later version.
00010 *
00011 *  This library is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 *  Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public
00017 *  License along with this library; if not, write to the Free Software
00018 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 
00022 #ifndef _SPRINT_PIPE_H_
00023 #define _SPRINT_PIPE_H_
00024 
00029 #ifndef DEFAULT_PIPE_BUFFER
00030 
00031 #define DEFAULT_PIPE_BUFFER     8192
00032 #endif
00033 
00034 #ifdef WIN32
00035 # include <windows.h>
00036 #endif
00037 
00038 namespace sprint {
00039           
00040 #ifdef WIN32
00041 
00042 class pipe {
00043 private:
00044         HANDLE write;
00045         HANDLE read;
00046 public:
00047 
00048         inline pipe(unsigned int _suggested_size = DEFAULT_PIPE_BUFFER)
00049         {
00050                 CreatePipe(&read, &write, NULL, _suggested_size);
00051         }
00052 
00053         inline ~pipe()
00054         {
00055         CloseHandle(read);
00056         CloseHandle(write);
00057         }
00058 
00060         inline DWORD write(LPCVOID lpData, UINT uDataSize)
00061         {
00062                 DWORD dwWrite;
00063                 WriteFile(write, lpData, uDataSize, &dwWrite, NULL);
00064                 return dwWrite;
00065         }
00066 
00068         inline DWORD read(LPVOID lpBuffer, UINT uDataToRead)
00069         {
00070                 DWORD dwRead;
00071                 ReadFile(read, lpBuffer, uDataToRead, &dwRead, NULL);
00072                 return dwRead;
00073         }
00074 
00076         inline DWORD peek()
00077         {
00078                 DWORD dwAvail;
00079                 PeekNamedPipe(read, NULL, 0, NULL, &dwAvail, NULL);
00080                 return dwAvail;
00081         }
00082 
00083 };
00084 #endif
00085 
00086 } // namespace
00087 
00088 #endif  // _SPRINT_PIPE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines