diff --git a/Foundation/Foundation_vs71.vcproj b/Foundation/Foundation_vs71.vcproj
index d3db52b69..4f6e601cf 100644
--- a/Foundation/Foundation_vs71.vcproj
+++ b/Foundation/Foundation_vs71.vcproj
@@ -3620,6 +3620,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Foundation/Foundation_vs80.vcproj b/Foundation/Foundation_vs80.vcproj
index 94f6378ad..b9d2175c2 100644
--- a/Foundation/Foundation_vs80.vcproj
+++ b/Foundation/Foundation_vs80.vcproj
@@ -1,7 +1,7 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Foundation/Makefile b/Foundation/Makefile
index 0a8f15168..de3795579 100644
--- a/Foundation/Makefile
+++ b/Foundation/Makefile
@@ -1,7 +1,7 @@
#
# Makefile
#
-# $Id: //poco/Main/Foundation/Makefile#43 $
+# $Id: //poco/Main/Foundation/Makefile#44 $
#
# Makefile for Poco Foundation
#
@@ -31,6 +31,7 @@ objects = ArchiveStrategy ASCIIEncoding AsyncChannel Base64Decoder Base64Encoder
UTF8Encoding UnicodeConverter UUID UUIDGenerator Void Format \
Pipe PipeImpl PipeStream DynamicAny DynamicAnyHolder SharedMemory \
FileStream Unicode UTF8String \
+ AsyncIOCommand AsyncIOEvent AsyncIOChannel AsyncStreamChannel \
adler32 compress crc32 deflate gzio infback inffast inflate inftrees \
trees zutil \
pcre_chartables pcre_compile pcre_globals pcre_maketables pcre_study \
diff --git a/Foundation/include/Poco/AsyncIOChannel.h b/Foundation/include/Poco/AsyncIOChannel.h
new file mode 100644
index 000000000..163622cc4
--- /dev/null
+++ b/Foundation/include/Poco/AsyncIOChannel.h
@@ -0,0 +1,154 @@
+//
+// AsyncIOChannel.h
+//
+// $Id: //poco/Main/Foundation/include/Poco/AsyncIOChannel.h#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncIOChannel
+//
+// Definition of the AsyncIOChannel class.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef Foundation_AsyncIOChannel_INCLUDED
+#define Foundation_AsyncIOChannel_INCLUDED
+
+
+#include "Poco/Foundation.h"
+#include "Poco/ActiveDispatcher.h"
+#include "Poco/ActiveMethod.h"
+#include "Poco/AsyncIOCommand.h"
+
+
+namespace Poco {
+
+
+class Foundation_API AsyncIOChannel: public ActiveDispatcher
+ /// AsyncIOChannel supports asynchronous I/O operations on
+ /// streams or other input/output facilities.
+ ///
+ /// This implementation of asynchronous I/O is based on
+ /// blocking I/O operations that are executed in a separate thread.
+ /// Some operating systems may provide special asynchronous
+ /// I/O operations at the operating system level. However, these
+ /// are not used by the current implementation.
+ ///
+ /// I/O operations (in the form of AsyncIOCommand subclass instances)
+ /// are queued for execution on an AsyncIOChannel. The AsyncIOChannel's
+ /// I/O thread executes all queued commands in FIFO order.
+ ///
+ /// Since AsyncIOChannel is based on ActiveDispatcher, the I/O thread is
+ /// taken from the default thread pool. It should be ensured that the
+ /// capacity of the default thread pool is sufficient before using
+ /// asynchronous I/O. For every AsyncIOChannel instance, one thread
+ /// from the default thread pool is needed.
+ ///
+ /// Subclasses of AsyncIOChannel implement asynchronous input/output
+ /// for streams and sockets.
+ ///
+ /// The enqueue() active member function is used to enqueue AsyncIOCommand
+ /// instances for execution.
+ ///
+ /// The cancel() member function (inherited from ActiveDispatcher) can be
+ /// used to cancel all pending requests.
+ ///
+ /// Both the AsyncIOCommand class, and the AsyncIOChannel class offer events
+ /// that notify an interested party about the successful or unsuccessful
+ /// completion of a command.
+ ///
+ /// There are also two ways to wait for the completion of a command and
+ /// obtain its result. The first one is by using the return value of
+ /// enqueue(), which is ActiveResult. See the ActiveResult class
+ /// template for more information. The second one is by using the functions
+ /// of AsyncIOCommand, such as wait(), succeeded() and result().
+ ///
+ /// AsyncIOChannel supports the operations write, read and seek directly. However,
+ /// subclasses of AsyncIOChannel can define additional operations.
+{
+public:
+ ActiveMethod > enqueue;
+ /// Actual signature:
+ /// int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
+ ///
+ /// Enqueue the given command for eventual execution.
+ /// Returns the number of bytes read or written if the operation
+ /// was successful.
+
+ BasicEvent commandCompleted;
+ /// Fired when a command has successfully completed.
+
+ BasicEvent commandFailed;
+ /// Fired when a command has failed.
+
+ virtual int write(const void* buffer, int length);
+ /// Write length bytes from buffer.
+ ///
+ /// Must be overridden by subclasses. The default implementation
+ /// throws a NotImplementedException.
+ ///
+ /// Returns the number of bytes written.
+
+ virtual int read(void* buffer, int length);
+ /// Read up to length bytes into buffer.
+ ///
+ /// Must be overridden by subclasses. The default implementation
+ /// throws a NotImplementedException.
+ ///
+ /// Returns the number of bytes read.
+
+ virtual int seek(std::streamoff off, std::ios::seekdir dir);
+ /// Sets the current read/write position.
+ ///
+ /// Must be overridden by subclasses. The default implementation
+ /// throws a NotImplementedException.
+ ///
+ /// Always returns 0.
+
+protected:
+ AsyncIOChannel();
+ /// Creates the AsyncIOChannel.
+
+ ~AsyncIOChannel();
+ /// Destroys the AsyncIOChannel.
+
+ int enqueueImpl(const AsyncIOCommand::Ptr& pCommand);
+ /// Execute the given command by calling
+ /// pCommand->execute(this);
+ /// and return the result.
+
+private:
+ AsyncIOChannel(const AsyncIOChannel&);
+ AsyncIOChannel& operator = (const AsyncIOChannel&);
+};
+
+
+} // namespace Poco
+
+
+#endif // Foundation_AsyncIOChannel_INCLUDED
diff --git a/Foundation/include/Poco/AsyncIOCommand.h b/Foundation/include/Poco/AsyncIOCommand.h
new file mode 100644
index 000000000..f687ce447
--- /dev/null
+++ b/Foundation/include/Poco/AsyncIOCommand.h
@@ -0,0 +1,319 @@
+//
+// AsyncIOCommand.h
+//
+// $Id: //poco/Main/Foundation/include/Poco/AsyncIOCommand.h#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncIOCommand
+//
+// Definition of the AsyncIOCommand class and subclasses.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef Foundation_AsyncIOCommand_INCLUDED
+#define Foundation_AsyncIOCommand_INCLUDED
+
+
+#include "Poco/Foundation.h"
+#include "Poco/RefCountedObject.h"
+#include "Poco/AutoPtr.h"
+#include "Poco/Event.h"
+#include "Poco/BasicEvent.h"
+#include "Poco/AsyncIOEvent.h"
+#include "Poco/Exception.h"
+#include
+
+
+namespace Poco {
+
+
+class AsyncIOChannel;
+
+
+class Foundation_API AsyncIOCommand: public RefCountedObject
+ /// AsyncIOCommand is the base class for all asynchronous input/output
+ /// commands used with AsyncIOChannel.
+ ///
+ /// See class AsyncIOChannel for more information about asynchronous input/output.
+{
+public:
+ typedef AutoPtr Ptr;
+
+ enum State
+ {
+ CMD_PENDING, /// Command is queued for execution.
+ CMD_IN_PROGRESS, /// Command is currently being executed.
+ CMD_COMPLETED, /// Command has completed successfully.
+ CMD_FAILED /// Command has failed.
+ };
+
+ BasicEvent commandCompleted;
+ /// Fired when the command has successfully completed.
+
+ BasicEvent commandFailed;
+ /// Fired when the command has failed.
+
+ State state() const;
+ /// Returns the current state of the command.
+
+ void wait();
+ /// Waits for the completion of the command.
+
+ void wait(long milliseconds);
+ /// Waits at most the given timeout for the
+ /// completion of the command. Throws a
+ /// TimeoutException if the command does
+ /// not complete within the given timeout.
+
+ bool tryWait(long milliseconds);
+ /// Waits at most the given timeout for the
+ /// completion of the command.
+ ///
+ /// Returns true if the command completes within
+ /// the given timeout, otherwise false.
+
+ bool succeeded() const;
+ /// Returns true iff the command completed successfully.
+
+ bool failed() const;
+ /// Returns true iff the command has completed with an error.
+
+ const Exception* exception() const;
+ /// If the command failed with an exception, returns a
+ /// clone of the exception. Otherwise, returns a null pointer.
+
+ int execute(AsyncIOChannel& channel);
+ /// Executes the command on the given AsyncIOChannel.
+ ///
+ /// Sets the state to CMD_IN_PROGRESS, calls
+ /// executeImpl(), and, according to its result,
+ /// sets the state to CMD_COMPLETED or CMD_FAILED
+ /// and signals the event.
+ ///
+ /// Returns the number of bytes processed by the
+ /// command.
+
+ int result() const;
+ /// Returns the result of the command.
+
+protected:
+ AsyncIOCommand();
+ /// Creates the AsyncIOCommand.
+
+ ~AsyncIOCommand();
+ /// Destroys the AsyncIOCommand.
+
+ virtual int executeImpl(AsyncIOChannel& channel) = 0;
+ /// Executes the command on the given AsyncIOChannel.
+ /// Must be overridded by subclasses.
+ ///
+ /// Returns the number of bytes processed by the
+ /// command.
+
+private:
+ State _state;
+ Event _completed;
+ int _result;
+ Exception* _pException;
+};
+
+
+class Foundation_API AsyncWriteCommand: public AsyncIOCommand
+ /// An asynchronous write command.
+{
+public:
+ AsyncWriteCommand(const void* buffer, int length);
+ /// Create an AsyncWriteCommand for writing length bytes
+ /// from the given buffer. The given buffer must be
+ /// valid until the command completes.
+
+ const void* buffer() const;
+ /// Returns the buffer's address.
+
+ int length() const;
+ /// Returns the buffer's size.
+
+protected:
+ int executeImpl(AsyncIOChannel& channel);
+ ~AsyncWriteCommand();
+
+private:
+ AsyncWriteCommand();
+
+ const void* _buffer;
+ int _length;
+};
+
+
+class Foundation_API AsyncBufferedWriteCommand: public AsyncWriteCommand
+ /// An asynchronous write command. The difference to
+ /// AsyncWriteCommand is that AsyncBufferedWriteCommand
+ /// copies the data in the buffer into an internal buffer, thus
+ /// the given buffer can be deleted as soon as the constructor
+ /// returns.
+{
+public:
+ AsyncBufferedWriteCommand(const void* buffer, int length);
+ /// Create an AsyncBufferedWriteCommand for writing length bytes
+ /// from the given buffer and copies the data from the
+ /// given buffer into an internal buffer.
+ ///
+ /// The internal buffer can be accessed via the buffer()
+ /// member function inherited from AsyncWriteCommand.
+
+protected:
+ ~AsyncBufferedWriteCommand();
+};
+
+
+class Foundation_API AsyncReadCommand: public AsyncIOCommand
+ /// An asynchronous read command.
+{
+public:
+ AsyncReadCommand(void* buffer, int length);
+ /// Create an AsyncReadCommand for reading up to length
+ /// bytes into the given buffer.
+
+ void* buffer() const;
+ /// Returns the buffer's address.
+
+ int length() const;
+ /// Returns the buffer's size.
+
+protected:
+ int executeImpl(AsyncIOChannel& channel);
+ ~AsyncReadCommand();
+
+private:
+ AsyncReadCommand();
+
+ void* _buffer;
+ int _length;
+};
+
+
+class Foundation_API AsyncBufferedReadCommand: public AsyncReadCommand
+ /// An asynchronous read command. In contrast to
+ /// AsyncReadCommand, which requires an externally supplied
+ /// buffer that must be valid until the command completes,
+ /// AsyncBufferedReadCommand maintains an internal buffer.
+{
+public:
+ AsyncBufferedReadCommand(int length);
+ /// Create an AsyncReadCommand for reading up to length
+ /// bytes into an internal buffer.
+ ///
+ /// The buffer can be accessed via the buffer() member
+ /// function inherited from AsyncReadCommand.
+
+protected:
+ ~AsyncBufferedReadCommand();
+};
+
+
+class Foundation_API AsyncSeekCommand: public AsyncIOCommand
+ /// An asynchronous seek command.
+{
+public:
+ AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir = std::ios::beg);
+ /// Creates an AsyncSeekCommand for setting the current read/write position.
+
+protected:
+ int executeImpl(AsyncIOChannel& channel);
+ ~AsyncSeekCommand();
+
+private:
+ AsyncSeekCommand();
+
+ std::streamoff _off;
+ std::ios::seekdir _dir;
+};
+
+
+//
+// inlines
+//
+inline AsyncIOCommand::State AsyncIOCommand::state() const
+{
+ return _state;
+}
+
+
+inline int AsyncIOCommand::result() const
+{
+ return _result;
+}
+
+
+inline const Exception* AsyncIOCommand::exception() const
+{
+ return _pException;
+}
+
+
+inline bool AsyncIOCommand::succeeded() const
+{
+ return _state == CMD_COMPLETED;
+}
+
+
+inline bool AsyncIOCommand::failed() const
+{
+ return _state == CMD_FAILED;
+}
+
+
+inline const void* AsyncWriteCommand::buffer() const
+{
+ return _buffer;
+}
+
+
+inline int AsyncWriteCommand::length() const
+{
+ return _length;
+}
+
+
+inline void* AsyncReadCommand::buffer() const
+{
+ return _buffer;
+}
+
+
+inline int AsyncReadCommand::length() const
+{
+ return _length;
+}
+
+
+} // namespace Poco
+
+
+#endif // Foundation_AsyncIOCommand_INCLUDED
diff --git a/Foundation/include/Poco/AsyncIOEvent.h b/Foundation/include/Poco/AsyncIOEvent.h
new file mode 100644
index 000000000..045337db1
--- /dev/null
+++ b/Foundation/include/Poco/AsyncIOEvent.h
@@ -0,0 +1,121 @@
+//
+// AsyncIOEvent.h
+//
+// $Id: //poco/Main/Foundation/include/Poco/AsyncIOEvent.h#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncIOEvent
+//
+// Definition of the AsyncIOEvent class.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef Foundation_AsyncIOEvent_INCLUDED
+#define Foundation_AsyncIOEvent_INCLUDED
+
+
+#include "Poco/Foundation.h"
+
+
+namespace Poco {
+
+
+class AsyncIOCommand;
+class AsyncIOChannel;
+
+
+class Foundation_API AsyncIOEvent
+ /// The AsyncIOEvent class holds information about an event
+ /// caused by asynchronous input or output operation.
+{
+public:
+ enum EventKind
+ {
+ EV_COMMAND_COMPLETED,
+ EV_COMMAND_FAILED
+ };
+
+ AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what);
+ /// Creates the AsyncIOEvent.
+
+ AsyncIOEvent(const AsyncIOEvent& event);
+ /// Creates a AsyncIOEvent from another one.
+
+ ~AsyncIOEvent();
+ /// Destroys the AsyncIOEvent.
+
+ AsyncIOEvent& operator = (const AsyncIOEvent& event);
+ /// Assigns a AsyncIOEvent.
+
+ void swap(AsyncIOEvent& event);
+ /// Swaps the event with another one.
+
+ AsyncIOCommand& command() const;
+ /// Returns the command that caused the event.
+
+ AsyncIOChannel& channel() const;
+ /// Returns the channel that caused the event.
+
+ EventKind what() const;
+ /// Returns the reason of the event.
+
+private:
+ AsyncIOEvent();
+
+ AsyncIOCommand* _pCommand;
+ AsyncIOChannel* _pChannel;
+ EventKind _what;
+};
+
+
+//
+// inlines
+//
+inline AsyncIOCommand& AsyncIOEvent::command() const
+{
+ return *_pCommand;
+}
+
+
+inline AsyncIOChannel& AsyncIOEvent::channel() const
+{
+ return *_pChannel;
+}
+
+
+inline AsyncIOEvent::EventKind AsyncIOEvent::what() const
+{
+ return _what;
+}
+
+
+} // namespace Poco
+
+
+#endif // Foundation_AsyncIOEvent_INCLUDED
diff --git a/Foundation/include/Poco/AsyncStreamChannel.h b/Foundation/include/Poco/AsyncStreamChannel.h
new file mode 100644
index 000000000..37d6ea29e
--- /dev/null
+++ b/Foundation/include/Poco/AsyncStreamChannel.h
@@ -0,0 +1,96 @@
+//
+// AsyncStreamChannel.h
+//
+// $Id: //poco/Main/Foundation/include/Poco/AsyncStreamChannel.h#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncStreamChannel
+//
+// Definition of the AsyncStreamChannel class.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef Foundation_AsyncStreamChannel_INCLUDED
+#define Foundation_AsyncStreamChannel_INCLUDED
+
+
+#include "Poco/Foundation.h"
+#include "Poco/AsyncIOChannel.h"
+#include
+#include
+#include
+
+
+namespace Poco {
+
+
+class Foundation_API AsyncStreamChannel: public AsyncIOChannel
+ /// AsyncStreamChannel provides an AsyncIOChannel for I/O streams.
+ ///
+ /// Usage Example:
+ /// std::stringstream str;
+ /// AsyncStreamChannel channel(str);
+ /// channel.enqueue(new AsyncWriteCommand("Hello", 5));
+ /// channel.enqueue(new AsyncWriteCommand(", ", 2));
+ /// ActiveResult result = channel.enqueue(new AsyncWriteCommand("world!", 6));
+ /// result.wait();
+ /// std::string s(str.str());
+{
+public:
+ AsyncStreamChannel(std::istream& istr);
+ /// Creates an AsyncStreamChannel using the given input stream.
+ /// Only read and seek operations will be allowed.
+
+ AsyncStreamChannel(std::ostream& ostr);
+ /// Creates an AsyncStreamChannel using the given output stream.
+ /// Only write and seek operations will be allowed.
+
+ AsyncStreamChannel(std::iostream& iostr);
+ /// Creates an AsyncStreamChannel using the given input/output stream.
+
+ ~AsyncStreamChannel();
+ /// Destroys the AsyncStreamChannel.
+
+ // AsyncIOChannel
+ int write(const void* buffer, int length);
+ int read(void* buffer, int length);
+ int seek(std::streamoff off, std::ios::seekdir dir);
+
+private:
+ AsyncStreamChannel();
+
+ std::istream* _pIstr;
+ std::ostream* _pOstr;
+};
+
+
+} // namespace Poco
+
+
+#endif // Foundation_AsyncStreamChannel_INCLUDED
diff --git a/Foundation/src/AsyncIOChannel.cpp b/Foundation/src/AsyncIOChannel.cpp
new file mode 100644
index 000000000..42944a751
--- /dev/null
+++ b/Foundation/src/AsyncIOChannel.cpp
@@ -0,0 +1,79 @@
+//
+// AsyncIOChannel.cpp
+//
+// $Id: //poco/Main/Foundation/src/AsyncIOChannel.cpp#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncIOChannel
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/AsyncIOChannel.h"
+
+
+namespace Poco {
+
+
+AsyncIOChannel::AsyncIOChannel():
+ enqueue(this, &AsyncIOChannel::enqueueImpl)
+{
+}
+
+
+AsyncIOChannel::~AsyncIOChannel()
+{
+}
+
+
+int AsyncIOChannel::enqueueImpl(const AsyncIOCommand::Ptr& pCommand)
+{
+ AsyncIOCommand::Ptr ptr(pCommand);
+ return ptr->execute(*this);
+}
+
+
+int AsyncIOChannel::write(const void* buffer, int length)
+{
+ throw NotImplementedException("write()");
+}
+
+
+int AsyncIOChannel::read(void* buffer, int length)
+{
+ throw NotImplementedException("read()");
+}
+
+
+int AsyncIOChannel::seek(std::streamoff off, std::ios::seekdir dir)
+{
+ throw NotImplementedException("seek()");
+}
+
+
+} // namespace Poco
diff --git a/Foundation/src/AsyncIOCommand.cpp b/Foundation/src/AsyncIOCommand.cpp
new file mode 100644
index 000000000..e7047c888
--- /dev/null
+++ b/Foundation/src/AsyncIOCommand.cpp
@@ -0,0 +1,236 @@
+//
+// AsyncIOCommand.cpp
+//
+// $Id: //poco/Main/Foundation/src/AsyncIOCommand.cpp#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncIOCommand
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/AsyncIOCommand.h"
+#include "Poco/AsyncIOChannel.h"
+#include "Poco/AsyncIOEvent.h"
+#include
+
+
+namespace Poco {
+
+
+//
+// AsyncIOCommand
+//
+
+
+AsyncIOCommand::AsyncIOCommand():
+ _state(CMD_PENDING),
+ _result(0),
+ _pException(0)
+{
+}
+
+
+AsyncIOCommand::~AsyncIOCommand()
+{
+ delete _pException;
+}
+
+
+void AsyncIOCommand::wait()
+{
+ _completed.wait();
+}
+
+
+void AsyncIOCommand::wait(long milliseconds)
+{
+ _completed.wait(milliseconds);
+}
+
+
+bool AsyncIOCommand::tryWait(long milliseconds)
+{
+ return _completed.tryWait(milliseconds);
+}
+
+
+int AsyncIOCommand::execute(AsyncIOChannel& channel)
+{
+ delete _pException;
+ _pException = 0;
+
+ _state = CMD_IN_PROGRESS;
+ try
+ {
+ _result = executeImpl(channel);
+ _state = CMD_COMPLETED;
+ _completed.set();
+ AsyncIOEvent completedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_COMPLETED);
+ commandCompleted(this, completedEvent);
+ channel.commandCompleted(this, completedEvent);
+ return _result;
+ }
+ catch (Exception& exc)
+ {
+ _pException = exc.clone();
+ _state = CMD_FAILED;
+ _completed.set();
+ AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
+ commandFailed(this, failedEvent);
+ channel.commandFailed(this, failedEvent);
+ throw;
+ }
+ catch (std::exception& exc)
+ {
+ _pException = new Exception(exc.what());
+ _state = CMD_FAILED;
+ _completed.set();
+ AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
+ commandFailed(this, failedEvent);
+ channel.commandFailed(this, failedEvent);
+ throw;
+ }
+ catch (...)
+ {
+ _pException = new Exception("Unknown exception");
+ _state = CMD_FAILED;
+ _completed.set();
+ AsyncIOEvent failedEvent(this, &channel, AsyncIOEvent::EV_COMMAND_FAILED);
+ commandFailed(this, failedEvent);
+ channel.commandFailed(this, failedEvent);
+ throw;
+ }
+}
+
+
+//
+// AsyncWriteCommand
+//
+
+
+AsyncWriteCommand::AsyncWriteCommand(const void* buffer, int length):
+ _buffer(buffer),
+ _length(length)
+{
+}
+
+
+AsyncWriteCommand::~AsyncWriteCommand()
+{
+}
+
+
+int AsyncWriteCommand::executeImpl(AsyncIOChannel& channel)
+{
+ return channel.write(_buffer, _length);
+}
+
+
+//
+// AsyncBufferedWriteCommand
+//
+
+
+AsyncBufferedWriteCommand::AsyncBufferedWriteCommand(const void* buf, int length):
+ AsyncWriteCommand(new char[length], length)
+{
+ std::memcpy(const_cast(buffer()), buf, length);
+}
+
+
+AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand()
+{
+ delete [] reinterpret_cast(buffer());
+}
+
+
+//
+// AsyncReadCommand
+//
+
+
+AsyncReadCommand::AsyncReadCommand(void* buffer, int length):
+ _buffer(buffer),
+ _length(length)
+{
+}
+
+
+AsyncReadCommand::~AsyncReadCommand()
+{
+}
+
+
+int AsyncReadCommand::executeImpl(AsyncIOChannel& channel)
+{
+ return channel.read(_buffer, _length);
+}
+
+
+//
+// AsyncBufferedReadCommand
+//
+
+
+AsyncBufferedReadCommand::AsyncBufferedReadCommand(int length):
+ AsyncReadCommand(new char[length], length)
+{
+}
+
+
+AsyncBufferedReadCommand::~AsyncBufferedReadCommand()
+{
+ delete [] reinterpret_cast(buffer());
+}
+
+
+//
+// AsyncSeekCommand
+//
+
+
+AsyncSeekCommand::AsyncSeekCommand(std::streamoff off, std::ios::seekdir dir):
+ _off(off),
+ _dir(dir)
+{
+}
+
+
+AsyncSeekCommand::~AsyncSeekCommand()
+{
+}
+
+
+int AsyncSeekCommand::executeImpl(AsyncIOChannel& channel)
+{
+ return channel.seek(_off, _dir);
+}
+
+
+} // namespace Poco
diff --git a/Foundation/src/AsyncIOEvent.cpp b/Foundation/src/AsyncIOEvent.cpp
new file mode 100644
index 000000000..e371b2a92
--- /dev/null
+++ b/Foundation/src/AsyncIOEvent.cpp
@@ -0,0 +1,88 @@
+//
+// AsyncIOEvent.cpp
+//
+// $Id: //poco/Main/Foundation/src/AsyncIOEvent.cpp#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncIOEvent
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/AsyncIOEvent.h"
+#include "Poco/AsyncIOCommand.h"
+#include
+
+
+namespace Poco {
+
+
+AsyncIOEvent::AsyncIOEvent(AsyncIOCommand* pCommand, AsyncIOChannel* pChannel, EventKind what):
+ _pCommand(pCommand),
+ _pChannel(pChannel),
+ _what(what)
+{
+ poco_check_ptr (pCommand);
+ poco_check_ptr (pChannel);
+
+ _pCommand->duplicate();
+}
+
+
+AsyncIOEvent::AsyncIOEvent(const AsyncIOEvent& event):
+ _pCommand(event._pCommand),
+ _pChannel(event._pChannel),
+ _what(event._what)
+{
+ _pCommand->duplicate();
+}
+
+
+AsyncIOEvent::~AsyncIOEvent()
+{
+ _pCommand->release();
+}
+
+
+AsyncIOEvent& AsyncIOEvent::operator = (const AsyncIOEvent& event)
+{
+ AsyncIOEvent tmp(event);
+ swap(tmp);
+ return *this;
+}
+
+
+void AsyncIOEvent::swap(AsyncIOEvent& event)
+{
+ std::swap(_pCommand, event._pCommand);
+ std::swap(_pChannel, event._pChannel);
+ std::swap(_what, event._what);
+}
+
+
+} // namespace Poco
diff --git a/Foundation/src/AsyncStreamChannel.cpp b/Foundation/src/AsyncStreamChannel.cpp
new file mode 100644
index 000000000..69d972249
--- /dev/null
+++ b/Foundation/src/AsyncStreamChannel.cpp
@@ -0,0 +1,100 @@
+//
+// AsyncStreamChannel.cpp
+//
+// $Id: //poco/Main/Foundation/src/AsyncStreamChannel.cpp#1 $
+//
+// Library: Foundation
+// Package: AsyncIO
+// Module: AsyncStreamChannel
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "Poco/AsyncStreamChannel.h"
+#include "Poco/Exception.h"
+
+
+namespace Poco {
+
+
+AsyncStreamChannel::AsyncStreamChannel(std::istream& istr):
+ _pIstr(&istr),
+ _pOstr(0)
+{
+}
+
+
+AsyncStreamChannel::AsyncStreamChannel(std::ostream& ostr):
+ _pIstr(0),
+ _pOstr(&ostr)
+{
+}
+
+
+AsyncStreamChannel::AsyncStreamChannel(std::iostream& iostr):
+ _pIstr(&iostr),
+ _pOstr(&iostr)
+{
+}
+
+
+AsyncStreamChannel::~AsyncStreamChannel()
+{
+}
+
+
+int AsyncStreamChannel::write(const void* buffer, int length)
+{
+ if (_pOstr)
+ {
+ _pOstr->write(reinterpret_cast(buffer), length);
+ return length;
+ }
+ else throw IOException("Cannot write to an input stream");
+}
+
+
+int AsyncStreamChannel::read(void* buffer, int length)
+{
+ if (_pIstr)
+ return static_cast(_pIstr->read(reinterpret_cast(buffer), length).gcount());
+ else
+ throw IOException("Cannot read from an output stream");
+}
+
+
+int AsyncStreamChannel::seek(std::streamoff off, std::ios::seekdir dir)
+{
+ if (_pIstr)
+ _pIstr->seekg(off, dir);
+ if (_pOstr)
+ _pOstr->seekp(off, dir);
+ return 0;
+}
+
+
+} // namespace Poco
diff --git a/Foundation/src/MSG00001.bin b/Foundation/src/MSG00001.bin
index 45ecf37e0..be19fe466 100644
Binary files a/Foundation/src/MSG00001.bin and b/Foundation/src/MSG00001.bin differ
diff --git a/Foundation/src/pocomsg.h b/Foundation/src/pocomsg.h
index 4aefa5ca5..3beca6676 100644
--- a/Foundation/src/pocomsg.h
+++ b/Foundation/src/pocomsg.h
@@ -1,7 +1,7 @@
//
// pocomsg.mc[.h]
//
-// $Id: //poco/Main/Foundation/src/pocomsg.mc#7 $
+// $Id: //poco/Main/Foundation/src/pocomsg.h#26 $
//
// The Poco message source/header file.
//
diff --git a/Foundation/testsuite/Makefile-Driver b/Foundation/testsuite/Makefile-Driver
index 8b164b4a1..79b2ea64f 100644
--- a/Foundation/testsuite/Makefile-Driver
+++ b/Foundation/testsuite/Makefile-Driver
@@ -1,7 +1,7 @@
#
# Makefile
#
-# $Id: //poco/Main/Foundation/testsuite/Makefile-Driver#35 $
+# $Id: //poco/Main/Foundation/testsuite/Makefile-Driver#36 $
#
# Makefile for Poco Foundation testsuite
#
@@ -37,7 +37,8 @@ objects = ActiveMethodTest ActivityTest ActiveDispatcherTest \
HashingTestSuite HashTableTest SimpleHashTableTest LinearHashTableTest \
HashSetTest HashMapTest SharedMemoryTest \
UniqueExpireCacheTest UniqueExpireLRUCacheTest \
- TuplesTest NamedTuplesTest TypeListTest DynamicAnyTest FileStreamTest
+ TuplesTest NamedTuplesTest TypeListTest DynamicAnyTest FileStreamTest \
+ AsyncIOTestSuite AsyncIOChannelTest
target = testrunner
target_version = 1
diff --git a/Foundation/testsuite/TestSuite_vs71.vcproj b/Foundation/testsuite/TestSuite_vs71.vcproj
index c0452b2f5..0618c0d81 100644
--- a/Foundation/testsuite/TestSuite_vs71.vcproj
+++ b/Foundation/testsuite/TestSuite_vs71.vcproj
@@ -1209,6 +1209,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Foundation/testsuite/TestSuite_vs80.vcproj b/Foundation/testsuite/TestSuite_vs80.vcproj
index 2792a77a8..a96fd5e66 100644
--- a/Foundation/testsuite/TestSuite_vs80.vcproj
+++ b/Foundation/testsuite/TestSuite_vs80.vcproj
@@ -1576,6 +1576,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Foundation/testsuite/src/AsyncIOChannelTest.cpp b/Foundation/testsuite/src/AsyncIOChannelTest.cpp
new file mode 100644
index 000000000..9af8bdde6
--- /dev/null
+++ b/Foundation/testsuite/src/AsyncIOChannelTest.cpp
@@ -0,0 +1,183 @@
+//
+// AsyncIOChannelTest.cpp
+//
+// $Id: //poco/Main/Foundation/testsuite/src/AsyncIOChannelTest.cpp#1 $
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "AsyncIOChannelTest.h"
+#include "CppUnit/TestCaller.h"
+#include "CppUnit/TestSuite.h"
+#include "Poco/AsyncStreamChannel.h"
+#include "Poco/AsyncIOCommand.h"
+#include "Poco/AsyncIOEvent.h"
+#include "Poco/Delegate.h"
+#include
+
+
+using Poco::AsyncStreamChannel;
+using Poco::AsyncIOCommand;
+using Poco::AsyncReadCommand;
+using Poco::AsyncWriteCommand;
+using Poco::AsyncSeekCommand;
+using Poco::AsyncIOEvent;
+using Poco::ActiveResult;
+using Poco::delegate;
+
+
+AsyncIOChannelTest::AsyncIOChannelTest(const std::string& name):
+ CppUnit::TestCase(name),
+ _completed(0),
+ _failed(0)
+{
+}
+
+
+AsyncIOChannelTest::~AsyncIOChannelTest()
+{
+}
+
+
+void AsyncIOChannelTest::testWrite()
+{
+ std::stringstream str;
+ AsyncStreamChannel channel(str);
+ channel.enqueue(new AsyncWriteCommand("Hello", 5));
+ channel.enqueue(new AsyncWriteCommand(", ", 2));
+ ActiveResult result = channel.enqueue(new AsyncWriteCommand("world!", 6));
+ result.wait();
+ std::string s(str.str());
+ assert (s == "Hello, world!");
+}
+
+
+void AsyncIOChannelTest::testRead()
+{
+ std::istringstream istr("Hello, world!");
+ char buffer[16];
+ AsyncStreamChannel channel(istr);
+ ActiveResult result = channel.enqueue(new AsyncReadCommand(buffer, sizeof(buffer)));
+ result.wait();
+ std::string s(buffer, result.data());
+ assert (s == "Hello, world!");
+}
+
+
+void AsyncIOChannelTest::testSeek()
+{
+ std::istringstream istr("Hello, world!");
+ char buffer[16];
+ AsyncStreamChannel channel(istr);
+ channel.enqueue(new AsyncSeekCommand(7, std::ios::beg));
+ ActiveResult result = channel.enqueue(new AsyncReadCommand(buffer, 5));
+ result.wait();
+ std::string s(buffer, result.data());
+ assert (s == "world");
+}
+
+
+void AsyncIOChannelTest::testEvents()
+{
+ std::stringstream str;
+ AsyncStreamChannel channel(str);
+ AsyncIOCommand::Ptr pWrite(new AsyncWriteCommand("Hello, world!", 13));
+ pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
+ channel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
+ assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
+ ActiveResult result = channel.enqueue(pWrite);
+ pWrite->wait();
+ result.wait();
+ assert (pWrite->succeeded());
+ assert (!pWrite->failed());
+ assert (pWrite->state() == AsyncIOCommand::CMD_COMPLETED);
+ assert (pWrite->result() == 13);
+ assert (pWrite->exception() == 0);
+ assert (_completed == 2);
+
+ reset();
+
+ std::istringstream istr;
+ AsyncStreamChannel ichannel(istr);
+ pWrite = new AsyncWriteCommand("Hello, world!", 13);
+ pWrite->commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
+ ichannel.commandFailed += delegate(this, &AsyncIOChannelTest::onFailed);
+ pWrite->commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
+ ichannel.commandCompleted += delegate(this, &AsyncIOChannelTest::onCompleted);
+ assert (pWrite->state() == AsyncIOCommand::CMD_PENDING);
+ result = ichannel.enqueue(pWrite);
+ pWrite->wait();
+ result.wait();
+ assert (!pWrite->succeeded());
+ assert (pWrite->failed());
+ assert (pWrite->exception() != 0);
+ assert (_completed == 0);
+ assert (_failed == 2);
+}
+
+
+void AsyncIOChannelTest::setUp()
+{
+ reset();
+}
+
+
+void AsyncIOChannelTest::tearDown()
+{
+}
+
+
+void AsyncIOChannelTest::reset()
+{
+ _completed = 0;
+ _failed = 0;
+}
+
+
+void AsyncIOChannelTest::onCompleted(const void* sender, Poco::AsyncIOEvent& event)
+{
+ ++_completed;
+}
+
+
+void AsyncIOChannelTest::onFailed(const void* sender, Poco::AsyncIOEvent& event)
+{
+ ++_failed;
+}
+
+
+CppUnit::Test* AsyncIOChannelTest::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOChannelTest");
+
+ CppUnit_addTest(pSuite, AsyncIOChannelTest, testWrite);
+ CppUnit_addTest(pSuite, AsyncIOChannelTest, testRead);
+ CppUnit_addTest(pSuite, AsyncIOChannelTest, testSeek);
+ CppUnit_addTest(pSuite, AsyncIOChannelTest, testEvents);
+
+ return pSuite;
+}
diff --git a/Foundation/testsuite/src/AsyncIOChannelTest.h b/Foundation/testsuite/src/AsyncIOChannelTest.h
new file mode 100644
index 000000000..17c59e61b
--- /dev/null
+++ b/Foundation/testsuite/src/AsyncIOChannelTest.h
@@ -0,0 +1,71 @@
+//
+// AsyncIOChannelTest.h
+//
+// $Id: //poco/Main/Foundation/testsuite/src/AsyncIOChannelTest.h#1 $
+//
+// Definition of the AsyncIOChannelTest class.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef AsyncIOChannelTest_INCLUDED
+#define AsyncIOChannelTest_INCLUDED
+
+
+#include "Poco/Foundation.h"
+#include "CppUnit/TestCase.h"
+#include "Poco/AsyncIOEvent.h"
+
+
+class AsyncIOChannelTest: public CppUnit::TestCase
+{
+public:
+ AsyncIOChannelTest(const std::string& name);
+ ~AsyncIOChannelTest();
+
+ void testWrite();
+ void testRead();
+ void testSeek();
+ void testEvents();
+
+ void setUp();
+ void tearDown();
+
+ static CppUnit::Test* suite();
+
+protected:
+ void reset();
+ void onCompleted(const void* sender, Poco::AsyncIOEvent& event);
+ void onFailed(const void* sender, Poco::AsyncIOEvent& event);
+
+private:
+ int _completed;
+ int _failed;
+};
+
+
+#endif // AsyncIOChannelTest_INCLUDED
diff --git a/Foundation/testsuite/src/AsyncIOTestSuite.cpp b/Foundation/testsuite/src/AsyncIOTestSuite.cpp
new file mode 100644
index 000000000..ae4d20264
--- /dev/null
+++ b/Foundation/testsuite/src/AsyncIOTestSuite.cpp
@@ -0,0 +1,44 @@
+//
+// AsyncIOTestSuite.cpp
+//
+// $Id: //poco/Main/Foundation/testsuite/src/AsyncIOTestSuite.cpp#1 $
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#include "AsyncIOTestSuite.h"
+#include "AsyncIOChannelTest.h"
+
+
+CppUnit::Test* AsyncIOTestSuite::suite()
+{
+ CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AsyncIOTestSuite");
+
+ pSuite->addTest(AsyncIOChannelTest::suite());
+
+ return pSuite;
+}
diff --git a/Foundation/testsuite/src/AsyncIOTestSuite.h b/Foundation/testsuite/src/AsyncIOTestSuite.h
new file mode 100644
index 000000000..64fd34886
--- /dev/null
+++ b/Foundation/testsuite/src/AsyncIOTestSuite.h
@@ -0,0 +1,49 @@
+//
+// AsyncIOTestSuite.h
+//
+// $Id: //poco/Main/Foundation/testsuite/src/AsyncIOTestSuite.h#1 $
+//
+// Definition of the AsyncIOTestSuite class.
+//
+// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
+// and Contributors.
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+
+
+#ifndef AsyncIOTestSuite_INCLUDED
+#define AsyncIOTestSuite_INCLUDED
+
+
+#include "CppUnit/TestSuite.h"
+
+
+class AsyncIOTestSuite
+{
+public:
+ static CppUnit::Test* suite();
+};
+
+
+#endif // AsyncIOTestSuite_INCLUDED
diff --git a/Foundation/testsuite/src/FoundationTestSuite.cpp b/Foundation/testsuite/src/FoundationTestSuite.cpp
index 5ebd1a6ec..ce5c3ede8 100644
--- a/Foundation/testsuite/src/FoundationTestSuite.cpp
+++ b/Foundation/testsuite/src/FoundationTestSuite.cpp
@@ -1,7 +1,7 @@
//
// FoundationTestSuite.cpp
//
-// $Id: //poco/Main/Foundation/testsuite/src/FoundationTestSuite.cpp#12 $
+// $Id: //poco/Main/Foundation/testsuite/src/FoundationTestSuite.cpp#13 $
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -48,6 +48,7 @@
#include "EventTestSuite.h"
#include "CacheTestSuite.h"
#include "HashingTestSuite.h"
+#include "AsyncIOTestSuite.h"
CppUnit::Test* FoundationTestSuite::suite()
@@ -71,6 +72,7 @@ CppUnit::Test* FoundationTestSuite::suite()
pSuite->addTest(EventTestSuite::suite());
pSuite->addTest(CacheTestSuite::suite());
pSuite->addTest(HashingTestSuite::suite());
+ pSuite->addTest(AsyncIOTestSuite::suite());
return pSuite;
}