Skip to content

Commit

Permalink
Merge branch '1.4' of https://github.com/triAGENS/ArangoDB into 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Dec 20, 2013
2 parents 834f3df + 55deb10 commit 4efb291
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
v1.4.x (XXXX-XX-XX)
-------------------

* fixed issue #711, #687: foxx-manager throws internal errors

* added `--server.ssl-protocol` option for client tools
this allows connecting from arangosh, arangoimp, arangoimp etc. to an ArangoDB
server that uses a non-default value for `--server.ssl-protocol`. The default
Expand Down
19 changes: 10 additions & 9 deletions js/common/tests/shell-replication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,7 @@ function ReplicationApplierSuite () {

// configure && start
replication.applier.properties({
endpoint: "tcp://9.9.9.9:9999",
endpoint: "tcp://9.9.9.9:9999", // should not exist
connectTimeout: 3,
maxConnectRetries: 1
});
Expand Down Expand Up @@ -2775,15 +2775,14 @@ function ReplicationApplierSuite () {
state = replication.applier.state();

assertFalse(state.state.running);

// configure && start
replication.applier.properties({
endpoint: "tcp://www.arangodb.org:80",
endpoint: "tcp://www.arangodb.org:7999", // should not exist
connectTimeout: 3,
maxConnectRetries: 1
});
replication.applier.start();

replication.applier.start();
state = replication.applier.state();
assertTrue(state.state.running);

Expand All @@ -2797,9 +2796,11 @@ function ReplicationApplierSuite () {
}

assertFalse(state.state.running);
assertTrue(state.state.totalFailedConnects <= i);
assertTrue(state.state.totalFailedConnects > 0);
assertTrue(state.state.progress.failedConnects > 0);
assertTrue(state.state.lastError.errorNum === errors.ERROR_REPLICATION_INVALID_RESPONSE.code ||
state.state.lastError.errorNum === errors.ERROR_REPLICATION_MASTER_ERROR.code);
state.state.lastError.errorNum === errors.ERROR_REPLICATION_MASTER_ERROR.code ||
state.state.lastError.errorNum === errors.ERROR_REPLICATION_NO_RESPONSE.code);
break;
}

Expand Down Expand Up @@ -2827,7 +2828,7 @@ function ReplicationApplierSuite () {

// configure && start
replication.applier.properties({
endpoint: "tcp://9.9.9.9:9999"
endpoint: "tcp://9.9.9.9:9999" // should not exist
});

replication.applier.start();
Expand Down Expand Up @@ -2874,7 +2875,7 @@ function ReplicationApplierSuite () {
}

replication.applier.properties({
endpoint: "tcp://9.9.9.9:9999"
endpoint: "tcp://9.9.9.9:9999"
});

properties = replication.applier.properties();
Expand Down Expand Up @@ -3139,7 +3140,7 @@ function ReplicationSyncSuite () {
/// @brief executes the test suites
////////////////////////////////////////////////////////////////////////////////

jsunity.run(ReplicationLoggerSuite);
//jsunity.run(ReplicationLoggerSuite);
jsunity.run(ReplicationApplierSuite);
jsunity.run(ReplicationSyncSuite);

Expand Down
3 changes: 3 additions & 0 deletions lib/SimpleHttpClient/ClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool ClientConnection::checkSocket () {

if (res != TRI_ERROR_NO_ERROR) {
TRI_set_errno(errno);
_isConnected = false;
return false;
}

Expand All @@ -110,6 +111,7 @@ bool ClientConnection::checkSocket () {
}

TRI_set_errno(so_error);
_isConnected = false;

return false;
}
Expand Down Expand Up @@ -264,6 +266,7 @@ bool ClientConnection::readClientConnection (StringBuffer& stringBuffer) {

if (lenRead == 0) {
// nothing more to read
_isConnected = false;
break;
}

Expand Down
21 changes: 18 additions & 3 deletions lib/SimpleHttpClient/SimpleHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ namespace triagens {
case (IN_READ_CHUNKED_HEADER):
case (IN_READ_CHUNKED_BODY): {
TRI_set_errno(TRI_ERROR_NO_ERROR);

if (_connection->handleRead(remainingTime, _readBuffer)) {
switch (_state) {
case (IN_READ_HEADER):
Expand All @@ -161,6 +162,15 @@ namespace triagens {
}
}
else {
if (! _result->hasContentLength() &&
! _connection->isConnected() &&
_state == IN_READ_BODY) {
// no content-length header in response, now set the length
_result->setContentLength(_readBuffer.length());
readBody();
break;
}

setErrorMessage(TRI_last_error(), false);
this->close();
}
Expand Down Expand Up @@ -387,8 +397,13 @@ namespace triagens {
_state = IN_READ_CHUNKED_HEADER;
return readChunkedHeader();
}
else if (_result->getContentLength()) {

else if (! _result->hasContentLength()) {
// no content-length header in response
_state = IN_READ_BODY;
return readBody();
}
else if (_result->hasContentLength() && _result->getContentLength() > 0) {
// found content-length header in response
if (_result->getContentLength() > _maxPacketSize) {
setErrorMessage("Content-Length > max packet size found", true);

Expand Down Expand Up @@ -432,7 +447,7 @@ namespace triagens {
return true;
}

if (_readBuffer.length() >= _result->getContentLength()) {
if (_result->hasContentLength() && _readBuffer.length() >= _result->getContentLength()) {
if (_result->isDeflated()) {
// body is compressed using deflate. inflate it
_readBuffer.inflate(_result->getBody());
Expand Down
1 change: 1 addition & 0 deletions lib/SimpleHttpClient/SimpleHttpResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace triagens {
_returnCode = 0;
_returnMessage = "";
_contentLength = 0;
_hasContentLength = false;
_chunked = false;
_deflated = false;
_requestResultType = UNKNOWN;
Expand Down
10 changes: 10 additions & 0 deletions lib/SimpleHttpClient/SimpleHttpResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ namespace triagens {
this->_returnMessage = message;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not the response contained a content length header
////////////////////////////////////////////////////////////////////////////////

bool hasContentLength () const {
return _hasContentLength;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief returns the content length
////////////////////////////////////////////////////////////////////////////////
Expand All @@ -137,6 +145,7 @@ namespace triagens {

void setContentLength (size_t len) {
_contentLength = len;
_hasContentLength = true;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -230,6 +239,7 @@ namespace triagens {
int _returnCode;
string _returnMessage;
size_t _contentLength;
bool _hasContentLength;
bool _chunked;
bool _deflated;

Expand Down
44 changes: 42 additions & 2 deletions lib/SimpleHttpClient/SslClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ bool SslClientConnection::writeClientConnection (void* buffer, size_t length, si
////////////////////////////////////////////////////////////////////////////////

bool SslClientConnection::readClientConnection (StringBuffer& stringBuffer) {
if (_ssl == 0) {
if (_ssl == 0 || ! _isConnected) {
return false;
}

Expand All @@ -285,6 +285,7 @@ bool SslClientConnection::readClientConnection (StringBuffer& stringBuffer) {
return false;
}

again:
int lenRead = SSL_read(_ssl, stringBuffer.end(), READBUFFER_SIZE - 1);

switch (SSL_get_error(_ssl, lenRead)) {
Expand All @@ -294,9 +295,12 @@ bool SslClientConnection::readClientConnection (StringBuffer& stringBuffer) {

case SSL_ERROR_ZERO_RETURN:
SSL_shutdown(_ssl);
_isConnected = false;
return true;

case SSL_ERROR_WANT_READ:
goto again;

case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_SYSCALL:
Expand Down Expand Up @@ -326,7 +330,43 @@ bool SslClientConnection::readable () {
// which are available inside ssl for reading.
// ...........................................................................

return (SSL_pending(_ssl) > 0);
if (SSL_pending(_ssl) > 0) {
return true;
}

if (prepare(0.0, false)) {
return checkSocket();
}

return false;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief return whether the socket is workable
////////////////////////////////////////////////////////////////////////////////

bool SslClientConnection::checkSocket () {
int so_error = -1;
socklen_t len = sizeof so_error;

assert(_socket.fileHandle > 0);

int res = getsockopt(_socket.fileHandle, SOL_SOCKET, SO_ERROR, (char*)(&so_error), &len);

if (res != TRI_ERROR_NO_ERROR) {
_isConnected = false;
TRI_set_errno(errno);
return false;
}

if (so_error == 0) {
return true;
}

TRI_set_errno(so_error);
_isConnected = false;

return false;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions lib/SimpleHttpClient/SslClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ namespace triagens {

bool readable ();

////////////////////////////////////////////////////////////////////////////////
/// @brief return whether the socket is still workable
////////////////////////////////////////////////////////////////////////////////

bool checkSocket ();

////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4efb291

Please sign in to comment.