Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make it win32 and cmake friendly #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 17, 2016
Merged

Make it win32 and cmake friendly #2

merged 12 commits into from
Nov 17, 2016

Conversation

basiliscos
Copy link

No description provided.

Copy link

@tom-binary tom-binary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, having cmake support is a very useful feature. Most of the comments here are quite minor, didn't see any showstoppers apart from maybe the installation steps in CMakeLists.txt. Nice work.

@@ -0,0 +1,40 @@
cmake_minimum_required (VERSION 2.6)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's bump this up to 3.2 and make sure that QA environments have a recent version installed. Under Windows, we'd either build directly from the VC++ project or have a recent cmake version available anyway, and on Travis we can make sure it's at least 3.2, so we might as well take advantage of the nicer syntax that we'd get with 3.0+. Since this is an internal project I'm not too bothered about supporting old platforms!

@@ -1,11 +0,0 @@

all:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth keeping the makefile build, if we're submitting this upstream? That means people can still do a simple build without needing to go through cmake - the code is minimal so the maintenance effort shouldn't be too bad.

endif(NOT UNIX)

# check for functions
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, but if you leave off the .cmake you don't need the path:

include(CheckFunctionExists)


#ifdef _WIN32
// Win32-specific close socket function
#define CLOSE_SOCKET(s) closesocket(s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably just an oversight, but: despite the nice application of check_function_exists to determine whether we have this, you don't appear to be using that HAVE_CLOSE_SOCKET flag here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've dropped check_function_exists , because it wasn't able to find closesocket on windows. May be I need to add some additional headers etc., so I've moved it under _WIN32

@@ -48,14 +75,14 @@ StatsdClient::StatsdClient(const string& host, int port, const string& ns)
d = new _StatsdClientData;
d->sock = -1;
config(host, port, ns);
srandom(time(NULL));
srand(time(NULL));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to change the random handling, might as well switch to C++11 and avoid polluting global state with srand().

#include <random>

        std::random_device rd;
        std::default_random_engine engine { rd() };
        std::uniform_real_distribution<> dist { 0.0f, 1.0f };
        for(int i = 0; i < 10; ++i) std::cout << "Random between 0..1: " << dist(engine)  << std::endl;

@@ -88,25 +115,21 @@ int StatsdClient::init()
d->server.sin_family = AF_INET;
d->server.sin_port = htons(d->port);

int ret = inet_aton(d->host.c_str(), &d->server.sin_addr);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for removing this? doesn't that take away the ability to pass an IP address?

#include <fcntl.h>

/* platform-specific headers */
#ifdef HAVE_WINSOCK2_H

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to put all the conditional checks in here directly. Reasoning being that we essentially have two modes: POSIX and Win32. If we only have some of the headers for one or the other, things will break anyway.

#ifdef POSIX
#include <posix things>
#elsif WIN32
#include <win32 things>
#else
#error "Need either POSIX or WIN32, this platform seems to be neither"
#endif

that way all the checks can be removed from cmake+the config.h file.

add_subdirectory (src)

configure_file (
"${PROJECT_SOURCE_DIR}/src/StatsdClient2Config.h.in"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should rename this to drop the 2, i.e. StatsdClientConfig.h(.in)

@@ -0,0 +1,4 @@
add_library(StatsdClient2 statsd_client.cpp)

install (TARGETS StatsdClient2 DESTINATION bin)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a library, so DESTINATION lib?

add_library(StatsdClient2 statsd_client.cpp)

install (TARGETS StatsdClient2 DESTINATION bin)
install (FILES MathFunctions.h DESTINATION include)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file exists? statsd_client.h maybe?

@tom-binary tom-binary merged commit f1d2aea into binary-com:master Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants