#include <FailoverDataIO.h>
Inheritance diagram for FailoverDataIO:

Public Types | |
| enum | { IO_SEEK_SET = 0, IO_SEEK_CUR, IO_SEEK_END, NUM_IO_SEEKS } |
| Values to pass in to DataIO::Seek()'s second parameter. More... | |
Public Member Functions | |
| FailoverDataIO (int logErrorLevel=MUSCLE_LOG_NONE) | |
| Default Constructor. | |
| virtual | ~FailoverDataIO () |
| Virtual destructor, to keep C++ honest. | |
| virtual int32 | Read (void *buffer, uint32 size) |
| Tries to place (size) bytes of new data into (buffer). | |
| virtual int32 | Write (const void *buffer, uint32 size) |
| Takes (size) bytes from (buffer) and pushes them in to the outgoing I/O stream. | |
| virtual status_t | Seek (int64 offset, int whence) |
| Seek to a given position in the I/O stream. | |
| virtual int64 | GetPosition () const |
| Should return the current position, in bytes, of the stream from its start position, or -1 if the current position is not known. | |
| virtual uint64 | GetOutputStallLimit () const |
| Returns the max number of microseconds to allow for an output stall, before presuming that the I/O is hosed. | |
| virtual void | FlushOutput () |
| Flushes the output buffer, if possible. | |
| virtual void | Shutdown () |
| Closes the connection. | |
| virtual const SocketRef & | GetSelectSocket () const |
| If this DataIO is usable with select(), this method should return the SocketRef object containing the file descriptor to select on for this DataIO. | |
| virtual status_t | GetReadByteTimeStamp (int32 whichByte, uint64 &retStamp) const |
| Optional interface for returning information on when a given byte returned by the previous Read() call was received. | |
| virtual bool | HasBufferedOutput () const |
| Optional: If your DataIO subclass is holding buffered data that it wants to output as soon as possible but hasn't been able to yet, then override this method to return true, and that will cause FlushBufferedOutput() to be called ASAP. | |
| virtual void | WriteBufferedOutput () |
| Optional: If this DataIO is holding any buffered output data, this method should be implemented to Write() as much of that data as possible. | |
| const Queue< DataIORef > & | GetChildDataIOs () const |
| Returns a read-only reference to our list of child DataIO objects. | |
| Queue< DataIORef > & | GetChildDataIOs () |
| Returns a read/write reference to our list of child DataIO objects. | |
| virtual void | Failover () |
| Called whenever a child DataIO reports an error. | |
| void | SetFailoverNotifyTarget (IFailoverNotifyTarget *t) |
| Call this to set the object that we should call DataIOFailover() on when a failover occurs. | |
| IFailoverNotifyTarget * | GetFailoverNotifyTarget () const |
| Returns the current failover notification target. | |
| uint32 | WriteFully (const void *buffer, uint32 size) |
| Convenience method: Calls Write() in a loop until the entire buffer is written, or until an error occurs. | |
| uint32 | ReadFully (void *buffer, uint32 size) |
| Convenience method: Calls Read() in a loop until the entire buffer is written, or until an error occurs. | |
| virtual int64 | GetLength () |
| Convenience method: Determines the length of this DataIO stream by Seek()'ing to the end of the stream, recording the current seek position, and then Seek()'ing back to the previous position in the stream. | |
| void | IncrementRefCount () const |
| Increments the counter and returns true iff the new value is zero. | |
| bool | DecrementRefCount () const |
| Decrements the counter and returns true iff the new value is zero. | |
| void | SetManager (AbstractObjectManager *manager) |
| Sets the recycle-pointer for this object. | |
| AbstractObjectManager * | GetManager () const |
| Returns this object's current recyler pointer. | |
| uint32 | GetRefCount () const |
| Returns this object's current reference count. | |
If an error occurs, it will discard the first held DataIO and start using the second one instead (and so on). This is useful for providing automatic failover/redundancy for important connections.
Definition at line 34 of file FailoverDataIO.h.
anonymous enum [inherited] |
Values to pass in to DataIO::Seek()'s second parameter.
| FailoverDataIO::FailoverDataIO | ( | int | logErrorLevel = MUSCLE_LOG_NONE |
) | [inline] |
Default Constructor.
Be sure to add some child DataIOs to our Queue of DataIOs (as returned by GetChildDataIOs()) so that this object will do something useful!
| logErrorLevel | Error level to give the log message that is generated when a failover occurs. Defaults to MUSCLE_LOG_NONE, so that by default no log message is generated. |
Definition at line 42 of file FailoverDataIO.h.
| virtual int32 FailoverDataIO::Read | ( | void * | buffer, | |
| uint32 | size | |||
| ) | [inline, virtual] |
Tries to place (size) bytes of new data into (buffer).
Returns the actual number of bytes placed, or a negative value if there was an error.
| buffer | Buffer to write the bytes into | |
| size | Number of bytes in the buffer. |
Implements DataIO.
Definition at line 47 of file FailoverDataIO.h.
References Failover(), and DataIO::Read().
| virtual int32 FailoverDataIO::Write | ( | const void * | buffer, | |
| uint32 | size | |||
| ) | [inline, virtual] |
Takes (size) bytes from (buffer) and pushes them in to the outgoing I/O stream.
Returns the actual number of bytes read from (buffer) and pushed, or a negative value if there was an error.
| buffer | Buffer to read the bytes from. | |
| size | Number of bytes in the buffer. |
Implements DataIO.
Definition at line 58 of file FailoverDataIO.h.
References Failover(), and DataIO::Write().
| virtual status_t FailoverDataIO::Seek | ( | int64 | offset, | |
| int | whence | |||
| ) | [inline, virtual] |
Seek to a given position in the I/O stream.
May not be supported by a DataIO subclass, in which case B_ERROR will always be returned.
| offset | Byte offset to seek to or by (depending on the next arg) | |
| whence | Set this to IO_SEEK_SET if you want the offset to be relative to the start of the stream; or to IO_SEEK_CUR if it should be relative to the current stream position, or IO_SEEK_END if it should be relative to the end of the stream. |
Implements DataIO.
Definition at line 69 of file FailoverDataIO.h.
References Failover(), and DataIO::Seek().
| virtual uint64 FailoverDataIO::GetOutputStallLimit | ( | ) | const [inline, virtual] |
Returns the max number of microseconds to allow for an output stall, before presuming that the I/O is hosed.
Default implementation returns MUSCLE_TIME_NEVER, aka no limit.
Reimplemented from DataIO.
Definition at line 82 of file FailoverDataIO.h.
References DataIO::GetOutputStallLimit().
| virtual void FailoverDataIO::FlushOutput | ( | ) | [inline, virtual] |
Flushes the output buffer, if possible.
For some implementations, this is a no-op. For others (e.g. TCPSocketDataIO) this can be called to reduced latency of outgoing data blocks.
Implements DataIO.
Definition at line 84 of file FailoverDataIO.h.
References DataIO::FlushOutput().
| virtual void FailoverDataIO::Shutdown | ( | ) | [inline, virtual] |
Closes the connection.
After calling this method, the DataIO object should not be used any more.
Implements DataIO.
Definition at line 86 of file FailoverDataIO.h.
| virtual const SocketRef& FailoverDataIO::GetSelectSocket | ( | ) | const [inline, virtual] |
If this DataIO is usable with select(), this method should return the SocketRef object containing the file descriptor to select on for this DataIO.
If this DataIO isn't usable with select(), then this method should return GetNullSocket().
Note that the only thing you are allowed to do with the returned file descriptor is pass it to select(). For all other operations, use the appropriate methods in the DataIO interface. If you attempt to do any other I/O operations on this file descriptor directly, the results are non-portable and undefined and will probably break your program.
Implements DataIO.
Definition at line 88 of file FailoverDataIO.h.
References DataIO::GetSelectSocket().
| virtual status_t FailoverDataIO::GetReadByteTimeStamp | ( | int32 | whichByte, | |
| uint64 & | retStamp | |||
| ) | const [inline, virtual] |
Optional interface for returning information on when a given byte returned by the previous Read() call was received.
Not implemented by default, and not implemented by any of the standard MUSCLE DataIO subclasses. (Used by an LCS dataIO class that needs precision timing)
| whichByte | Index of the byte in the previously returned read-buffer that you are interested in. | |
| retStamp | On success, this value is set to the timestamp of the byte. |
Reimplemented from DataIO.
Definition at line 90 of file FailoverDataIO.h.
References DataIO::GetReadByteTimeStamp().
| virtual bool FailoverDataIO::HasBufferedOutput | ( | ) | const [inline, virtual] |
Optional: If your DataIO subclass is holding buffered data that it wants to output as soon as possible but hasn't been able to yet, then override this method to return true, and that will cause FlushBufferedOutput() to be called ASAP.
Default implementation always returns false.
Reimplemented from DataIO.
Definition at line 92 of file FailoverDataIO.h.
References DataIO::HasBufferedOutput().
| virtual void FailoverDataIO::WriteBufferedOutput | ( | ) | [inline, virtual] |
Optional: If this DataIO is holding any buffered output data, this method should be implemented to Write() as much of that data as possible.
Default implementation is a no-op.
Reimplemented from DataIO.
Definition at line 94 of file FailoverDataIO.h.
References DataIO::WriteBufferedOutput().
| virtual void FailoverDataIO::Failover | ( | ) | [inline, virtual] |
Called whenever a child DataIO reports an error.
Default implementation removes the first DataIORef from the queue, prints an error to the log, and calls DataIOFailover() on the current failover notification target (if any; see SetFailoverNotifyTarget() for details)
Definition at line 107 of file FailoverDataIO.h.
References IFailoverNotifyTarget::DataIOFailover().
| IFailoverNotifyTarget* FailoverDataIO::GetFailoverNotifyTarget | ( | ) | const [inline] |
Returns the current failover notification target.
Default is NULL (i.e. no target set)
Definition at line 119 of file FailoverDataIO.h.
| uint32 DataIO::WriteFully | ( | const void * | buffer, | |
| uint32 | size | |||
| ) | [inherited] |
Convenience method: Calls Write() in a loop until the entire buffer is written, or until an error occurs.
This method should only be used in conjunction with blocking I/O; it will not work reliably with non-blocking I/O.
| buffer | Pointer to the first byte of the buffer to write data from. | |
| size | Number of bytes to write |
| uint32 DataIO::ReadFully | ( | void * | buffer, | |
| uint32 | size | |||
| ) | [inherited] |
Convenience method: Calls Read() in a loop until the entire buffer is written, or until an error occurs.
This method should only be used in conjunction with blocking I/O; it will not work reliably with non-blocking I/O.
| buffer | Pointer to the first byte of the buffer to place the read data into. | |
| size | Number of bytes to read |
| virtual int64 DataIO::GetLength | ( | ) | [virtual, inherited] |
Convenience method: Determines the length of this DataIO stream by Seek()'ing to the end of the stream, recording the current seek position, and then Seek()'ing back to the previous position in the stream.
Of course this only works with DataIOs that support seeking and have a fixed length.
Reimplemented in PacketizedDataIO.
| void RefCountable::IncrementRefCount | ( | ) | const [inline, inherited] |
Increments the counter and returns true iff the new value is zero.
Thread safe.
Definition at line 32 of file RefCount.h.
References AtomicCounter::AtomicIncrement().
| bool RefCountable::DecrementRefCount | ( | ) | const [inline, inherited] |
Decrements the counter and returns true iff the new value is zero.
Thread safe.
Definition at line 35 of file RefCount.h.
References AtomicCounter::AtomicDecrement().
| void RefCountable::SetManager | ( | AbstractObjectManager * | manager | ) | [inline, inherited] |
Sets the recycle-pointer for this object.
If set to non-NULL, this pointer is used by the ObjectPool class to recycle this object when it is no longer in use, so as to avoid the overhead of having to delete it and re-create it later on. The RefCountable class itself does nothing with this pointer. Default value is NULL.
| manager | Pointer to the new manager object to use, or NULL to use no manager. |
Definition at line 44 of file RefCount.h.
| uint32 RefCountable::GetRefCount | ( | ) | const [inline, inherited] |
Returns this object's current reference count.
Note that the value returned by this method is volatile in multithreaded environments, so it may already be wrong by the time it is returned. Be careful!
Definition at line 54 of file RefCount.h.
References AtomicCounter::GetCount().
1.5.1