Permalink
Browse files

builds on GCC 4.7.1

  • Loading branch information...
1 parent 2aa824e commit b4be5dfa625cb3037f884dcdd0ce0032abdca218 @jwatte jwatte committed Sep 25, 2012
Showing with 215 additions and 22 deletions.
  1. +4 −12 .gitignore
  2. +4 −2 Makefile
  3. +19 −2 configure
  4. +1 −1 daemon/HttpServer.h
  5. +2 −0 daemon/IComplete.h
  6. +1 −1 daemon/RequestInFlight.cpp
  7. +1 −1 daemon/StatStore.cpp
  8. +2 −0 daemon/main.cpp
  9. +2 −0 daemon/threadfunc.h
  10. +3 −3 ftest/functions
  11. +176 −0 tool/istatd_netcat.cpp
View
@@ -1,12 +1,4 @@
-# Compiled Object files
-*.slo
-*.lo
-*.o
-
-# Compiled Dynamic libraries
-*.so
-
-# Compiled Static libraries
-*.lai
-*.la
-*.a
+bin
+obj
+*~
+core
View
@@ -17,7 +17,8 @@ DAEMON_OBJS:=$(patsubst %.cpp,obj/%.o,$(DAEMON_SRCS))
SPLITTER_MAIN_SRC:=splitter/main.cpp
SPLITTER_MAIN_OBJ:=$(patsubst %.cpp,obj/%.o,$(SPLITTER_MAIN_SRC))
DAEMONS:=istatd splitd
-DEPS:=$(sort $(patsubst %.o,%.d,$(TEST_OBJS) $(TOOL_OBJS) $(LIB_OBJS) $(DAEMON_OBJS) $(DAEMON_MAIN_OBJ) $(SPLITTER_MAIN_OBJ)))
+DEPS:=$(sort $(patsubst %.o,%.d,$(TEST_OBJS) $(TOOL_OBJS) $(LIB_OBJS) $(DAEMON_OBJS) \
+ $(DAEMON_MAIN_OBJ) $(SPLITTER_MAIN_OBJ)))
BINS:=$(patsubst %,bin/%,$(TESTS) $(TOOLS) $(DAEMONS))
LIB_DEPS:=$(foreach lib,$(LIBS),obj/lib$(lib).a)
HDRS:=$(wildcard include/istat/*.h) $(wildcard include/json/*.h)
@@ -40,7 +41,8 @@ ifeq ($(OPT),)
OPT := -O2
endif
CXXFLAGS:=-pipe $(OPT) -g -Iinclude -MMD -D_LARGEFILE64_SOURCE -Wall -Werror
-SYS_LIBS:=$(BOOST_SYSTEM) -lboost_thread -lboost_signals -lpthread $(STATGRAB) $(BOOST_FILESYSTEM) -lboost_date_time
+SYS_LIBS:=$(BOOST_SYSTEM) -lboost_thread -lboost_signals -lpthread $(STATGRAB) \
+ $(BOOST_FILESYSTEM) -lboost_date_time $(LIBRT)
all: $(DIR_DEPS) $(LIB_DEPS) $(BINS) tests ftests
View
@@ -12,6 +12,7 @@ echo "# makevars.config for istatd generated on " `date` > makevars.config
BOOST_SYSTEM=""
BOOST_FILESYSTEM=""
STATGRAB=""
+LIBRT=""
DESTDIR=""
USR_PREFIX=""
VAR_PREFIX=""
@@ -31,6 +32,10 @@ while [ $# -gt 0 ]; do
shift
STATGRAB="$1"
;;
+ --librt)
+ shift
+ LIBRT="$1"
+ ;;
--prefix)
shift
DESTDIR="$1"
@@ -52,6 +57,7 @@ while [ $# -gt 0 ]; do
echo "--boost_system -lboost_system-mt What is the boost_system library name?"
echo "--boost_filesystem -lboost_filesystem-mt What is the boost_filesystem library name?"
echo "--statgrab -lstatgrab What is the statgrab library name?"
+ echo "--librt -lrt What is the librt library name (if any)?"
echo "--prefix / What is the root of the install?"
echo "--usr-prefix /usr What is the '/usr' directory for executables?"
echo "--var-prefix /var What is the '/var' directory for database data?"
@@ -72,22 +78,23 @@ fi
if [ ! -r /usr/include/statgrab.h -a ! -r /usr/local/include/statgrab.h ]; then
echo "You need to install libstatgrab-dev for your distribution, or "
echo "download and install it from source. See README.md"
+ exit 1
fi
# boost_system is a pain across versions
if [ -z "$BOOST_SYSTEM" ]; then
if [ -r /usr/lib/libboost_system.so ]; then
BOOST_SYSTEM=-lboost_system
- elif [ -r /usr/lib/libboost_system.so ]; then
+ elif [ -r /usr/lib/libboost_system-mt.so ]; then
BOOST_SYSTEM=-lboost_system-mt.so
fi
fi
# boost_filesystem is also somewhat a pain
if [ -z "$BOOST_FILESYSTEM" ]; then
if [ -r /usr/lib/libboost_filesystem.so ]; then
BOOST_FILESYSTEM=-lboost_filesystem
- elif [ -r /usr/lib/libboost_filesystem.so ]; then
+ elif [ -r /usr/lib/libboost_filesystem-mt.so ]; then
BOOST_FILESYSTEM=-lboost_filesystem-mt
fi
fi
@@ -98,6 +105,13 @@ if [ -z "$STATGRAB" ]; then
STATGRAB=-lstatgrab
fi
fi
+if [ -z "$LIBRT" ]; then
+ if [ -r /usr/lib/librt.so ]; then
+ LIBRT=-lrt
+ elif [ -r /usr/local/lib/librt.so ]; then
+ LIBRT=-lrt
+ fi
+fi
if [ ! -z "$BOOST_SYSTEM" ]; then
echo "BOOST_SYSTEM=$BOOST_SYSTEM" >> makevars.config
@@ -108,6 +122,9 @@ fi
if [ ! -z "$STATGRAB" ]; then
echo "STATGRAB=$STATGRAB" >> makevars.config
fi
+if [ ! -z "$LIBRT" ]; then
+ echo "LIBRT=$LIBRT" >> makevars.config
+fi
if [ ! -z "$DESTDIR" ]; then
echo "DESTDIR=$DESTDIR" >> makevars.config
fi
View
@@ -132,7 +132,7 @@ class HttpServer : public IHttpServerInfo
{
public:
HttpServer(int port, boost::asio::io_service &svc, std::string listen_addr);
- ~HttpServer();
+ virtual ~HttpServer();
inline boost::asio::io_service &svc() { return svc_; }
// You will see the request *before* headers are parsed.
// Generally, sign up for onHeader_ and perhaps onError_ if you keep a reference.
View
@@ -6,6 +6,8 @@ class IComplete
{
public:
virtual void on_complete() = 0;
+protected:
+ virtual ~IComplete() {}
};
template<typename Cls, void (Cls::*Func)()>
@@ -213,7 +213,7 @@ class MultiCounterWorker
for (std::map<boost::shared_ptr<IStatCounter>, std::pair<boost::asio::strand *, std::string> >::iterator
ptr(data.begin()), end(data.end()); ptr != end; ++ptr)
{
- (*ptr).second.first->io_service().post((*ptr).second.first->wrap(
+ (*ptr).second.first->get_io_service().post((*ptr).second.first->wrap(
boost::bind(&MultiCounterWorker::workOne, this, (*ptr).first, (*ptr).second.second)));
}
}
@@ -349,7 +349,7 @@ class Flusher
delete this;
return;
}
- ptrs.front()->strand_.io_service().post(ptrs.front()->strand_.wrap(
+ ptrs.front()->strand_.get_io_service().post(ptrs.front()->strand_.wrap(
boost::bind(&Flusher::flush_stuff, this)));
}
void flush_stuff()
View
@@ -997,12 +997,14 @@ int main(int argc, char const *argv[])
{
std::cerr << "Error in main() [" << x.what() << "]" << std::endl;
delete hsp;
+ delete asp;
return 2;
}
catch (...)
{
std::cerr << "Error in main() [unknown]" << std::endl;
delete hsp;
+ delete asp;
return 1;
}
View
@@ -4,8 +4,10 @@
#include <boost/thread/locks.hpp>
#include <boost/thread/recursive_mutex.hpp>
+#include <boost/asio.hpp>
typedef boost::lock_guard<boost::recursive_mutex> grab;
typedef boost::recursive_mutex lock;
+
#endif // daemon_threadfunc_h
View
@@ -94,7 +94,7 @@ function wait_for_stats {
N=0
echo -n "wait_for_stats $PORT $EXPECTED "
while [ $N -lt 100 ]; do
- DATA=`echo -ne 'stats\r\nquit\r\n' | netcat -q 1 localhost $PORT || true`
+ DATA=`echo -ne 'stats\r\nquit\r\n' | bin/istatd_netcat -q 1 localhost $PORT || true`
DATA=`echo "$DATA" | grep -F "$EXPECTED" || true`
if [ ! -z "$DATA" ]; then
echo ""
@@ -133,7 +133,7 @@ function send_stat {
if [ -z "$2" ]; then
failure "usage: send_stat port counter.name val [...]"
fi
- echo -ne "$*\r\n" | netcat -q 1 localhost "$PORT"
+ echo -ne "$*\r\n" | bin/istatd_netcat -q 1 localhost "$PORT"
}
function send_event {
@@ -142,7 +142,7 @@ function send_event {
if [ -z "$1" ]; then
failure "usage: send_event port 'eventType|eventMessage[|maybehost]'"
fi
- echo -ne "$*\r\n" | netcat -q 1 localhost "$PORT"
+ echo -ne "$*\r\n" | bin/istatd_netcat -q 1 localhost "$PORT"
}
function make_data {
View
@@ -0,0 +1,176 @@
+
+/* this tool does not purport to emulate the full netcat; rather
+ it is a version that works for IMVU test scripts without having
+ a dependency on a specific installed version of netcat (the -q
+ option in particular).
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <errno.h>
+#include <time.h>
+
+
+void usage() {
+ fprintf(stderr, "usage: istatd_netcat [-q timeout] host port\n");
+ exit(1);
+}
+
+int connect_to(char const *host, unsigned short port) {
+ struct sockaddr_in sin;
+ memset(&sin, 0, sizeof(sin));
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(port);
+ struct hostent *hent = gethostbyname(host);
+ if (!hent || !hent->h_addr_list[0]) {
+ fprintf(stderr, "host not found: %s\n", host);
+ exit(1);
+ }
+ if (hent->h_length != sizeof(sin.sin_addr)) {
+ fprintf(stderr, "wrong host address type: %s\n", host);
+ exit(1);
+ }
+ memcpy(&sin.sin_addr, hent->h_addr_list[0], sizeof(sin.sin_addr));
+
+ int s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+ perror("socket()");
+ exit(1);
+ }
+ int c = connect(s, (struct sockaddr *)&sin, sizeof(sin));
+ if (c < 0) {
+ fprintf(stderr, "connect(%s:%d) failed: %s\n", host, port, strerror(errno));
+ exit(1);
+ }
+ return s;
+}
+
+int recvsome(int s, void *buf, int len) {
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(s, &fds);
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 250000;
+ int sres = select(s+1, &fds, 0, 0, &tv);
+ if (sres < 0) {
+ return sres;
+ }
+ if (!FD_ISSET(s, &fds)) {
+ return 0;
+ }
+ int rres = recv(s, buf, len, 0);
+ return rres == 0 ? -2 : rres;
+}
+
+
+int main(int argc, char const *argv[]) {
+
+ int qflag = 0;
+ char const *host = 0;
+ unsigned short port = 0;
+
+ /* parse arguments */
+
+ while (argv[1]) {
+ if (!strcmp(argv[1], "-q")) {
+ if (!argv[2]) {
+ usage();
+ }
+ qflag = atoi(argv[2]);
+ if (qflag <= 0) {
+ usage();
+ }
+ ++argv;
+ --argc;
+ }
+ else if (argv[1][0] == '-') {
+ usage();
+ }
+ else {
+ if (!host) {
+ host = argv[1];
+ }
+ else if (!port) {
+ int i = atoi(argv[1]);
+ if (i < 1 || i > 65535) {
+ usage();
+ }
+ port = (unsigned short)i;
+ }
+ }
+ ++argv;
+ --argc;
+ }
+ if (!host) {
+ usage();
+ }
+ if (!port) {
+ usage();
+ }
+
+ /* connect to host */
+ char buf[8192];
+ int r, s = connect_to(host, port);
+
+ /* do an echo thing */
+ while (true) {
+ r = read(0, buf, sizeof(buf));
+ if (r < 0) {
+ perror("read(stdin)");
+ exit(1);
+ }
+ if (r == 0) {
+ break;
+ }
+ int off = 0;
+ while (r > off) {
+ int q = send(s, &buf[off], r-off, 0);
+ if (q < 0) {
+ perror("send()");
+ exit(1);
+ }
+ if (q == 0) {
+ break;
+ }
+ off += q;
+ }
+ r = recvsome(s, buf, sizeof(buf));
+ if (r == -2) { // closed
+ break;
+ }
+ if (r < 0) {
+ perror("recv()");
+ exit(1);
+ }
+ if (r > 0) {
+ write(1, buf, r);
+ }
+ }
+ shutdown(s, SHUT_WR);
+
+ time_t now, then;
+ time(&now);
+ then = now + qflag;
+ r = 1;
+ while (now <= then || r > 0) {
+ r = recvsome(s, buf, sizeof(buf));
+ if (r == -2) { // closed
+ break;
+ }
+ if (r < 0) {
+ perror("recv()");
+ exit(1);
+ }
+ if (r > 0) {
+ write(1, buf, r);
+ }
+ time(&now);
+ }
+ close(s);
+ return 0;
+}
+

0 comments on commit b4be5df

Please sign in to comment.