QSocketDataIO.h

00001 /* This file is Copyright 2000-2008 Meyer Sound Laboratories Inc.  See the included LICENSE.txt file for details. */
00002 
00003 #ifndef MuscleQSocketDataIO_h
00004 #define MuscleQSocketDataIO_h
00005 
00006 #include <qsocket.h>
00007 #include "dataio/DataIO.h"
00008 
00009 BEGIN_NAMESPACE(muscle);
00010 
00028 class QSocketDataIO : public DataIO  
00029 {
00030 public: 
00034    QSocketDataIO(QSocket * newSocket) : _socket(newSocket), _socketRef(newSocket?GetSocketRefFromPool(newSocket, false):SocketRef()) {/* empty */}
00035 
00037    virtual ~QSocketDataIO() {Shutdown();}
00038 
00046    virtual int32 Read(void * buffer, uint32 size) {return _socket ? _socket->readBlock((char *) buffer, size) : -1;}
00047 
00056    virtual int32 Write(const void * buffer, uint32 size) {return _socket ? _socket->writeBlock((char *) buffer, size) : -1;}
00057 
00061    virtual status_t Seek(int64 /*offset*/, int /*whence*/) {return B_ERROR;}
00062 
00064    virtual int64 GetPosition() const {return -1;}
00065 
00069    virtual void FlushOutput() {if (_socket) _socket->flush();}
00070 
00075    virtual void Shutdown() {if (_socket) _socket->close(); delete _socket; _socket = NULL; _socketRef.Reset();}
00076 
00078    virtual const SocketRef & GetSelectSocket() const {return _socket ? _socketRef : GetNullSocket();}
00079 
00083    QSocket * GetSocket() {return _socket;}
00084 
00090    void ReleaseSocket() {_socket = NULL; _socketRef.Neutralize();}
00091 
00092 private:
00093    SocketRef _socketRef;
00094    QSocket * _socket;
00095 };
00096 
00097 END_NAMESPACE(muscle);
00098 
00099 #endif

Generated on Thu Jun 5 17:47:53 2008 for MUSCLE by  doxygen 1.5.1