Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

StreamedSocket.h

Go to the documentation of this file.
00001 /*  StreamedSocket.h - Reliable send/recv socket class
00002     Copyright (C) 2001-2004 Mark Weaver
00003     Written by Mark Weaver <mark@npsl.co.uk>
00004 
00005     Part of the Open-Win32 library.
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 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     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the
00018     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA  02111-1307, USA.
00020 */
00021 
00026 #ifndef OW32_StreamedSocket_h
00027 #define OW32_StreamedSocket_h
00028 
00029 #include <OW32/Socket.h>
00030 
00031 // Open Win32 namespace
00032 namespace OW32
00033 {
00034 
00038 template <class TSocket = CSocket> 
00039 class CStreamedSocket : 
00040     public TSocket
00041 {
00042 private:
00043     CStreamedSocket(const CStreamedSocket& );
00044     CStreamedSocket& operator=(const CStreamedSocket& );
00045 
00046 public:
00047     CStreamedSocket() {}
00048 
00049     CStreamedSocket(SOCKET s) :
00050         TSocket(s)
00051     {
00052     }
00053 
00054     // recv with a loop to read all requested data in stream
00055     virtual int recv(char* buf, int len)
00056     {
00057         int count=0;
00058         
00059         do
00060         {
00061             int result = TSocket::recv(buf+count, len-count);
00062             if (result <= 0)
00063                 return result;
00064             count += result;
00065         } while (count < len);
00066 
00067         return count;
00068     }
00069 
00070     // send with the same
00071     virtual int send(const char *buf, int len)
00072     {
00073         int count=0;
00074 
00075         do
00076         {
00077             int result = TSocket::send(buf+count, len-count);
00078             if (result <= 0)
00079                 return result;
00080             count += result;
00081         } while (count < len);
00082 
00083         return count;
00084     }
00085 };
00086 
00087 } // namespace OW32
00088 
00089 #endif // OW32_StreamedSocket_h

Generated on Sun Jun 5 01:29:18 2005 for OW32 by  doxygen 1.3.9.1