1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
Jan Steemann 2013-01-15 16:45:54 +01:00
commit 6fde7e2f27
24 changed files with 503 additions and 197 deletions

View File

@ -151,8 +151,8 @@ unittests-boost: UnitTests/basics_suite UnitTests/geo_suite
noinst_PROGRAMS += UnitTests/basics_suite UnitTests/geo_suite
UnitTests_basics_suite_CPPFLAGS = -I@top_srcdir@/arangod -I@top_srcdir@/lib
UnitTests_basics_suite_LDADD = -L@top_builddir@/lib -larango -lboost_unit_test_framework
UnitTests_basics_suite_CPPFLAGS = -I@top_srcdir@/arangod -I@top_srcdir@/lib @ICU_CPPFLAGS@
UnitTests_basics_suite_LDADD = -L@top_builddir@/lib -larango -lboost_unit_test_framework @ICU_LDFLAGS@
UnitTests_basics_suite_DEPENDENCIES = @top_builddir@/lib/libarango.a
UnitTests_basics_suite_SOURCES = \

7
arangod/Ahuacatl/ahuacatl-scope.c Normal file → Executable file
View File

@ -417,7 +417,8 @@ bool TRI_AddVariableScopeAql (TRI_aql_context_t* const context,
TRI_aql_node_t* const definingNode) {
TRI_aql_variable_t* variable;
TRI_aql_scope_t* scope;
void* result;
assert(context);
assert(name);
@ -431,8 +432,10 @@ bool TRI_AddVariableScopeAql (TRI_aql_context_t* const context,
}
scope = CurrentScope(context);
assert(! TRI_InsertKeyAssociativePointer(&scope->_variables, variable->_name, (void*) variable, false));
result = TRI_InsertKeyAssociativePointer(&scope->_variables, variable->_name, (void*) variable, false);
assert(result == NULL);
return true;
}

1
arangod/RestServer/arango.cpp Normal file → Executable file
View File

@ -89,7 +89,6 @@ int main (int argc, char* argv[]) {
// ...........................................................................
// TODO: need a terminate function for windows to be called and cleanup
// any windows specific stuff.
// TODO: find the memory deallocation/allocation error
// ...........................................................................
res = finaliseWindows(TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL, 0);

23
arangosh/ArangoShell/ArangoClient.cpp Normal file → Executable file
View File

@ -420,6 +420,16 @@ void ArangoClient::parse (ProgramOptions& options,
/// @brief starts pager
////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
void ArangoClient::startPager () {
// not supported
if (!_usePager || _usePager) {
return;
}
}
#else
void ArangoClient::startPager () {
if (! _usePager || _outputPager == "" || _outputPager == "stdout" || _outputPager == "-") {
_pager = stdout;
@ -434,10 +444,21 @@ void ArangoClient::startPager () {
_usePager = false;
}
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief stops pager
////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
void ArangoClient::stopPager () {
// not supported
if (!_usePager || _usePager) {
return;
}
}
#else
void ArangoClient::stopPager () {
if (_pager != stdout) {
@ -446,6 +467,8 @@ void ArangoClient::stopPager () {
}
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief print to pager
////////////////////////////////////////////////////////////////////////////////

14
arangosh/V8Client/ImportHelper.cpp Normal file → Executable file
View File

@ -59,7 +59,7 @@ namespace triagens {
/// constructor and destructor
////////////////////////////////////////////////////////////////////////////////
ImportHelper::ImportHelper (httpclient::SimpleHttpClient* _client, size_t maxUploadSize)
ImportHelper::ImportHelper (httpclient::SimpleHttpClient* _client, uint64_t maxUploadSize)
: _client(_client),
_maxUploadSize(maxUploadSize),
_lineBuffer(TRI_UNKNOWN_MEM_ZONE),
@ -106,7 +106,7 @@ namespace triagens {
fd = STDIN_FILENO;
}
else {
fd = open(fileName.c_str(), O_RDONLY);
fd = TRI_OPEN(fileName.c_str(), O_RDONLY);
}
if (fd < 0) {
@ -154,7 +154,7 @@ namespace triagens {
while (! _hasError) {
v8::HandleScope scope;
ssize_t n = read(fd, buffer, sizeof(buffer));
ssize_t n = TRI_READ(fd, buffer, sizeof(buffer));
if (n < 0) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, separator);
@ -179,7 +179,7 @@ namespace triagens {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, eol);
if (fileName != "-") {
close(fd);
TRI_CLOSE(fd);
}
_outputBuffer.clear();
@ -203,7 +203,7 @@ namespace triagens {
fd = STDIN_FILENO;
}
else {
fd = open(fileName.c_str(), O_RDONLY);
fd = TRI_OPEN(fileName.c_str(), O_RDONLY);
}
if (fd < 0) {
@ -215,7 +215,7 @@ namespace triagens {
bool isArray = false;
while (! _hasError) {
ssize_t n = read(fd, buffer, sizeof(buffer));
ssize_t n = TRI_READ(fd, buffer, sizeof(buffer));
if (n < 0) {
_errorMessage = TRI_LAST_ERROR_STR;
@ -260,7 +260,7 @@ namespace triagens {
_numberLines = _numberError + _numberOk;
if (fileName != "-") {
close(fd);
TRI_CLOSE(fd);
}
_outputBuffer.clear();

8
arangosh/V8Client/ImportHelper.h Normal file → Executable file
View File

@ -52,6 +52,10 @@
#include "BasicsC/csv.h"
#include "Basics/StringBuffer.h"
#ifdef _WIN32
#include "BasicsC/win-utils.h"
#endif
namespace triagens {
namespace httpclient {
class SimpleHttpClient;
@ -87,7 +91,7 @@ namespace triagens {
/// @brief constructor
////////////////////////////////////////////////////////////////////////////////
ImportHelper (httpclient::SimpleHttpClient* client, size_t maxUploadSize);
ImportHelper (httpclient::SimpleHttpClient* client, uint64_t maxUploadSize);
////////////////////////////////////////////////////////////////////////////////
/// @brief destructor
@ -202,7 +206,7 @@ namespace triagens {
private:
httpclient::SimpleHttpClient* _client;
size_t _maxUploadSize;
uint64_t _maxUploadSize;
string _separator;
string _quote;

2
arangosh/V8Client/V8ClientConnection.cpp Normal file → Executable file
View File

@ -81,7 +81,9 @@ V8ClientConnection::V8ClientConnection (Endpoint* endpoint,
_client(0),
_httpResult(0) {
_connection = GeneralClientConnection::factory(endpoint, requestTimeout, connectTimeout, numRetries);
if (_connection == 0) {
throw "out of memory";
}

40
arangosh/V8Client/arangoimp.cpp Normal file → Executable file
View File

@ -187,6 +187,33 @@ static void ParseProgramOptions (int argc, char* argv[]) {
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char* argv[]) {
int ret = EXIT_SUCCESS;
#ifdef _WIN32
// ...........................................................................
// Call this function to do various initialistions for windows only
// ...........................................................................
// ...........................................................................
// Uncomment this to call this for extended debug information.
// If you familiar with valgrind ... then this is not like that, however
// you do get some similar functionality.
// ...........................................................................
//res = initialiseWindows(TRI_WIN_INITIAL_SET_DEBUG_FLAG, 0);
ret = initialiseWindows(TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER, 0);
if (ret != 0) {
_exit(1);
}
ret = initialiseWindows(TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL, 0);
if (ret != 0) {
_exit(1);
}
#endif
TRIAGENS_C_INITIALISE(argc, argv);
TRIAGENS_REST_INITIALISE(argc, argv);
@ -339,7 +366,18 @@ int main (int argc, char* argv[]) {
TRIAGENS_REST_SHUTDOWN;
return EXIT_SUCCESS;
#ifdef _WIN32
// ...........................................................................
// TODO: need a terminate function for windows to be called and cleanup
// any windows specific stuff.
// ...........................................................................
ret = finaliseWindows(TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL, 0);
#endif
return ret;
}
////////////////////////////////////////////////////////////////////////////////

105
arangosh/V8Client/arangosh.cpp Normal file → Executable file
View File

@ -1061,11 +1061,37 @@ static bool RunJsLint (v8::Handle<v8::Context> context) {
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char* argv[]) {
int ret = EXIT_SUCCESS;
#ifdef _WIN32
// ...........................................................................
// Call this function to do various initialistions for windows only
// ...........................................................................
// ...........................................................................
// Uncomment this to call this for extended debug information.
// If you familiar with valgrind ... then this is not like that, however
// you do get some similar functionality.
// ...........................................................................
//res = initialiseWindows(TRI_WIN_INITIAL_SET_DEBUG_FLAG, 0);
ret = initialiseWindows(TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER, 0);
if (ret != 0) {
_exit(1);
}
ret = initialiseWindows(TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL, 0);
if (ret != 0) {
_exit(1);
}
#endif
TRIAGENS_C_INITIALISE(argc, argv);
TRIAGENS_REST_INITIALISE(argc, argv);
TRI_InitialiseLogging(false);
int ret = EXIT_SUCCESS;
BaseClient.setEndpointString(Endpoint::getDefaultEndpoint());
@ -1088,6 +1114,7 @@ int main (int argc, char* argv[]) {
}
if (useServer) {
BaseClient.createEndpoint();
if (BaseClient.endpointServer() == 0) {
@ -1095,6 +1122,7 @@ int main (int argc, char* argv[]) {
exit(EXIT_FAILURE);
}
ClientConnection = CreateConnection();
}
@ -1203,7 +1231,69 @@ int main (int argc, char* argv[]) {
// .............................................................................
// http://www.network-science.de/ascii/ Font: ogre
if (! BaseClient.quiet()) {
#ifdef _WIN32
// .............................................................................
// Quick hack for windows
// .............................................................................
if (BaseClient.colors()) {
int greenColour = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
int redColour = FOREGROUND_RED | FOREGROUND_INTENSITY;
int defaultColour = 0;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
bool ok;
ok = GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
if (ok) {
defaultColour = csbiInfo.wAttributes;
}
SetConsoleOutputCP(65001);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
printf(" _ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColour);
printf("\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf(" __ _ _ __ __ _ _ __ __ _ ___ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
printf(" ___| |__ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColour);
printf("\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf(" / _` | '__/ _` | '_ \\ / _` |/ _ \\");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
printf("/ __| '_ \\ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColour);
printf("\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf("| (_| | | | (_| | | | | (_| | (_) ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
printf("\\__ \\ | | |");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColour);
printf("\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf(" \\__,_|_| \\__,_|_| |_|\\__, |\\___/");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
printf("|___/_| |_|");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColour);
printf("\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour);
printf(" |___/ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour);
printf(" ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColour);
printf("\n");
}
#else
char const* g = TRI_SHELL_COLOR_GREEN;
char const* r = TRI_SHELL_COLOR_RED;
char const* z = TRI_SHELL_COLOR_RESET;
@ -1222,6 +1312,7 @@ int main (int argc, char* argv[]) {
printf("%s| (_| | | | (_| | | | | (_| | (_) %s\\__ \\ | | |%s\n", g, r, z);
printf("%s \\__,_|_| \\__,_|_| |_|\\__, |\\___/%s|___/_| |_|%s\n", g, r, z);
printf("%s |___/ %s %s\n", g, r, z);
#endif
cout << endl << "Welcome to arangosh " << TRIAGENS_VERSION << ". Copyright (c) 2012 triAGENS GmbH" << endl;
@ -1308,6 +1399,7 @@ int main (int argc, char* argv[]) {
BaseClient.openLog();
// .............................................................................
// run normal shell
// .............................................................................
@ -1359,6 +1451,17 @@ int main (int argc, char* argv[]) {
TRIAGENS_REST_SHUTDOWN;
#ifdef _WIN32
// ...........................................................................
// TODO: need a terminate function for windows to be called and cleanup
// any windows specific stuff.
// ...........................................................................
ret = finaliseWindows(TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL, 0);
#endif
return ret;
}

View File

@ -1,12 +1,15 @@
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, plusplus: true */
/*global _, require, db, exports */
var Frank,
baseMiddleware,
BaseMiddleware,
_ = require("underscore"),
internal = {};
internal.createUrlObject = function (url, constraint, method) {
var urlObject = {};
if(!_.isString(url)) {
if (!_.isString(url)) {
throw "URL has to be a String";
}
@ -37,28 +40,29 @@ Frank = function (options) {
}
if (_.isString(templateCollection)) {
this.routingInfo.templateCollection = db._collection(templateCollection) || db._create(templateCollection);
this.routingInfo.templateCollection = db._collection(templateCollection) ||
db._create(templateCollection);
}
};
_.extend(Frank.prototype, {
handleRequest: function (method, route, argument1, argument2) {
var newRoute = {}, options, handler;
var newRoute = {}, options, handler;
if (_.isUndefined(argument2)) {
handler = argument1;
options = {};
} else {
options = argument1;
handler = argument2;
}
if (_.isUndefined(argument2)) {
handler = argument1;
options = {};
} else {
options = argument1;
handler = argument2;
}
newRoute.url = internal.createUrlObject(route, options.constraint, method);
newRoute.handler = handler;
newRoute.url = internal.createUrlObject(route, options.constraint, method);
newRoute.handler = handler;
this.routingInfo.routes.push(newRoute);
this.routingInfo.routes.push(newRoute);
},
head: function (route, argument1, argument2) {
this.handleRequest("head", route, argument1, argument2);
},
@ -74,14 +78,14 @@ _.extend(Frank.prototype, {
put: function (route, argument1, argument2) {
this.handleRequest("put", route, argument1, argument2);
},
patch: function (route, argument1, argument2) {
this.handleRequest("patch", route, argument1, argument2);
},
delete: function (route, argument1, argument2) {
this.handleRequest("delete", route, argument1, argument2);
},
}
});
@ -125,7 +129,11 @@ BaseMiddleware = function (templateCollection) {
throw "No template collection has been provided when creating a new Frank";
}
template = templateCollection.firstExample({path: "simple/path"});
template = templateCollection.firstExample({path: templatePath });
if (_.isNull(template)) {
throw "Template '" + templatePath + "' does not exist";
}
if (template.templateLanguage !== "underscore") {
throw "Unknown template language '" + template.templateLanguage + "'";
@ -137,6 +145,8 @@ BaseMiddleware = function (templateCollection) {
};
response = _.extend(response, responseFunctions);
next();
};
return middleware;

View File

@ -77,7 +77,7 @@ function SetRoutesFrankSpec () {
assertEqual(routes.length, 1);
assertEqual(routes[0].url.constraint, constraint);
},
testSetMethodToHead: function () {
var myFunc = function () {},
routes = app.routingInfo.routes;
@ -243,6 +243,18 @@ function BaseMiddlewareWithoutTemplateSpec () {
}
assertEqual(error, "No template collection has been provided when creating a new Frank");
},
testMiddlewareCallsTheAction: function () {
var actionWasCalled = false;
next = function () {
actionWasCalled = true;
};
baseMiddleware(request, response, options, next);
assertTrue(actionWasCalled);
}
};
}
@ -303,11 +315,28 @@ function BaseMiddlewareWithTemplateSpec () {
}
assertEqual(error, "Unknown template language 'pirateEngine'");
},
testRenderingATemplateWithAnNotExistingTemplate: function () {
var myCollection, error, middleware;
internal.db._drop("templateTest");
myCollection = internal.db._create("templateTest");
middleware = new BaseMiddleware(myCollection);
middleware(request, response, options, next);
try {
response.render("simple/path", { username: "moonglum" });
} catch(e) {
error = e;
}
assertEqual(error, "Template 'simple/path' does not exist");
}
};
}
jsunity.run(CreateFrankSpec);
jsunity.run(SetRoutesFrankSpec);
jsunity.run(BaseMiddlewareWithoutTemplateSpec);

View File

@ -102,7 +102,7 @@ static TRI_read_write_lock_t FileNamesLock;
static ssize_t LookupElementVectorString (TRI_vector_string_t * vector, char const * element) {
int idx = -1;
size_t i;
int i;
TRI_ReadLockReadWriteLock(&FileNamesLock);
@ -289,6 +289,12 @@ bool TRI_IsDirectory (char const* path) {
/// @brief checks if path is a symbolic link
////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
bool TRI_IsSymbolicLink (char const* path) {
// todo : check if a file is a symbolic link - without opening the file
return false;
}
#else
bool TRI_IsSymbolicLink (char const* path) {
struct stat stbuf;
int res;
@ -297,6 +303,7 @@ bool TRI_IsSymbolicLink (char const* path) {
return (res == 0) && ((stbuf.st_mode & S_IFMT) == S_IFLNK);
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief checks if file exists
@ -946,6 +953,14 @@ int TRI_VerifyLockFile (char const* filename) {
}
fd = TRI_OPEN(filename, O_RDONLY);
if (fd < 0) {
// this method if checking whether or not the database is locked is not suitable with the manner
// in which it is coded.
// windows assigns ownership of the file to the process for exclusive use
// the file exists, yet we can not open it, so being here we can only assume that the
// database is locked.
return TRI_ERROR_NO_ERROR;
}
n = TRI_READ(fd, buffer, sizeof(buffer));
TRI_CLOSE(fd);
@ -1091,7 +1106,11 @@ int TRI_DestroyLockFile (char const* filename) {
fd = TRI_OPEN(filename, O_RDWR);
if (fd < 0) {
return false;
}
// ..........................................................................
// TODO: Use windows LockFileEx to determine if file can be locked
// ..........................................................................

0
lib/BasicsC/messages.h Normal file → Executable file
View File

4
lib/BasicsC/operating-system.h Normal file → Executable file
View File

@ -535,6 +535,10 @@ typedef unsigned char bool;
typedef SOCKET socket_t;
#define STDIN_FILENO 0;
#define STDOUT_FILENO 1;
#define STDERR_FILENO 2;
#endif
////////////////////////////////////////////////////////////////////////////////

25
lib/BasicsC/win-utils.c Normal file → Executable file
View File

@ -105,16 +105,22 @@ void TRI_usleep(unsigned long waitTime) {
return;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
abort();
}
// Set timer to wait for indicated micro seconds.
if (!SetWaitableTimer(hTimer, &wTime, 0, NULL, NULL, 0)) {
// no much we can do at this low level
return;
}
// Wait for the timer - but don't wait for ever.
// TODO: Variable 'result' is assigned a value that is never used
result = WaitForSingleObject(hTimer, ((waitTime/1000) + 1)); // wait for a 1 millisecond at least
// Wait for the timer
result = WaitForSingleObject(hTimer, INFINITE);
if (result != WAIT_OBJECT_0) {
abort();
}
CloseHandle(hTimer);
// todo: go through what the result is e.g. WAIT_OBJECT_0
return;
}
@ -153,7 +159,6 @@ static void InvalidParameterHandler(const wchar_t* expression, // expression sen
else {
wprintf(L"win-utils.c:InvalidParameterHandler:FILE = NULL\n");
}
// TODO: printf format string has 2 parameters but only 1 are given
printf("oreste:%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%:win-utils.c:InvalidParameterHandler:LINE = %ud\n",line);
/* end oreste -debug */
//abort();
@ -173,7 +178,8 @@ static void InvalidParameterHandler(const wchar_t* expression, // expression sen
int finaliseWindows(const TRI_win_finalise_e finaliseWhat, const char* data) {
int result = 0;
// ............................................................................
// The data is used to transport information from the calling function to here
// it may be NULL (and will be in most cases)
@ -182,11 +188,10 @@ int finaliseWindows(const TRI_win_finalise_e finaliseWhat, const char* data) {
switch (finaliseWhat) {
case TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL: {
int errorCode;
errorCode = WSACleanup();
if (errorCode != 0) {
result = WSACleanup(); // could this cause error on server termination?
if (result != 0) {
// can not use LOG_ etc here since the logging may have terminated
printf("ERROR: Could not perform a valid Winsock2 cleanup. WSACleanup returned error %d.",errorCode);
printf("ERROR: Could not perform a valid Winsock2 cleanup. WSACleanup returned error %d.",result);
return -1;
}
return 0;
@ -254,8 +259,6 @@ int initialiseWindows(const TRI_win_initialise_e initialiseWhat, const char* dat
return -1;
}

261
lib/BasicsC/win-utils.h Normal file → Executable file
View File

@ -1,133 +1,132 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief windows utilties
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
///
/// Licensed 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.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. O
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_BASICS_C_WIN_UTILS_H
#define TRIAGENS_BASICS_C_WIN_UTILS_H 1
////////////////////////////////////////////////////////////////////////////////
/// @brief windows utilties
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2004-2012 triagens GmbH, Cologne, Germany
///
/// Licensed 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.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. O
/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_BASICS_C_WIN_UTILS_H
#define TRIAGENS_BASICS_C_WIN_UTILS_H 1
#include <WinSock2.h>
/* Constants rounded for 21 decimals.
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_1_SQRTPI 0.564189583547756286948
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT_2 0.707106781186547524401
*/
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Windows_Utilties
/// @{
////////////////////////////////////////////////////////////////////////////////
// .............................................................................
// Called before anything else starts - initialises whatever is required to be
// initalised.
// .............................................................................
typedef enum {
TRI_WIN_FINAL_SET_INVALID_HANLE_HANDLER,
TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL
}
TRI_win_finalise_e;
typedef enum {
TRI_WIN_INITIAL_SET_DEBUG_FLAG,
TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER,
TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL
}
TRI_win_initialise_e;
int finaliseWindows (const TRI_win_finalise_e, const char*);
int initialiseWindows (const TRI_win_initialise_e, const char*);
// .............................................................................
// windows equivalent of ftruncate (the truncation of an open file) is
// _chsize
// .............................................................................
int ftruncate (int, long);
// .............................................................................
// windows does not have a function called getpagesize -- create one here
// .............................................................................
int getpagesize (void);
/* Constants rounded for 21 decimals.
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_1_SQRTPI 0.564189583547756286948
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT_2 0.707106781186547524401
*/
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Windows_Utilties
/// @{
////////////////////////////////////////////////////////////////////////////////
// .............................................................................
// Called before anything else starts - initialises whatever is required to be
// initalised.
// .............................................................................
typedef enum {
TRI_WIN_FINAL_SET_INVALID_HANLE_HANDLER,
TRI_WIN_FINAL_WSASTARTUP_FUNCTION_CALL
}
TRI_win_finalise_e;
typedef enum {
TRI_WIN_INITIAL_SET_DEBUG_FLAG,
TRI_WIN_INITIAL_SET_INVALID_HANLE_HANDLER,
TRI_WIN_INITIAL_WSASTARTUP_FUNCTION_CALL
}
TRI_win_initialise_e;
int finaliseWindows (const TRI_win_finalise_e, const char*);
int initialiseWindows (const TRI_win_initialise_e, const char*);
// .............................................................................
// windows equivalent of ftruncate (the truncation of an open file) is
// _chsize
// .............................................................................
int ftruncate (int, long);
// .............................................................................
// windows does not have a function called getpagesize -- create one here
// .............................................................................
int getpagesize (void);
int TRI_WIN_closesocket (SOCKET);
// .............................................................................
// This function uses the CreateFile windows method rather than _open which
// then will allow the application to rename files on the fly.
// .............................................................................
int TRI_createFile (const char* filename, int openFlags, int modeFlags);
int TRI_openFile (const char* filename, int openFlags);
// .............................................................................
// the sleep function in windows is for milliseconds, on linux it is for seconds
// this provides a translation
// .............................................................................
void TRI_sleep(unsigned long);
// .............................................................................
// there is no usleep (micro sleep) in windows, so we create one here
// .............................................................................
void TRI_usleep(unsigned long);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:
// .............................................................................
// This function uses the CreateFile windows method rather than _open which
// then will allow the application to rename files on the fly.
// .............................................................................
int TRI_createFile (const char* filename, int openFlags, int modeFlags);
int TRI_openFile (const char* filename, int openFlags);
// .............................................................................
// the sleep function in windows is for milliseconds, on linux it is for seconds
// this provides a translation
// .............................................................................
void TRI_sleep(unsigned long);
// .............................................................................
// there is no usleep (micro sleep) in windows, so we create one here
// .............................................................................
void TRI_usleep(unsigned long);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -210,6 +210,75 @@ socket_t EndpointIp::connectSocket (const struct addrinfo* aip, double connectTi
/// @brief connect the endpoint
////////////////////////////////////////////////////////////////////////////////
#ifdef _WIN32
socket_t EndpointIp::connect (double connectTimeout, double requestTimeout) {
struct addrinfo* result = 0;
struct addrinfo* aip;
struct addrinfo hints;
int error;
LOGGER_DEBUG << "connecting to ip endpoint " << _specification;
assert(_socket == 0);
assert(!_connected);
memset(&hints, 0, sizeof (struct addrinfo));
hints.ai_family = getDomain(); // Allow IPv4 or IPv6
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV | AI_ALL;
hints.ai_socktype = SOCK_STREAM;
string portString = StringUtils::itoa(_port);
error = getaddrinfo(_host.c_str(), portString.c_str(), &hints, &result);
if (error != 0) {
int lastError = WSAGetLastError();
if (error == WSANOTINITIALISED) {
// can not call WSAGetLastError - since the socket layer hasn't been initialised yet!
lastError = error;
}
else {
lastError = WSAGetLastError();
}
switch (lastError) {
case WSANOTINITIALISED: {
LOGGER_ERROR << "getaddrinfo for host: " << _host.c_str() << " => WSAStartup was not called or not called successfully.";
break;
}
default: {
LOGGER_ERROR << "getaddrinfo for host: " << _host.c_str() << " => " << gai_strerror(error);
break;
}
}
if (result != 0) {
freeaddrinfo(result);
}
return 0;
}
socket_t listenSocket = 0;
// Try all returned addresses until one works
for (aip = result; aip != NULL; aip = aip->ai_next) {
// try to bind the address info pointer
listenSocket = connectSocket(aip, connectTimeout, requestTimeout);
if (listenSocket != 0) {
// OK
break;
}
}
freeaddrinfo(result);
return listenSocket;
}
#else
socket_t EndpointIp::connect (double connectTimeout, double requestTimeout) {
struct addrinfo* result = 0;
struct addrinfo* aip;
@ -256,6 +325,7 @@ socket_t EndpointIp::connect (double connectTimeout, double requestTimeout) {
return listenSocket;
}
#endif
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys an IPv4 socket endpoint

6
lib/Scheduler/Scheduler.cpp Normal file → Executable file
View File

@ -272,7 +272,7 @@ void Scheduler::unregisterTask (Task* task) {
map<Task*, SchedulerThread*>::iterator i = task2thread.find(task);
if (i == task2thread.end()) {
LOGGER_WARNING << "unregisterTask called for a unknown task " << task << " (" << task->getName() << ")";
LOGGER_WARNING << "unregisterTask called for an unknown task " << task << " (" << task->getName() << ")";
return;
}
@ -306,7 +306,7 @@ void Scheduler::destroyTask (Task* task) {
map<Task*, SchedulerThread*>::iterator i = task2thread.find(task);
if (i == task2thread.end()) {
LOGGER_WARNING << "destroyTask called for a unknown task " << task << " (" << task->getName() << ")";
LOGGER_WARNING << "destroyTask called for an unknown task " << task << " (" << task->getName() << ")";
return;
}
@ -323,7 +323,7 @@ void Scheduler::destroyTask (Task* task) {
task2thread.erase(i);
}
}
thread->destroyTask(task);
}

8
lib/SimpleHttpClient/ClientConnection.cpp Normal file → Executable file
View File

@ -186,7 +186,7 @@ bool ClientConnection::prepare (const double timeout, const bool isWrite) const
/// @brief write data to the connection
////////////////////////////////////////////////////////////////////////////////
bool ClientConnection::write (void* buffer, size_t length, size_t* bytesWritten) {
bool ClientConnection::writeClientConnection (void* buffer, size_t length, size_t* bytesWritten) {
if (!checkSocket()) {
return false;
}
@ -196,7 +196,7 @@ bool ClientConnection::write (void* buffer, size_t length, size_t* bytesWritten)
int status = ::send(_socket, buffer, length, 0);
#elif defined(_WIN32)
// MSG_NOSIGNAL not supported on windows platform
int status = ::send(_socket, (const char*)(buffer), (int)(length), 0);
int status = TRI_WRITE_SOCKET(_socket, (const char*)(buffer), (int)(length), 0);
#else
int status = ::send(_socket, buffer, length, MSG_NOSIGNAL);
#endif
@ -211,7 +211,7 @@ bool ClientConnection::write (void* buffer, size_t length, size_t* bytesWritten)
/// @brief read data from the connection
////////////////////////////////////////////////////////////////////////////////
bool ClientConnection::read (StringBuffer& stringBuffer) {
bool ClientConnection::readClientConnection (StringBuffer& stringBuffer) {
if (!checkSocket()) {
return false;
}
@ -221,7 +221,7 @@ bool ClientConnection::read (StringBuffer& stringBuffer) {
do {
char buffer[READBUFFER_SIZE];
int lenRead = ::read(_socket, buffer, READBUFFER_SIZE - 1);
int lenRead = TRI_READ_SOCKET(_socket, buffer, READBUFFER_SIZE - 1,0);
if (lenRead == -1) {
// error occurred

4
lib/SimpleHttpClient/ClientConnection.h Normal file → Executable file
View File

@ -130,13 +130,13 @@ namespace triagens {
/// @brief write data to the connection
////////////////////////////////////////////////////////////////////////////////
bool write (void*, size_t, size_t*);
bool writeClientConnection (void*, size_t, size_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief read data from the connection
////////////////////////////////////////////////////////////////////////////////
bool read (triagens::basics::StringBuffer&);
bool readClientConnection (triagens::basics::StringBuffer&);
////////////////////////////////////////////////////////////////////////////////
/// @brief return whether the connection is readable

4
lib/SimpleHttpClient/GeneralClientConnection.cpp Normal file → Executable file
View File

@ -144,7 +144,7 @@ bool GeneralClientConnection::handleWrite (const double timeout, void* buffer, s
*bytesWritten = 0;
if (prepare(timeout, true)) {
return this->write(buffer, length, bytesWritten);
return this->writeClientConnection(buffer, length, bytesWritten);
}
return false;
@ -156,7 +156,7 @@ bool GeneralClientConnection::handleWrite (const double timeout, void* buffer, s
bool GeneralClientConnection::handleRead (double timeout, StringBuffer& buffer) {
if (prepare(timeout, false)) {
return this->read(buffer);
return this->readClientConnection(buffer);
}
return false;

4
lib/SimpleHttpClient/GeneralClientConnection.h Normal file → Executable file
View File

@ -212,13 +212,13 @@ namespace triagens {
/// @brief write data to the connection
////////////////////////////////////////////////////////////////////////////////
virtual bool write (void*, size_t, size_t*) = 0;
virtual bool writeClientConnection (void*, size_t, size_t*) = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief read data from the connection
////////////////////////////////////////////////////////////////////////////////
virtual bool read (triagens::basics::StringBuffer&) = 0;
virtual bool readClientConnection (triagens::basics::StringBuffer&) = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief return whether the connection is readable

4
lib/SimpleHttpClient/SslClientConnection.cpp Normal file → Executable file
View File

@ -200,7 +200,7 @@ bool SslClientConnection::prepare (const double timeout, const bool isWrite) con
/// @brief write data to the connection
////////////////////////////////////////////////////////////////////////////////
bool SslClientConnection::write (void* buffer, size_t length, size_t* bytesWritten) {
bool SslClientConnection::writeClientConnection (void* buffer, size_t length, size_t* bytesWritten) {
*bytesWritten = 0;
if (_ssl == 0) {
@ -234,7 +234,7 @@ bool SslClientConnection::write (void* buffer, size_t length, size_t* bytesWritt
/// @brief read data from the connection
////////////////////////////////////////////////////////////////////////////////
bool SslClientConnection::read (StringBuffer& stringBuffer) {
bool SslClientConnection::readClientConnection (StringBuffer& stringBuffer) {
if (_ssl == 0) {
return false;
}

4
lib/SimpleHttpClient/SslClientConnection.h Normal file → Executable file
View File

@ -115,13 +115,13 @@ namespace triagens {
/// @brief write data to the connection
////////////////////////////////////////////////////////////////////////////////
bool write (void*, size_t, size_t*);
bool writeClientConnection (void*, size_t, size_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief read data from the connection
////////////////////////////////////////////////////////////////////////////////
bool read (triagens::basics::StringBuffer&);
bool readClientConnection (triagens::basics::StringBuffer&);
////////////////////////////////////////////////////////////////////////////////
/// @brief return whether the connection is readable