You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by nm...@apache.org on 2007/04/23 16:51:19 UTC
svn commit: r531487 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network:
SocketError.cpp SocketError.h SocketInputStream.cpp
Author: nmittler
Date: Mon Apr 23 07:51:15 2007
New Revision: 531487
URL: http://svn.apache.org/viewvc?view=rev&rev=531487
Log:
AMQCPP-107 - adding handling of signal interruptions to SocketInputStream
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.cpp?view=diff&rev=531487&r1=531486&r2=531487
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.cpp Mon Apr 23 07:51:15 2007
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include "SocketError.h"
#include <activemq/util/Config.h>
@@ -10,15 +27,36 @@
using namespace activemq;
using namespace activemq::network;
+// Platform constants.
+#if defined(HAVE_WINSOCK2_H)
+ const int SocketError::INTERRUPTED = WSAEINTR;
+#else
+ const int SocketError::INTERRUPTED = EINTR;
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+int SocketError::getErrorCode() {
+
+ #if defined(HAVE_WINSOCK2_H)
+
+ return ::WSAGetLastError();
+
+ #else
+
+ return errno;
+
+ #endif
+}
+
////////////////////////////////////////////////////////////////////////////////
std::string SocketError::getErrorString() {
std::string returnValue;
- #if defined(HAVE_WINSOCK2_H)
+ // Get the error code.
+ int errorCode = getErrorCode();
- // If the socket was temporarily unavailable - just try again.
- int errorCode = ::WSAGetLastError();
+ #if defined(HAVE_WINSOCK2_H)
// Create the error string.
static const int errorStringSize = 512;
@@ -37,7 +75,7 @@
#else
// Create the error string.
- returnValue = ::strerror(errno);
+ returnValue = ::strerror(errorCode);
#endif
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.h?view=diff&rev=531487&r1=531486&r2=531487
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketError.h Mon Apr 23 07:51:15 2007
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#ifndef ACTIVEMQ_NETWORK_SOCKETERROR_H_
#define ACTIVEMQ_NETWORK_SOCKETERROR_H_
@@ -6,9 +23,28 @@
namespace activemq{
namespace network{
- class SocketError {
+ /**
+ * Static utility class to simplify handling of error codes
+ * for socket operations.
+ */
+ class SocketError {
+ public:
+
+ /**
+ * Indicates that a socket operation was interrupted by a signal.
+ */
+ static const int INTERRUPTED;
+
public:
+ /**
+ * Gets the last error appropriate for the platform.
+ */
+ static int getErrorCode();
+
+ /**
+ * Gets the string description for the last error.
+ */
static std::string getErrorString();
};
}}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp?view=diff&rev=531487&r1=531486&r2=531487
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp Mon Apr 23 07:51:15 2007
@@ -134,14 +134,23 @@
std::size_t SocketInputStream::read( unsigned char* buffer,
std::size_t bufferSize ) throw (IOException)
{
- int len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
+ int len = 0;
- // Check for a closed socket.
- if( len == 0 ){
- throw IOException( __FILE__, __LINE__,
- "activemq::io::SocketInputStream::read - The connection is broken" );
- }
+ // Loop to ignore any signal interruptions that occur during the read.
+ do {
+
+ // Read data from the socket.
+ len = ::recv(socket, (char*)buffer, (int)bufferSize, 0);
+ // Check for a closed socket.
+ if( len == 0 ){
+ throw IOException( __FILE__, __LINE__,
+ "activemq::io::SocketInputStream::read - The connection is broken" );
+ }
+
+ } while( len == -1 &&
+ SocketError::getErrorCode() == SocketError::INTERRUPTED );
+
// Check for error.
if( len == -1 ){