}
catch(Exception& e)
{
- // Ignore idle timeout -- may happen on slow or loaded systems.
- if (!String::equal(
- e.getMessage(),"Connection closed by CIM Server."))
- {
- cerr << "Error: " << e.getMessage() << endl;
- throw;
- }
+ cerr << "Error: " << e.getMessage() << endl;
+ throw;
}
client.disconnect();
{
Threads::sleep(1000);
}
-
+ //the client shall reconnect if the connection was closed and
+ //so the operation should succeed.
CIMClass tmpClass2 =
client.getClass (OSINFO_NAMESPACE, OSINFO_CLASSNAME);
}
catch(Exception& e)
{
- if (String::equal(e.getMessage(),"Connection closed by CIM Server."))
- {
- test2CaughtException = true;
- cout << "Expected error: " << e.getMessage() << endl;
- }
- else
- {
- cerr << "Error: " << e.getMessage() << endl;
- }
+ test2CaughtException = true;
+ cerr << "Error: " << e.getMessage() << endl;
}
client.disconnect();
return TEST_PASSED;
}
-// _test2 verifies that a CIM Operation on a client connection does not
+// _test2 verifies that a CIM Operation on a client connection will still
// succeed when the idleConnectionTimeout period is exceeded (_idleThd) *and*
// there is concurrent server activity (_runningThd) so that the Monitor
-// will wake up and check for timeouts. In this case, the second call to
-// getClass() in _idleThd() should receive an exception because the
-// connection has been closed due to the timeout.
+// will wake up and check for timeouts and close the connection.
+// In this case, the second call to getClass() in _idleThd() will reconnect
+// and send the request.
Boolean _test2(
int durationSeconds, const char * testUserid, const char * testPasswd)
{
return TEST_FAILED;
}
- // We except the exception in this case, so if it was caught
- // then the test passed.
- return test2CaughtException;
+ // We do not expect exception in this case.
+ return (test2CaughtException == false);
}
int main(int argc, char** argv)
return _idleConnectionTimeoutSeconds;
}
+/*
+ Note: This method is called in client code for reconnecting with the Server
+ and can also be used in the server code to check the connection status and
+ take appropriate actions.it checks whether the connection is alive by
+ attempting to read 1 byte from the socket.This method MUST not be used when
+ incoming data is expected from the connection.
+
+ Returns TRUE when there is no data and peer has closed the connection
+ gracefully or there is an unanticipated incoming data, returns FALSE
+ otherwise. Note that this method does not consider the errors returned
+ from read().
+*/
+
+Boolean HTTPConnection::needsReconnect()
+{
+ char buffer;
+
+ int n = _socket->read(&buffer, sizeof(buffer));
+
+ return n >= 0;
+}
+
HTTPConnection::HTTPConnection(
Monitor* monitor,
SharedPtr<MP_Socket>& socket,
Boolean closeConnectionOnTimeout(struct timeval* timeNow);
+ // This method is called in Client code to decide reconnection with
+ // the Server and can also be used in the server code to check if the
+ // connection is still alive and take appropriate action.
+ Boolean needsReconnect();
+
// This method is called in Server code when response encoders or
// HTTPAuthenticatorDelegator runs out-of-memory. This method calls
// _handleWriteEvent() with a dummy HTTPMessage to maintain response