summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--protocols/ace/RMCast/Link.cpp17
-rw-r--r--protocols/ace/RMCast/Socket.cpp68
-rw-r--r--protocols/ace/RMCast/Socket.h23
4 files changed, 99 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 98a38bde9b0..92391121520 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Jun 9 16:18:32 2005 Boris Kolpackov <boris@kolpackov.net>
+
+ * protocols/ace/RMCast/Link.cpp:
+ * protocols/ace/RMCast/Socket.cpp:
+ * protocols/ace/RMCast/Socket.h:
+
+ Implemented timed recv() and size().
+
Thu Jun 9 13:16:53 2005 Simon McQueen <sm@prismtech.com>
* bin/tao_other_tests.lst:
diff --git a/protocols/ace/RMCast/Link.cpp b/protocols/ace/RMCast/Link.cpp
index dafc6fd2d5a..7e8cab77845 100644
--- a/protocols/ace/RMCast/Link.cpp
+++ b/protocols/ace/RMCast/Link.cpp
@@ -181,6 +181,15 @@ namespace ACE_RMCast
ACE_Time_Value t (timeout);
ssize_t r = rsock_.recv (data, 4, addr, MSG_PEEK, &t);
+
+ // Check for cancellation request.
+ //
+ {
+ Lock l (mutex_);
+ if (stop_)
+ return;
+ }
+
if (r == -1)
{
if (errno != ETIME)
@@ -191,14 +200,6 @@ namespace ACE_RMCast
size = static_cast<size_t> (r);
break;
}
-
- // Check for cancellation request.
- //
- {
- Lock l (mutex_);
- if (stop_)
- return;
- }
}
diff --git a/protocols/ace/RMCast/Socket.cpp b/protocols/ace/RMCast/Socket.cpp
index f5b3c577f02..31f2807ac53 100644
--- a/protocols/ace/RMCast/Socket.cpp
+++ b/protocols/ace/RMCast/Socket.cpp
@@ -5,6 +5,7 @@
#include "ace/OS_Memory.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"
+#include "ace/OS_NS_sys_time.h" // gettimeofday
#include "ace/Unbounded_Queue.h"
@@ -36,10 +37,10 @@ namespace ACE_RMCast
send_ (void const* buf, size_t s);
ssize_t
- recv_ (void* buf, size_t s);
+ recv_ (void* buf, size_t s, ACE_Time_Value const* timeout);
ssize_t
- size_ ();
+ size_ (ACE_Time_Value const* timeout);
ACE_HANDLE
get_handle_ () const;
@@ -132,12 +133,31 @@ namespace ACE_RMCast
}
ssize_t Socket_Impl::
- recv_ (void* buf, size_t s)
+ recv_ (void* buf, size_t s, ACE_Time_Value const* timeout)
{
+ ACE_Time_Value abs_time;
+
+ if (timeout)
+ abs_time = ACE_OS::gettimeofday () + *timeout;
+
Lock l (mutex_);
while (queue_.is_empty ())
- cond_.wait ();
+ {
+ if (timeout)
+ {
+ if (cond_.wait (&abs_time) != -1)
+ break;
+ }
+ else
+ {
+ if (cond_.wait () != -1)
+ break;
+ }
+
+ return -1; // errno is already set
+ }
+
Message_ptr m;
@@ -175,12 +195,30 @@ namespace ACE_RMCast
}
ssize_t Socket_Impl::
- size_ ()
+ size_ (ACE_Time_Value const* timeout)
{
+ ACE_Time_Value abs_time;
+
+ if (timeout)
+ abs_time = ACE_OS::gettimeofday () + *timeout;
+
Lock l (mutex_);
while (queue_.is_empty ())
- cond_.wait ();
+ {
+ if (timeout)
+ {
+ if (cond_.wait (&abs_time) != -1)
+ break;
+ }
+ else
+ {
+ if (cond_.wait () != -1)
+ break;
+ }
+
+ return -1; // errno is already set
+ }
// I can't get the head of the queue without actually dequeuing
// the element.
@@ -241,7 +279,7 @@ namespace ACE_RMCast
if (ACE_OS::write (signal_pipe_.write_handle (), &c, 1) != 1)
{
- perror ("write: ");
+ // perror ("write: ");
abort ();
}
@@ -275,13 +313,25 @@ namespace ACE_RMCast
ssize_t Socket::
recv (void* buf, size_t s)
{
- return impl_->recv_ (buf, s);
+ return impl_->recv_ (buf, s, 0);
+ }
+
+ ssize_t Socket::
+ recv (void* buf, size_t s, ACE_Time_Value const& timeout)
+ {
+ return impl_->recv_ (buf, s, &timeout);
}
ssize_t Socket::
size ()
{
- return impl_->size_ ();
+ return impl_->size_ (0);
+ }
+
+ ssize_t Socket::
+ size (ACE_Time_Value const& timeout)
+ {
+ return impl_->size_ (&timeout);
}
ACE_HANDLE Socket::
diff --git a/protocols/ace/RMCast/Socket.h b/protocols/ace/RMCast/Socket.h
index 97b7b4b4e75..9f516d488ce 100644
--- a/protocols/ace/RMCast/Socket.h
+++ b/protocols/ace/RMCast/Socket.h
@@ -11,6 +11,7 @@
#include "ace/Auto_Ptr.h"
#include "ace/INET_Addr.h"
+#include "ace/Time_Value.h"
#include "RMCast_Export.h"
@@ -34,6 +35,7 @@ namespace ACE_RMCast
virtual void
send (void const* buf, size_t s);
+
// Block if message is not available. Upon successful completion
// return the next message. Otherwise return -1 and errno set to
// indicate the error. ENOENT indicates that the sender does not
@@ -42,6 +44,17 @@ namespace ACE_RMCast
virtual ssize_t
recv (void* buf, size_t s);
+
+ // Block for up to <timeout> until message is available. Upon
+ // successful completion return the next message. Otherwise
+ // return -1 and errno set to indicate the error. ETIME indicates
+ // that the operation timed out. ENOENT indicates that the sender
+ // does not retain the data for this message anymore.
+ //
+ virtual ssize_t
+ recv (void* buf, size_t s, ACE_Time_Value const& timeout);
+
+
// Block if message is not available. Upon successful completion
// return the size of the next message. Otherwise return -1 and
// errno set to indicate the error. ENOENT indicates that the
@@ -50,6 +63,16 @@ namespace ACE_RMCast
virtual ssize_t
size ();
+
+ // Block for up to <timeout> until message is available. Upon
+ // successful completion return the size of the next message.
+ // Otherwise return -1 and errno set to indicate the error.
+ // ETIME indicates that the operation timed out. ENOENT indicates
+ // that the sender does not retain the data for this message anymore.
+ //
+ virtual ssize_t
+ size (ACE_Time_Value const& timeout);
+
public:
// Reactor interface. Note that the handle returned by get_handle()
// is for signalling purposes only.