moved IO (sync and async) from Foundation and Net to IO, IO::Serial and IO::Socket;

only MS VS80 and Unix Makefiles are up to date with this modification
This commit is contained in:
Aleksandar Fabijanic 2008-03-22 21:28:05 +00:00
parent d2de70c58a
commit e41a7aef2e
35 changed files with 10 additions and 3695 deletions

View File

@ -1,12 +1,15 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Foundation", "Foundation_vs80.vcproj", "{8164D41D-B053-405B-826C-CF37AC0EF176}"
ProjectSection(ProjectDependencies) = postProject
{AA986945-F3B6-4381-94BB-14DD49202B40} = {AA986945-F3B6-4381-94BB-14DD49202B40}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_vs80.vcproj", "{F1EE93DF-347F-4CB3-B191-C4E63F38E972}"
ProjectSection(ProjectDependencies) = postProject
{0955EB03-544B-4BD4-9C10-89CF38078F5F} = {0955EB03-544B-4BD4-9C10-89CF38078F5F}
{8164D41D-B053-405B-826C-CF37AC0EF176} = {8164D41D-B053-405B-826C-CF37AC0EF176}
{6C41E55D-C0FC-4E01-AA8D-B7DA40E31D3A} = {6C41E55D-C0FC-4E01-AA8D-B7DA40E31D3A}
{8164D41D-B053-405B-826C-CF37AC0EF176} = {8164D41D-B053-405B-826C-CF37AC0EF176}
{0955EB03-544B-4BD4-9C10-89CF38078F5F} = {0955EB03-544B-4BD4-9C10-89CF38078F5F}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLibrary", "testsuite\TestLibrary_vs80.vcproj", "{0955EB03-544B-4BD4-9C10-89CF38078F5F}"

View File

@ -4741,90 +4741,6 @@
</File>
</Filter>
</Filter>
<Filter
Name="AsyncIO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\AsyncIOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\AsyncIOCommand.h"
>
</File>
<File
RelativePath=".\include\Poco\AsyncIOEvent.h"
>
</File>
<File
RelativePath=".\include\Poco\AsyncStreamChannel.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\AsyncIOChannel.cpp"
>
</File>
<File
RelativePath=".\src\AsyncIOCommand.cpp"
>
</File>
<File
RelativePath=".\src\AsyncIOEvent.cpp"
>
</File>
<File
RelativePath=".\src\AsyncStreamChannel.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="IO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\ActiveIOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannelConfig.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannelStream.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\IOChannel.cpp"
>
</File>
<File
RelativePath=".\src\IOChannelConfig.cpp"
>
</File>
<File
RelativePath=".\src\IOChannelStream.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -10,9 +10,9 @@ include $(POCO_BASE)/build/rules/global
objects = ArchiveStrategy ASCIIEncoding AsyncChannel Base64Decoder Base64Encoder \
BinaryReader BinaryWriter Bugcheck ByteOrder Channel Checksum Configurable ConsoleChannel \
IOChannel IOChannelConfig IOChannelStream \
CountingStream DateTime LocalDateTime DateTimeFormat DateTimeFormatter DateTimeParser \
Debugger DeflatingStream DigestEngine DigestStream DirectoryIterator \
DynamicAny DynamicAnyHolder DynamicStruct \
Environment Event EventArgs ErrorHandler Exception FPEnvironment File Glob \
FileChannel Formatter FormattingChannel HexBinaryDecoder LineEndingConverter \
HexBinaryEncoder InflatingStream Latin1Encoding Latin9Encoding LogFile Logger \
@ -30,9 +30,8 @@ objects = ArchiveStrategy ASCIIEncoding AsyncChannel Base64Decoder Base64Encoder
ThreadPool ActiveDispatcher Timer Timespan Timestamp Timezone Token URI \
FileStreamFactory URIStreamFactory URIStreamOpener UTF16Encoding Windows1252Encoding \
UTF8Encoding UnicodeConverter UUID UUIDGenerator Void Format \
Pipe PipeImpl PipeStream DynamicAny DynamicAnyHolder DynamicStruct SharedMemory \
FileStream Unicode UTF8String AsyncIOCommand AsyncIOEvent AsyncIOChannel AsyncStreamChannel \
adler32 compress crc32 deflate gzio infback inffast inflate inftrees trees zutil \
Pipe PipeImpl PipeStream SharedMemory FileStream Unicode UTF8String \
adler32 compress crc32 deflate gzio infback inffast inflate inftrees trees zutil \
pcre_chartables pcre_compile pcre_globals pcre_maketables pcre_study \
pcre_tables pcre_try_flipped pcre_ucp_searchfuncs pcre_valid_utf8 \
pcre_exec pcre_ord2utf8 pcre_newline pcre_fullinfo pcre_xclass

View File

@ -1,89 +0,0 @@
//
// ActiveIOChannel.h
//
// $Id: //poco/Main/Data/include/Poco/ActiveIOChannel.h#1 $
//
// Library: Foundation
// Package: Foundation
// Module: ActiveIOChannel
//
// Definition of the ActiveIOChannel class.
//
// Copyright (c) 2006, 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 CONNECTFoundationN WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Foundation_ActiveIOChannel_INCLUDED
#define Foundation_ActiveIOChannel_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/ActiveMethod.h"
#include "Poco/Void.h"
namespace Poco {
template <class P>
class ActiveIOChannel
{
public:
ActiveIOChannel(P& channel):
read(this, &ActiveIOChannel::readImpl),
write(this, &ActiveIOChannel::writeImpl),
_channel(channel)
{
}
~ActiveIOChannel()
{
}
Poco::ActiveMethod<std::string, Void, ActiveIOChannel> read;
Poco::ActiveMethod<int, std::string, ActiveIOChannel> write;
protected:
std::string readImpl(const Void&)
{
std::string buffer;
return _channel.read(buffer);
}
int writeImpl(const std::string& data)
{
return _channel.write(data);
}
private:
P& _channel;
};
} // namespace Poco
#endif // Foundation_ActiveIOChannel_INCLUDED

View File

@ -1,154 +0,0 @@
//
// AsyncIOChannel.h
//
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOChannel.h#2 $
//
// 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<int>. 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<int, AsyncIOCommand::Ptr, AsyncIOChannel, ActiveStarter<ActiveDispatcher> > 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<AsyncIOEvent> commandCompleted;
/// Fired when a command has successfully completed.
BasicEvent<AsyncIOEvent> 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

View File

@ -1,319 +0,0 @@
//
// AsyncIOCommand.h
//
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOCommand.h#2 $
//
// 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 <ios>
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<AsyncIOCommand> 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<AsyncIOEvent> commandCompleted;
/// Fired when the command has successfully completed.
BasicEvent<AsyncIOEvent> 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

View File

@ -1,121 +0,0 @@
//
// AsyncIOEvent.h
//
// $Id: //poco/svn/Foundation/include/Poco/AsyncIOEvent.h#2 $
//
// 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

View File

@ -1,96 +0,0 @@
//
// AsyncStreamChannel.h
//
// $Id: //poco/svn/Foundation/include/Poco/AsyncStreamChannel.h#2 $
//
// 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 <istream>
#include <ostream>
#include <iostream>
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<int> 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

View File

@ -1,242 +0,0 @@
//
// IOChannel.h
//
// $Id: //poco/svn/Foundation/include/Poco/IOChannel.h#2 $
//
// Library: Foundation
// Package: IO
// Module: IOChannel
//
// Definition of the IOChannel 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_IOChannel_INCLUDED
#define Foundation_IOChannel_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/IOChannelConfig.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
namespace Poco {
class Foundation_API IOChannel: public RefCountedObject
/// IOChannel supports I/O operations on streams or other input/output facilities.
///
/// IOChannel supports blocking (default) and non-blocking read and write operations.
{
public:
typedef AutoPtr<IOChannelConfig> ConfigPtr;
IOChannel(const std::string& name = "");
/// Creates the IOChannel.
IOChannel(IOChannelConfig* pConfig, const std::string& name = "");
/// Creates the IOChannel with specified configuration.
virtual ~IOChannel();
/// Destroys the IOChannel.
virtual void open() = 0;
/// Opens the channel.
virtual void close() = 0;
/// Closes the channel.
std::string& read(std::string& buffer, int length = 0);
/// Read up to length bytes into the supplied buffer.
/// If length is 0, the channel implementation must provide
/// support for the termination of transmission.
/// Also, in case when length is 0 and the channel implementation
/// provides the buffer length and termination character
/// information, it also allocates the buffer. The buffer,
/// however, is always freed in this function, regardless of where
/// it was allocated. See readData(char*&) for more information.
const std::string& read(int length);
/// Read up to length bytes and return the reference to internal buffer.
int read(char* pReadBuf, int length);
/// Reads a string of characters from the channel.
int write(char c);
/// Writes a character to the channel.
int write(const char* buffer, int length);
/// Write length bytes from buffer.
/// Returns the number of bytes written.
int write(const std::string& data);
/// Writes a string of characters to the channel.
char read();
/// Reads one character from the channel.
const std::string& name() const;
/// Returns the channel name.
virtual void setTimeout(int timeoutMS);
/// Sets timeout in milliseconds.
virtual void setBlocking();
/// Sets blocking operation.
virtual void setNonblocking(int timeoutMS);
/// Sets non-blocking operation by calling setTimeout().
int getTimeout() const;
/// Returns timeout in milliseconds.
bool isBlocking() const;
/// Returns true if operation is blocking, false otherwise.
protected:
IOChannelConfig& config();
/// Returns the reference to the configuration for this cahannel.
virtual void init();
/// (Re)initializes the internal channel configuration.
/// Does nothing in this implementation.
virtual int readData(char* pReadBuf, int length) = 0;
/// Reads length bytes and puts them in the buffer.
/// Must be implemented by the inheriting class.
virtual int readData(char*& pReadBuf) = 0;
/// Reads an unspecified amount of bytes and places them in the buffer.
/// Properly behaved implementation of this function reads bytes and places
/// them in the buffer. Buffer is allocated by the implementation as
/// needed. Implementation must provide a way to terminate the communication
/// session.
/// Important: this function is called from read(std::string, int length) when
/// the length is zero. The buffer allocated in the implementation of this function
/// is always freed in the caller function.
virtual int writeData(const char* buffer, int length) = 0;
/// Writes length bytes from buffer to the target.
/// Must be implemented by the inheriting class.
private:
IOChannel(const IOChannel&);
IOChannel& operator = (const IOChannel&);
std::string _name;
std::string _buffer;
ConfigPtr _pConfig;
};
//
// inlines
//
inline IOChannelConfig& IOChannel::config()
{
return *_pConfig;
}
inline void IOChannel::init()
{
}
inline const std::string& IOChannel::name() const
{
return _name;
}
inline const std::string& IOChannel::read(int length)
{
return read(_buffer, length);
}
inline int IOChannel::read(char* pReadBuf, int length)
{
return readData(pReadBuf, length);
}
inline int IOChannel::write(char c)
{
return writeData(&c, 1);
}
inline int IOChannel::write(const std::string& data)
{
return writeData(data.data(), static_cast<int>(data.size()));
}
inline int IOChannel::write(const char* buffer, int length)
{
return writeData(buffer, length);
}
inline void IOChannel::setTimeout(int timeoutMS)
{
_pConfig->setTimeout(timeoutMS);
}
inline void IOChannel::setBlocking()
{
_pConfig->setBlocking();
}
inline void IOChannel::setNonblocking(int timeoutMS)
{
setTimeout(timeoutMS);
}
inline int IOChannel::getTimeout() const
{
return _pConfig->getTimeout();
}
inline bool IOChannel::isBlocking() const
{
return _pConfig->isBlocking();
}
} // namespace Poco
#endif // Foundation_IOChannel_INCLUDED

View File

@ -1,158 +0,0 @@
//
// IOChannelConfig.h
//
// $Id: //poco/Main/Data/include/Poco/IOChannelConfig.h#1 $
//
// Library: Foundation
// Package: IO
// Module: IOChannelConfig
//
// Definition of the IOChannelConfig class.
//
// Copyright (c) 2006, 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_IOChannelConfig_INCLUDED
#define Foundation_IOChannelConfig_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/RefCountedObject.h"
namespace Poco {
class Foundation_API IOChannelConfig: public RefCountedObject
{
public:
enum ChannelType
{
CONNECTION_CHANNEL,
CONNECTIONLESS_CHANNEL
};
IOChannelConfig(const std::string& name = "",
ChannelType type = CONNECTION_CHANNEL,
int timeoutMS = INFINITE_TIMEOUT);
/// Creates IOChannelConfig.
virtual ~IOChannelConfig();
/// Destroys IOChannelConfig.
virtual void setTimeout(int timeoutMS);
/// Sets timeout in milliseconds.
int getTimeout() const;
/// Returns timeout in milliseconds.
virtual void setBlocking();
/// Sets blocking operation.
virtual void setNonblocking(int timeoutMS);
/// Sets blocking operation.
bool isBlocking() const;
/// Returns true if operation is blocking, false otherwise.
void setName(const std::string& name);
/// Sets the channel name.
const std::string& getName() const;
/// Returns the channel name.
void setType(ChannelType type);
/// Sets the channel name.
ChannelType getType() const;
/// Returns the channel name.
static const int INFINITE_TIMEOUT = -1;
private:
std::string _name;
ChannelType _type;
int _timeoutMS;
};
//
// inlines
//
inline void IOChannelConfig::setBlocking()
{
_timeoutMS = INFINITE_TIMEOUT;
}
inline void IOChannelConfig::setNonblocking(int timeoutMS)
{
_timeoutMS = timeoutMS;
}
inline int IOChannelConfig::getTimeout() const
{
return _timeoutMS;
}
inline bool IOChannelConfig::isBlocking() const
{
return INFINITE_TIMEOUT == _timeoutMS;
}
inline void IOChannelConfig::setName(const std::string& name)
{
_name = name;
}
inline const std::string& IOChannelConfig::getName() const
{
return _name;
}
inline void IOChannelConfig::setType(ChannelType type)
{
_type = type;
}
inline IOChannelConfig::ChannelType IOChannelConfig::getType() const
{
return _type;
}
} // namespace Poco
#endif // Foundation_IOChannelConfig_INCLUDED

View File

@ -1,130 +0,0 @@
//
// IOChannelStream.h
//
// $Id: //poco/Main/Data/include/Poco/IOChannelStream.h#1 $
//
// Library: Poco
// Package: IO
// Module: IOChannelStream
//
// Definition of the IOChannelStream class.
//
// Copyright (c) 2004-2006, 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_IOChannelStream_INCLUDED
#define Foundation_IOChannelStream_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/UnbufferedStreamBuf.h"
#include "Poco/IOChannel.h"
#include <istream>
#include <ostream>
namespace Poco {
class Foundation_API IOChannelStreamBuf: public UnbufferedStreamBuf
/// This is the streambuf class used for reading from and writing to a IOChannel.
{
public:
IOChannelStreamBuf(IOChannel& channel);
/// Creates a IOChannelStreamBuf with the given IOChannel.
~IOChannelStreamBuf();
/// Destroys the IOChannelStreamBuf.
void close();
/// Closes the channel.
protected:
int_type readFromDevice();
int_type writeToDevice(char c);
private:
IOChannel& _channel;
};
class Foundation_API IOChannelIOS: public virtual std::ios
/// The base class for IOChannelInputStream and
/// IOChannelOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
IOChannelIOS(IOChannel& channel, openmode mode);
/// Creates the IOChannelIOS with the given IOChannel.
~IOChannelIOS();
/// Destroys the IOChannelIOS.
IOChannelStreamBuf* rdbuf();
/// Returns a pointer to the internal IOChannelStreamBuf.
protected:
IOChannelStreamBuf _buf;
};
class Foundation_API IOChannelOutputStream: public IOChannelIOS, public std::ostream
/// An output stream for writing to a IOChannel.
{
public:
IOChannelOutputStream(IOChannel& channel);
/// Creates the IOChannelOutputStream with the given IOChannel.
~IOChannelOutputStream();
/// Destroys the IOChannelOutputStream.
///
/// Flushes the buffer, but does not close the channel.
};
class Foundation_API IOChannelInputStream: public IOChannelIOS, public std::istream
/// An input stream for reading from a IOChannel.
///
/// Using formatted input from a IOChannelInputStream
/// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads.
{
public:
IOChannelInputStream(IOChannel& channel);
/// Creates the IOChannelInputStream with the given IOChannel.
~IOChannelInputStream();
/// Destroys the IOChannelInputStream.
};
} // namespace Poco
#endif // Foundation_IOChannelStream_INCLUDED

View File

@ -1,79 +0,0 @@
//
// AsyncIOChannel.cpp
//
// $Id: //poco/svn/Foundation/src/AsyncIOChannel.cpp#2 $
//
// 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

View File

@ -1,236 +0,0 @@
//
// AsyncIOCommand.cpp
//
// $Id: //poco/svn/Foundation/src/AsyncIOCommand.cpp#2 $
//
// 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 <cstring>
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<void*>(buffer()), buf, length);
}
AsyncBufferedWriteCommand::~AsyncBufferedWriteCommand()
{
delete [] reinterpret_cast<const char*>(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<char*>(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

View File

@ -1,88 +0,0 @@
//
// AsyncIOEvent.cpp
//
// $Id: //poco/svn/Foundation/src/AsyncIOEvent.cpp#2 $
//
// 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 <algorithm>
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

View File

@ -1,100 +0,0 @@
//
// AsyncStreamChannel.cpp
//
// $Id: //poco/svn/Foundation/src/AsyncStreamChannel.cpp#2 $
//
// 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<const char*>(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<int>(_pIstr->read(reinterpret_cast<char*>(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

View File

@ -1,93 +0,0 @@
//
// IOChannel.cpp
//
// $Id: //poco/svn/Foundation/src/IOChannel.cpp#2 $
//
// Library: Foundation
// Package: IO
// Module: IOChannel
//
// 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/IOChannel.h"
namespace Poco {
IOChannel::IOChannel(const std::string& name):
_name(name),
_pConfig(new IOChannelConfig)
{
}
IOChannel::IOChannel(IOChannelConfig* pConfig, const std::string& name):
_name(name),
_pConfig(pConfig)
{
}
IOChannel::~IOChannel()
{
}
char IOChannel::read()
{
char readBuf = 0;
char* pReadBuf = &readBuf;
readData(pReadBuf, 1);
return readBuf;
}
std::string& IOChannel::read(std::string& buffer, int length)
{
buffer.clear();
char* pBuf = 0;
int len = 0;
if (length > 0)
{
pBuf = static_cast<char*>(std::calloc(length, sizeof(char)));
len = readData(pBuf, length);
}
else
len = readData(pBuf); // must allocate buffer as needed
if (len > 0) buffer.assign(pBuf, len);
std::free(pBuf);
return buffer;
}
} // namespace Poco

View File

@ -1,67 +0,0 @@
//
// SerialConfig.cpp
//
// $Id: //poco/Main/IO/src/IOChannelConfig.cpp#1 $
//
// Library: Foundation
// Package: IO
// Module: IOChannelConfig
//
// Copyright (c) 2006, 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/IOChannelConfig.h"
#include "Poco/Exception.h"
namespace Poco {
IOChannelConfig::IOChannelConfig(const std::string& name, ChannelType type, int timeoutMS):
_name(name),
_type(type),
_timeoutMS(timeoutMS)
{
}
IOChannelConfig::~IOChannelConfig()
{
}
void IOChannelConfig::setTimeout(int timeoutMS)
{
if (timeoutMS < 0 && INFINITE_TIMEOUT != timeoutMS)
throw InvalidArgumentException("Invalid timeout value");
_timeoutMS = timeoutMS;
}
} // namespace Poco::IO

View File

@ -1,111 +0,0 @@
//
// DigestStream.cpp
//
// $Id: //poco/1.2/IO/src/IOChannelStream.cpp#1 $
//
// Library: IO
// Package: IO
// Module: IOChannelStream
//
// Copyright (c) 2004-2006, 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/IOChannelStream.h"
namespace Poco {
IOChannelStreamBuf::IOChannelStreamBuf(IOChannel& channel): _channel(channel)
{
}
IOChannelStreamBuf::~IOChannelStreamBuf()
{
}
void IOChannelStreamBuf::close()
{
_channel.close();
}
UnbufferedStreamBuf::int_type IOChannelStreamBuf::readFromDevice()
{
return charToInt(_channel.read());
}
UnbufferedStreamBuf::int_type IOChannelStreamBuf::writeToDevice(char c)
{
return _channel.write(c);
}
IOChannelIOS::IOChannelIOS(IOChannel& channel, openmode mode) :_buf(channel)
{
poco_ios_init(&_buf);
}
IOChannelIOS::~IOChannelIOS()
{
}
IOChannelStreamBuf* IOChannelIOS::rdbuf()
{
return &_buf;
}
IOChannelOutputStream::IOChannelOutputStream(IOChannel& channel):
IOChannelIOS(channel, std::ios::out),
std::ostream(&_buf)
{
}
IOChannelOutputStream::~IOChannelOutputStream()
{
}
IOChannelInputStream::IOChannelInputStream(IOChannel& channel):
IOChannelIOS(channel, std::ios::in),
std::istream(&_buf)
{
}
IOChannelInputStream::~IOChannelInputStream()
{
}
} // namespace Poco

View File

@ -1,183 +0,0 @@
//
// AsyncIOChannelTest.cpp
//
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.cpp#2 $
//
// 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 <sstream>
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<int> 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<int> 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<int> 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<int> 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;
}

View File

@ -1,71 +0,0 @@
//
// AsyncIOChannelTest.h
//
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOChannelTest.h#2 $
//
// 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

View File

@ -1,44 +0,0 @@
//
// AsyncIOTestSuite.cpp
//
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.cpp#2 $
//
// 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;
}

View File

@ -1,49 +0,0 @@
//
// AsyncIOTestSuite.h
//
// $Id: //poco/svn/Foundation/testsuite/src/AsyncIOTestSuite.h#2 $
//
// 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

View File

@ -29,8 +29,7 @@ objects = \
MailRecipient MailMessage MailStream SMTPClientSession POP3ClientSession \
RawSocket RawSocketImpl ICMPClient ICMPEventArgs ICMPPacket ICMPPacketImpl \
ICMPSocket ICMPSocketImpl ICMPv4PacketImpl \
RemoteSyslogChannel RemoteSyslogListener SMTPChannel \
AsyncSocketChannel SocketIOChannel
RemoteSyslogChannel RemoteSyslogListener SMTPChannel
target = PocoNet
target_version = $(LIBVERSION)

View File

@ -1207,46 +1207,6 @@
</File>
</Filter>
</Filter>
<Filter
Name="AsyncIO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Net\AsyncSocketChannel.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\AsyncSocketChannel.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="IO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\Net\SocketIOChannel.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\SocketIOChannel.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -1,84 +0,0 @@
//
// AsyncSocketChannel.h
//
// $Id: //poco/svn/Net/include/Poco/Net/AsyncSocketChannel.h#2 $
//
// Library: Net
// Package: AsyncIO
// Module: AsyncSocketChannel
//
// Definition of the AsyncSocketChannel 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 Net_AsyncSocketChannel_INCLUDED
#define Net_AsyncSocketChannel_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/AsyncIOChannel.h"
namespace Poco {
namespace Net {
class Net_API AsyncSocketChannel: public Poco::AsyncIOChannel
/// AsyncSocketChannel provides an AsyncIOChannel for a StreamSocket.
///
/// Usage Example:
/// StreamSocket socket(...);
/// AsyncSocketChannel channel(socket);
/// channel.enqueue(new AsyncWriteCommand("Hello", 5));
/// channel.enqueue(new AsyncWriteCommand(", ", 2));
/// ActiveResult<int> result = channel.enqueue(new AsyncWriteCommand("world!", 6));
/// result.wait();
{
public:
AsyncSocketChannel(const StreamSocket& socket);
/// Creates an AsyncSocketChannel using the given StreamSocket.
~AsyncSocketChannel();
/// Destroys the AsyncSocketChannel.
// AsyncIOChannel
int write(const void* buffer, int length);
int read(void* buffer, int length);
private:
AsyncSocketChannel();
StreamSocket _socket;
};
} } // namespace Poco::Net
#endif // Net_AsyncSocketChannel_INCLUDED

View File

@ -1,138 +0,0 @@
//
// SocketIOChannel.h
//
// $Id: //poco/Main/Data/include/Poco/Net/SocketIOChannel.h#1 $
//
// Library: Net
// Package: IO
// Module: SocketIOChannel
//
// Definition of the SocketIOChannel class.
//
// Copyright (c) 2006, 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 Net_SocketIOChannel_INCLUDED
#define Net_SocketIOChannel_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/IOChannel.h"
#include "Poco/IOChannelConfig.h"
#include "Poco/Net/Socket.h"
#include "Poco/Net/SocketImpl.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/DatagramSocket.h"
namespace Poco {
namespace Net {
class Net_API SocketIOChannel: public Poco::IOChannel
/// Wraps a socket into IO channel interface.
/// Both stream and datagram sockets are supported.
{
public:
SocketIOChannel(IOChannelConfig* pConfig);
/// Creates SocketIOChannel.
~SocketIOChannel();
/// Destroys SocketIOChannel.
void open();
/// Opens SocketIOChannel.
void close();
/// Closes SocketIOChannel.
bool isStream();
/// Returns true if SocketIOChannel currently wraps stream socket.
bool isDatagram();
/// Returns true if SocketIOChannel currently wraps datagram socket.
private:
SocketIOChannel(const SocketIOChannel&);
const SocketIOChannel& operator=(const SocketIOChannel&);
void init();
int readData(char* pReadBuf, int length);
int readData(char*& pReadBuf);
int writeData(const char* buffer, int length);
Poco::Net::Socket& socket();
Poco::Net::SocketImpl* socketImpl();
Poco::Net::Socket* _pSocket;
};
//
// inlines
//
inline Poco::Net::Socket& SocketIOChannel::socket()
{
if (!_pSocket) init();
return *_pSocket;
}
inline Poco::Net::SocketImpl* SocketIOChannel::socketImpl()
{
return socket().impl();
}
inline void SocketIOChannel::close()
{
socketImpl()->close();
delete _pSocket;
_pSocket = 0;
}
inline bool SocketIOChannel::isStream()
{
return Poco::IOChannelConfig::CONNECTION_CHANNEL == config().getType();
}
inline bool SocketIOChannel::isDatagram()
{
return Poco::IOChannelConfig::CONNECTIONLESS_CHANNEL == config().getType();
}
} } // namespace Poco::Net
#endif // Net_SocketIOChannel_INCLUDED

View File

@ -1,67 +0,0 @@
//
// AsyncSocketChannel.cpp
//
// $Id: //poco/svn/Net/src/AsyncSocketChannel.cpp#2 $
//
// Library: Net
// Package: AsyncIO
// Module: AsyncSocketChannel
//
// 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/Net/AsyncSocketChannel.h"
namespace Poco {
namespace Net {
AsyncSocketChannel::AsyncSocketChannel(const StreamSocket& socket):
_socket(socket)
{
}
AsyncSocketChannel::~AsyncSocketChannel()
{
}
int AsyncSocketChannel::write(const void* buffer, int length)
{
return _socket.sendBytes(buffer, length);
}
int AsyncSocketChannel::read(void* buffer, int length)
{
return _socket.receiveBytes(buffer, length);
}
} } // namespace Poco::Net

View File

@ -1,180 +0,0 @@
//
// SocketIOChannel.cpp
//
// $Id: //poco/Main/IO/src/SocketIOChannel.cpp#1 $
//
// Library: Net
// Package: IO
// Module: SocketIOChannel
//
// Copyright (c) 2006, 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/Net/SocketIOChannel.h"
#include "Poco/Exception.h"
#include "Poco/Net/SocketImpl.h"
using Poco::InvalidArgumentException;
using Poco::Net::SocketImpl;
namespace Poco {
namespace Net {
SocketIOChannel::SocketIOChannel(IOChannelConfig* pConfig):
IOChannel(pConfig),
_pSocket(0)
{
init();
}
SocketIOChannel::~SocketIOChannel()
{
delete _pSocket;
}
void SocketIOChannel::init()
{
delete _pSocket;
if (isStream())
_pSocket = new Poco::Net::StreamSocket();
else if (isDatagram())
_pSocket = new Poco::Net::DatagramSocket();
else
throw IllegalStateException();
poco_check_ptr (_pSocket);
open();
if (!_pSocket) throw NullPointerException();
}
void SocketIOChannel::open()
{
Poco::Timespan timeout(config().getTimeout() * Timespan::MILLISECONDS);
SocketAddress address(config().getName());
try
{
if (isStream() && timeout != IOChannelConfig::INFINITE_TIMEOUT)
socketImpl()->connect(address, timeout);
else
socketImpl()->connect(address);
socketImpl()->setBlocking(false);
}
catch (Exception&)
{
close();
}
}
int SocketIOChannel::readData(char*& pReadBuf)
{
int bufSize = socketImpl()->getReceiveBufferSize();
char* pBuffer = new char[bufSize];
int size = 0;
try
{
int read = 0;
do
{
read = readData(pBuffer, bufSize);
if (read > 0)
{
pReadBuf = static_cast<char*>(std::realloc(pReadBuf, size + read));
std::memcpy(pReadBuf + size, pBuffer, read);
size += read;
}
else break;
} while (true);
}
catch (TimeoutException&)
{
}
catch (Exception&)
{
delete [] pBuffer;
throw;
}
delete [] pBuffer;
return size;
}
int SocketIOChannel::readData(char* pBuffer, int length)
{
int received = 0;
try
{
if (!socketImpl()->poll(config().getTimeout(), SocketImpl::SELECT_READ))
throw TimeoutException("read timed out", socketImpl()->address().toString());
received = socketImpl()->receiveBytes(pBuffer, (int) length);
}
catch (Poco::Exception&)
{
socketImpl()->setBlocking(true);
throw;
}
return received;
}
int SocketIOChannel::writeData(const char* pBuffer, int length)
{
int sent = 0;
socketImpl()->setBlocking(false);
try
{
if (!socketImpl()->poll(config().getTimeout(), SocketImpl::SELECT_WRITE))
throw Poco::TimeoutException("write timed out", socketImpl()->address().toString());
sent = socketImpl()->sendBytes(pBuffer, (int) length);
socketImpl()->setBlocking(true);
}
catch (Poco::Exception&)
{
socketImpl()->setBlocking(true);
throw;
}
return sent;
}
} } // namespace Poco::Net

View File

@ -25,7 +25,7 @@ objects = \
MailTestSuite MailMessageTest MailStreamTest \
SMTPClientSessionTest POP3ClientSessionTest \
RawSocketTest ICMPClientTest ICMPSocketTest ICMPClientTestSuite \
SyslogTest SocketIOChannelTestSuite SocketIOChannelTest
SyslogTest
target = testrunner
target_version = 1

View File

@ -976,34 +976,6 @@
</File>
</Filter>
</Filter>
<Filter
Name="IO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\src\SocketIOChannelTest.h"
>
</File>
<File
RelativePath=".\src\SocketIOChannelTestSuite.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\SocketIOChannelTest.cpp"
>
</File>
<File
RelativePath=".\src\SocketIOChannelTestSuite.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -44,7 +44,6 @@
#include "MailTestSuite.h"
#include "ICMPClientTestSuite.h"
#include "SyslogTest.h"
#include "SocketIOChannelTest.h"
CppUnit::Test* NetTestSuite::suite()
@ -64,7 +63,6 @@ CppUnit::Test* NetTestSuite::suite()
pSuite->addTest(MailTestSuite::suite());
pSuite->addTest(ICMPClientTestSuite::suite());
pSuite->addTest(SyslogTest::suite());
pSuite->addTest(SocketIOChannelTest::suite());
return pSuite;
}

View File

@ -1,465 +0,0 @@
//
// SocketIOChannelTest.cpp
//
// $Id: //poco/Main/template/test.cpp#6 $
//
// Copyright (c) 2006, 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 "SocketIOChannelTest.h"
#include "UDPEchoServer.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Types.h"
#include "Poco/Format.h"
#include "Poco/ActiveResult.h"
#include "Poco/IOChannel.h"
#include "Poco/IOChannelConfig.h"
#include "Poco/Net/SocketIOChannel.h"
#include "Poco/ActiveIOChannel.h"
#include "Poco/Net/TCPServer.h"
#include "Poco/Net/TCPServerConnection.h"
#include "Poco/Net/TCPServerConnectionFactory.h"
#include "Poco/Net/TCPServerParams.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Void.h"
#include "Poco/Types.h"
#include "Poco/Thread.h"
#include "Poco/BinaryReader.h"
#include "Poco/BinaryWriter.h"
#include <iostream>
using Poco::UInt32;
using Poco::Int64;
using Poco::UInt64;
using Poco::ActiveResult;
using Poco::Void;
using Poco::Thread;
using Poco::format;
using Poco::BinaryReader;
using Poco::BinaryWriter;
using Poco::IOChannel;
using Poco::ActiveIOChannel;
using Poco::IOChannelInputStream;
using Poco::IOChannelOutputStream;
using Poco::IOChannelConfig;
using Poco::Net::SocketIOChannel;
using Poco::Net::TCPServer;
using Poco::Net::TCPServerConnection;
using Poco::Net::TCPServerConnectionFactory;
using Poco::Net::TCPServerConnectionFactoryImpl;
using Poco::Net::TCPServerParams;
using Poco::Net::ServerSocket;
using Poco::Net::StreamSocket;
namespace
{
class EchoConnection: public TCPServerConnection
{
public:
EchoConnection(const StreamSocket& s): TCPServerConnection(s)
{
}
void run()
{
StreamSocket& ss = socket();
try
{
char buffer[256];
int n = ss.receiveBytes(buffer, sizeof(buffer));
while (n > 0)
{
ss.sendBytes(buffer, n);
n = ss.receiveBytes(buffer, sizeof(buffer));
}
}
catch (Poco::Exception& exc)
{
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
}
}
};
}
SocketIOChannelTest::SocketIOChannelTest(const std::string& name):
CppUnit::TestCase(name)
{
}
SocketIOChannelTest::~SocketIOChannelTest()
{
}
void SocketIOChannelTest::testChannelStream()
{
ServerSocket svs(0);
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
srv.start();
assert (srv.currentConnections() == 0);
assert (srv.currentThreads() == 0);
assert (srv.queuedConnections() == 0);
assert (srv.totalConnections() == 0);
SocketIOChannel network(new IOChannelConfig(format("localhost:%hu", svs.address().port()),
IOChannelConfig::CONNECTION_CHANNEL,
1000));
std::string data("hello, world");
network.write(data.data(), (int) data.size());
char buffer[256];
int n = network.read(buffer, sizeof(buffer));
assert ((int) data.size() == n);
assert (std::string(buffer, n) == data);
assert (srv.currentConnections() == 1);
assert (srv.currentThreads() == 1);
assert (srv.queuedConnections() == 0);
assert (srv.totalConnections() == 1);
network.close();
Thread::sleep(300);
assert (srv.currentConnections() == 0);
}
void SocketIOChannelTest::testActiveChannelStream()
{
ServerSocket svs(0);
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
srv.start();
SocketIOChannel network(new IOChannelConfig(format("localhost:%hu", svs.address().port()),
IOChannelConfig::CONNECTION_CHANNEL,
1000));
std::string str1 = "1234567890";
std::string str2 = "";
ActiveIOChannel<SocketIOChannel> activeChannel(network);
ActiveResult<int> result1 = activeChannel.write(str1);
result1.wait();
ActiveResult<std::string> result2 = activeChannel.read();
result2.wait();
assert("1234567890" == result2.data());
}
void SocketIOChannelTest::testStreamsStream()
{
ServerSocket svs(0);
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
srv.start();
SocketIOChannel net(new IOChannelConfig(format("localhost:%hu", svs.address().port()),
IOChannelConfig::CONNECTION_CHANNEL,
1000));
IOChannelOutputStream sos(net);
IOChannelInputStream sis(net);
sos << "1234567890\n";
std::string str;
sis >> str;
assert("1234567890" == str);
sos << 1.5;
sos << "\n";
sis >> str;
assert("1.5" == str);
}
void SocketIOChannelTest::testBinaryStream()
{
ServerSocket svs(0);
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
srv.start();
SocketIOChannel net(new IOChannelConfig(format("localhost:%hu", svs.address().port()),
IOChannelConfig::CONNECTION_CHANNEL,
1000));
IOChannelOutputStream sos(net);
IOChannelInputStream sis(net);
BinaryWriter bw(sos);
BinaryReader br(sis);
writeBinary(bw);
readBinary(br);
}
void SocketIOChannelTest::testChannelDatagram()
{
UDPEchoServer echoServer;
SocketIOChannel network(new IOChannelConfig(format("localhost:%hu", echoServer.address().port()),
IOChannelConfig::CONNECTIONLESS_CHANNEL,
1000));
std::string data("hello, world");
network.write(data.data(), (int) data.size());
char buffer[256];
int n = network.read(buffer, sizeof(buffer));
assert (n > 0);
assert (std::string(buffer, n) == data);
}
void SocketIOChannelTest::testActiveChannelDatagram()
{
UDPEchoServer echoServer;
SocketIOChannel network(new IOChannelConfig(format("localhost:%hu", echoServer.address().port()),
IOChannelConfig::CONNECTIONLESS_CHANNEL,
1000));
std::string str1 = "1234567890";
std::string str2 = "";
ActiveIOChannel<SocketIOChannel> activeChannel(network);
ActiveResult<int> result1 = activeChannel.write(str1);
result1.wait();
ActiveResult<std::string> result2 = activeChannel.read();
result2.wait();
assert("1234567890" == result2.data());
}
void SocketIOChannelTest::testStreamsDatagram()
{
UDPEchoServer echoServer;
SocketIOChannel net(new IOChannelConfig(format("localhost:%hu", echoServer.address().port()),
IOChannelConfig::CONNECTIONLESS_CHANNEL,
1000));
IOChannelOutputStream sos(net);
IOChannelInputStream sis(net);
sos << "1234567890\n";
std::string str;
sis >> str;
assert("1234567890" == str);
sos << 1.5;
sos << "\n";
sis >> str;
assert("1.5" == str);
}
void SocketIOChannelTest::testBinaryDatagram()
{
UDPEchoServer echoServer;
SocketIOChannel net(new IOChannelConfig(format("localhost:%hu", echoServer.address().port()),
IOChannelConfig::CONNECTIONLESS_CHANNEL,
1000));
IOChannelOutputStream sos(net);
IOChannelInputStream sis(net);
BinaryWriter bw(sos);
BinaryReader br(sis);
writeBinary(bw);
readBinary(br);
}
void SocketIOChannelTest::writeBinary(BinaryWriter& writer)
{
writer << true;
writer << false;
writer << 'a';
writer << (short) -100;
writer << (unsigned short) 50000;
writer << -123456;
writer << (unsigned) 123456;
writer << (long) -1234567890;
writer << (unsigned long) 1234567890;
#if defined(POCO_HAVE_INT64)
writer << (Int64) -1234567890;
writer << (UInt64) 1234567890;
#endif
writer << (float) 1.5;
writer << (double) -1.5;
writer << "foo";
writer << "";
writer << std::string("bar");
writer << std::string();
writer.write7BitEncoded((UInt32) 100);
writer.write7BitEncoded((UInt32) 1000);
writer.write7BitEncoded((UInt32) 10000);
writer.write7BitEncoded((UInt32) 100000);
writer.write7BitEncoded((UInt32) 1000000);
#if defined(POCO_HAVE_INT64)
writer.write7BitEncoded((UInt64) 100);
writer.write7BitEncoded((UInt64) 1000);
writer.write7BitEncoded((UInt64) 10000);
writer.write7BitEncoded((UInt64) 100000);
writer.write7BitEncoded((UInt64) 1000000);
#endif
writer.writeRaw("RAW");
}
void SocketIOChannelTest::readBinary(BinaryReader& reader)
{
bool b = false;
reader >> b;
assert (b);
reader >> b;
assert (!b);
char c = ' ';
reader >> c;
assert (c == 'a');
short shortv = 0;
reader >> shortv;
assert (shortv == -100);
unsigned short ushortv = 0;
reader >> ushortv;
assert (ushortv == 50000);
int intv = 0;
reader >> intv;
assert (intv == -123456);
unsigned uintv = 0;
reader >> uintv;
assert (uintv == 123456);
long longv = 0;
reader >> longv;
assert (longv == -1234567890);
unsigned long ulongv = 0;
reader >> ulongv;
assert (ulongv == 1234567890);
#if defined(POCO_HAVE_INT64)
Int64 int64v = 0;
reader >> int64v;
assert (int64v == -1234567890);
UInt64 uint64v = 0;
reader >> uint64v;
assert (uint64v == 1234567890);
#endif
float floatv = 0.0;
reader >> floatv;
assert (floatv == 1.5);
double doublev = 0.0;
reader >> doublev;
assert (doublev == -1.5);
std::string str;
reader >> str;
assert (str == "foo");
reader >> str;
assert (str == "");
reader >> str;
assert (str == "bar");
reader >> str;
assert (str == "");
UInt32 uint32v;
reader.read7BitEncoded(uint32v);
assert (uint32v == 100);
reader.read7BitEncoded(uint32v);
assert (uint32v == 1000);
reader.read7BitEncoded(uint32v);
assert (uint32v == 10000);
reader.read7BitEncoded(uint32v);
assert (uint32v == 100000);
reader.read7BitEncoded(uint32v);
assert (uint32v == 1000000);
#if defined(POCO_HAVE_INT64)
reader.read7BitEncoded(uint64v);
assert (uint64v == 100);
reader.read7BitEncoded(uint64v);
assert (uint64v == 1000);
reader.read7BitEncoded(uint64v);
assert (uint64v == 10000);
reader.read7BitEncoded(uint64v);
assert (uint64v == 100000);
reader.read7BitEncoded(uint64v);
assert (uint64v == 1000000);
#endif
reader.readRaw(3, str);
assert (str == "RAW");
}
void SocketIOChannelTest::setUp()
{
}
void SocketIOChannelTest::tearDown()
{
}
CppUnit::Test* SocketIOChannelTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketIOChannelTest");
CppUnit_addTest(pSuite, SocketIOChannelTest, testChannelStream);
CppUnit_addTest(pSuite, SocketIOChannelTest, testActiveChannelStream);
CppUnit_addTest(pSuite, SocketIOChannelTest, testStreamsStream);
CppUnit_addTest(pSuite, SocketIOChannelTest, testBinaryStream);
CppUnit_addTest(pSuite, SocketIOChannelTest, testChannelDatagram);
CppUnit_addTest(pSuite, SocketIOChannelTest, testActiveChannelDatagram);
CppUnit_addTest(pSuite, SocketIOChannelTest, testStreamsDatagram);
CppUnit_addTest(pSuite, SocketIOChannelTest, testBinaryDatagram);
return pSuite;
}

View File

@ -1,75 +0,0 @@
//
// SocketIOChannelTest.h
//
// $Id: //poco/Main/template/test.h#7 $
//
// Definition of the SocketIOChannelTest class.
//
// Copyright (c) 2006, 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 SocketIOChannelTest_INCLUDED
#define SocketIOChannelTest_INCLUDED
#include "CppUnit/TestCase.h"
#include "Poco/BinaryReader.h"
#include "Poco/BinaryWriter.h"
#include "Poco/IOChannel.h"
#include "Poco/IOChannelStream.h"
#include "Poco/IOChannelConfig.h"
#include "Poco/Net/SocketIOChannel.h"
class SocketIOChannelTest: public CppUnit::TestCase
{
public:
SocketIOChannelTest(const std::string& name);
~SocketIOChannelTest();
void testChannelStream();
void testActiveChannelStream();
void testStreamsStream();
void testBinaryStream();
void testChannelDatagram();
void testActiveChannelDatagram();
void testStreamsDatagram();
void testBinaryDatagram();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
void writeBinary(Poco::BinaryWriter& writer);
void readBinary(Poco::BinaryReader& reader);
};
#endif // SocketIOChannelTest_INCLUDED

View File

@ -1,44 +0,0 @@
//
// SocketIOChannelTestSuite.cpp
//
// $Id: //poco/Main/template/suite.cpp#6 $
//
// Copyright (c) 2006, 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 "SocketIOChannelTestSuite.h"
#include "SocketIOChannelTest.h"
CppUnit::Test* SocketIOChannelTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketIOChannelTestSuite");
pSuite->addTest(SocketIOChannelTest::suite());
return pSuite;
}

View File

@ -1,49 +0,0 @@
//
// NetTestSuite.h
//
// $Id: //poco/Main/template/suite.h#6 $
//
// Definition of the NetTestSuite class.
//
// Copyright (c) 2006, 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 SocketIOChannelTestSuite_INCLUDED
#define SocketIOChannelTestSuite_INCLUDED
#include "CppUnit/TestSuite.h"
class SocketIOChannelTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // SocketIOChannelTestSuite_INCLUDED