Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXSocketStream.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                  Socket Stream                                                *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.   All Rights Reserved.                *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************/
00022 #ifndef FXSOCKETSTREAM_H
00023 #define FXSOCKETSTREAM_H
00024 
00025 // FIXME this should really be made generic and called FXIOStream, so as to use the
00026 //       virtual methods of the FXIOHandle class
00027 
00028 #ifndef FXSTREAM_H
00029 #include <fox/FXStream.h>
00030 using namespace FX;
00031 #endif
00032 namespace FXEX {
00033 class FXSocket;
00034 
00035 /**
00036  * A first implementation of a socket stream
00037  */
00038 class FXAPI FXSocketStream : public FXStream {
00039 
00040   protected:
00041     FXSocket *socket;  // handle to actual socket
00042     FXbool    opened;  // did this stream open the socket
00043 
00044   protected:
00045     // serialisation
00046     FXSocketStream(){}
00047 
00048     /// save data to socket
00049     void saveItems(const void* buf,unsigned long n);
00050 
00051     /// load data from socket
00052     void loadItems(void* buf,unsigned long n);
00053 
00054   public:
00055     /// Create a socket stream based on a specific socket
00056     FXSocketStream(const FXObject *cont=NULL);
00057 
00058     /// open a socket stream - socket will be opened if not already opened
00059     FXbool open(FXSocket *sock,FXStreamDirection save_or_load);
00060 
00061     /// close a socket stream
00062     FXbool close();
00063 
00064     /// dtor
00065     virtual ~FXSocketStream();
00066   };
00067 
00068 } // namespace FXEX
00069 #endif // FXIOSTREAM_H