summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2012-12-16 17:47:51 -0800
committerBen Longbons <b.r.longbons@gmail.com>2012-12-24 10:02:00 -0800
commitb52127bcbf817ff8285b36d22198b275327e16bb (patch)
tree7bc596289c011e719168bef846b8cf63bf5d4947 /src/common
parent4bd7eeec09629d3c0f900d42c899fe23c69e07b6 (diff)
downloadtmwa-b52127bcbf817ff8285b36d22198b275327e16bb.tar.gz
tmwa-b52127bcbf817ff8285b36d22198b275327e16bb.tar.bz2
tmwa-b52127bcbf817ff8285b36d22198b275327e16bb.tar.xz
tmwa-b52127bcbf817ff8285b36d22198b275327e16bb.zip
Cleanup headers and remove all uses of va_list except logging
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.cpp26
-rw-r--r--src/common/core.hpp2
-rw-r--r--src/common/db.cpp59
-rw-r--r--src/common/db.hpp12
-rw-r--r--src/common/grfio.cpp33
-rw-r--r--src/common/grfio.hpp7
-rw-r--r--src/common/lock.cpp7
-rw-r--r--src/common/lock.hpp3
-rw-r--r--src/common/md5calc.cpp28
-rw-r--r--src/common/md5calc.hpp20
-rw-r--r--src/common/mmo.hpp5
-rw-r--r--src/common/mt_rand.cpp12
-rw-r--r--src/common/nullpo.cpp19
-rw-r--r--src/common/sanity.hpp2
-rw-r--r--src/common/socket.cpp40
-rw-r--r--src/common/socket.hpp9
-rw-r--r--src/common/timer.cpp44
-rw-r--r--src/common/utils.cpp6
-rw-r--r--src/common/utils2.hpp41
19 files changed, 211 insertions, 164 deletions
diff --git a/src/common/core.cpp b/src/common/core.cpp
index 9d1d8e7..a6a170b 100644
--- a/src/common/core.cpp
+++ b/src/common/core.cpp
@@ -1,15 +1,18 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <signal.h>
+#include "core.hpp"
+
#include <sys/wait.h>
-#include "core.hpp"
+#include <unistd.h>
+
+#include <csignal>
+#include <cstdio>
+#include <cstdlib>
+
+#include "mt_rand.hpp"
+#include "nullpo.hpp"
#include "socket.hpp"
#include "timer.hpp"
#include "version.hpp"
-#include "mt_rand.hpp"
-#include "nullpo.hpp"
// Added by Gabuzomeu
//
@@ -18,7 +21,8 @@
// Programming in the UNIX Environment_.
//
typedef void(*sigfunc)(int);
-static sigfunc compat_signal(int signo, sigfunc func)
+static
+sigfunc compat_signal(int signo, sigfunc func)
{
struct sigaction sact, oact;
@@ -37,11 +41,13 @@ static sigfunc compat_signal(int signo, sigfunc func)
return oact.sa_handler;
}
-static void chld_proc(int UNUSED)
+static
+void chld_proc(int)
{
wait(NULL);
}
-static void sig_proc(int UNUSED)
+static
+void sig_proc(int)
{
for (int i = 1; i < 31; ++i)
compat_signal(i, SIG_IGN);
diff --git a/src/common/core.hpp b/src/common/core.hpp
index 14dc61d..2d68eaf 100644
--- a/src/common/core.hpp
+++ b/src/common/core.hpp
@@ -1,6 +1,6 @@
#ifndef CORE_HPP
#define CORE_HPP
-#include <stdbool.h>
+
/// core.c contains a server-independent main() function
/// and then runs a do_sendrecv loop
diff --git a/src/common/db.cpp b/src/common/db.cpp
index e04b7d0..8780138 100644
--- a/src/common/db.cpp
+++ b/src/common/db.cpp
@@ -1,21 +1,23 @@
#include "db.hpp"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include "utils.hpp"
#define ROOT_SIZE 4096
-static int strdb_cmp(struct dbt *table, const char *a, const char* b)
+static
+int strdb_cmp(struct dbt *table, const char *a, const char* b)
{
if (table->maxlen)
return strncmp(a, b, table->maxlen);
return strcmp(a, b);
}
-static hash_t strdb_hash(struct dbt *table, const char *a)
+static
+hash_t strdb_hash(struct dbt *table, const char *a)
{
size_t i = table->maxlen;
if (i == 0)
@@ -38,7 +40,8 @@ struct dbt *strdb_init(size_t maxlen)
return table;
}
-static int numdb_cmp(numdb_key_t a, numdb_key_t b)
+static
+int numdb_cmp(numdb_key_t a, numdb_key_t b)
{
if (a == b)
return 0;
@@ -47,7 +50,8 @@ static int numdb_cmp(numdb_key_t a, numdb_key_t b)
return 1;
}
-static hash_t numdb_hash(numdb_key_t a)
+static
+hash_t numdb_hash(numdb_key_t a)
{
return (hash_t) a;
}
@@ -60,7 +64,8 @@ struct dbt *numdb_init(void)
return table;
}
-static int table_cmp(struct dbt *table, db_key_t a, db_key_t b)
+static
+int table_cmp(struct dbt *table, db_key_t a, db_key_t b)
{
switch (table->type)
{
@@ -70,7 +75,8 @@ static int table_cmp(struct dbt *table, db_key_t a, db_key_t b)
abort();
}
-static hash_t table_hash(struct dbt *table, db_key_t key)
+static
+hash_t table_hash(struct dbt *table, db_key_t key)
{
switch (table->type)
{
@@ -99,7 +105,8 @@ db_val_t db_search(struct dbt *table, db_key_t key)
}
// Tree maintainance methods
-static void db_rotate_left(struct dbn *p, struct dbn **root)
+static
+void db_rotate_left(struct dbn *p, struct dbn **root)
{
struct dbn *y = p->right;
p->right = y->left;
@@ -117,7 +124,8 @@ static void db_rotate_left(struct dbn *p, struct dbn **root)
p->parent = y;
}
-static void db_rotate_right(struct dbn *p, struct dbn **root)
+static
+void db_rotate_right(struct dbn *p, struct dbn **root)
{
struct dbn *y = p->left;
p->left = y->right;
@@ -135,7 +143,8 @@ static void db_rotate_right(struct dbn *p, struct dbn **root)
p->parent = y;
}
-static void db_rebalance(struct dbn *p, struct dbn **root)
+static
+void db_rebalance(struct dbn *p, struct dbn **root)
{
p->color = RED;
while (p != *root && p->parent->color == RED)
@@ -189,7 +198,8 @@ static void db_rebalance(struct dbn *p, struct dbn **root)
}
// param z = node to remove
-static void db_rebalance_erase(struct dbn *z, struct dbn **root)
+static
+void db_rebalance_erase(struct dbn *z, struct dbn **root)
{
struct dbn *y = z;
struct dbn *x = NULL;
@@ -397,7 +407,8 @@ db_val_t db_erase(struct dbt *table, db_key_t key)
return data;
}
#ifdef SMART_WALK_TREE
-static inline void db_walk_tree(bool dealloc, struct dbn* p, db_func_t func, va_list ap)
+static
+void db_walk_tree(bool dealloc, struct dbn* p, db_func_t func)
{
if (!p)
return;
@@ -415,7 +426,7 @@ static inline void db_walk_tree(bool dealloc, struct dbn* p, db_func_t func, va_
{
// apply_func loop
if (func)
- func(p->key, p->data, ap);
+ func(p->key, p->data);
if (p->left)
{
// continue descending
@@ -457,11 +468,8 @@ static inline void db_walk_tree(bool dealloc, struct dbn* p, db_func_t func, va_
}
#endif // SMART_WALK_TREE
-void db_foreach(struct dbt *table, db_func_t func, ...)
+void db_foreach(struct dbt *table, db_func_t func)
{
- va_list ap;
- va_start(ap, func);
-
for (int i = 0; i < HASH_SIZE; i++)
{
#ifdef SMART_WALK_TREE
@@ -474,7 +482,7 @@ void db_foreach(struct dbt *table, db_func_t func, ...)
int sp = 0;
while (1)
{
- func(p->key, p->data, ap);
+ func(p->key, p->data);
struct dbn *pn = p->left;
if (pn)
{
@@ -496,19 +504,15 @@ void db_foreach(struct dbt *table, db_func_t func, ...)
} // while true
#endif // else ! SMART_WALK_TREE
} // for i
- va_end(ap);
}
// This function is suspiciously similar to the previous
-void db_final(struct dbt *table, db_func_t func, ...)
+void db_final(struct dbt *table, db_func_t func)
{
- va_list ap;
- va_start(ap, func);
-
for (int i = 0; i < HASH_SIZE; i++)
{
#ifdef SMART_WALK_TREE
- db_walk_tree(true, table->ht[i], func, ap);
+ db_walk_tree(true, table->ht[i], func);
#else
struct dbn *p = table->ht[i];
if (!p)
@@ -518,7 +522,7 @@ void db_final(struct dbt *table, db_func_t func, ...)
while (1)
{
if (func)
- func(p->key, p->data, ap);
+ func(p->key, p->data);
struct dbn *pn = p->left;
if (pn)
{
@@ -542,5 +546,4 @@ void db_final(struct dbt *table, db_func_t func, ...)
#endif // else ! SMART_WALK_TREE
} // for i
free(table);
- va_end(ap);
}
diff --git a/src/common/db.hpp b/src/common/db.hpp
index 313ba3a..63ce7fa 100644
--- a/src/common/db.hpp
+++ b/src/common/db.hpp
@@ -3,7 +3,7 @@
#define DB_HPP
# include "sanity.hpp"
-# include <stdarg.h>
+# include <functional>
/// Number of tree roots
// Somewhat arbitrary - larger wastes more space but is faster for large trees
@@ -13,7 +13,7 @@
typedef enum dbn_color
{
RED,
- BLACK
+ BLACK,
} dbn_color;
typedef intptr_t numdb_key_t;
@@ -28,7 +28,7 @@ typedef union db_key_t
} db_key_t;
typedef void* db_val_t;
typedef uint32_t hash_t;
-typedef void(*db_func_t)(db_key_t, db_val_t, va_list);
+typedef std::function<void(db_key_t, db_val_t)> db_func_t;
/// DataBase Node
struct dbn
@@ -82,9 +82,9 @@ struct dbn *db_insert(struct dbt *table, db_key_t key, db_val_t data);
db_val_t db_erase(struct dbt *table, db_key_t key);
/// Execute a function for every element, in unspecified order
-void db_foreach(struct dbt *, db_func_t, ...);
+void db_foreach(struct dbt *, db_func_t);
// opposite of init? Calls release for every element and frees memory
// This probably isn't really needed: we don't have to free memory while exiting
-void db_final(struct dbt *, db_func_t, ...) __attribute__((deprecated));
+void db_final(struct dbt *, db_func_t) __attribute__((deprecated));
-#endif
+#endif // DB_HPP
diff --git a/src/common/grfio.cpp b/src/common/grfio.cpp
index 042de85..7eb847a 100644
--- a/src/common/grfio.cpp
+++ b/src/common/grfio.cpp
@@ -1,13 +1,15 @@
// Reads .gat files by name-mapping .wlk files
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "grfio.hpp"
+
#include <sys/stat.h>
-#include "utils.hpp"
-#include "grfio.hpp"
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
#include "mmo.hpp"
#include "socket.hpp"
+#include "utils.hpp"
//----------------------------
// file entry table struct
@@ -22,19 +24,24 @@ typedef struct
#define FILELIST_LIMIT 32768 // limit to number of filelists - if you increase this, change all shorts to int
#define FILELIST_ADDS 1024 // amount to increment when reallocing
-static FILELIST *filelist = NULL;
+static
+FILELIST *filelist = NULL;
/// Number of entries used
-static uint16_t filelist_entrys = 0;
+static
+uint16_t filelist_entrys = 0;
/// Number of FILELIST entries actually allocated
-static uint16_t filelist_maxentry = 0;
+static
+uint16_t filelist_maxentry = 0;
/// First index of the given hash, into the filelist[] array
#define l -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
-static int16_t filelist_hash[256] = {l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l};
+static
+int16_t filelist_hash[256] = {l,l,l,l,l,l,l,l,l,l,l,l,l,l,l,l};
#undef l
/// Hash a filename
-static uint8_t filehash(const char *fname)
+static
+uint8_t filehash(const char *fname)
{
// Larger than the return type - upper bits are used in the process
uint32_t hash = 0;
@@ -61,7 +68,8 @@ FILELIST *filelist_find(const char *fname)
}
/// Copy a temporary entry into the hash map
-static FILELIST *filelist_add(FILELIST * entry)
+static
+FILELIST *filelist_add(FILELIST * entry)
{
if (filelist_entrys >= FILELIST_LIMIT)
{
@@ -87,7 +95,8 @@ static FILELIST *filelist_add(FILELIST * entry)
return &filelist[new_index];
}
-static FILELIST *filelist_modify(FILELIST * entry)
+static
+FILELIST *filelist_modify(FILELIST * entry)
{
FILELIST *fentry = filelist_find(entry->fn);
if (fentry)
diff --git a/src/common/grfio.hpp b/src/common/grfio.hpp
index f418ac3..58afb07 100644
--- a/src/common/grfio.hpp
+++ b/src/common/grfio.hpp
@@ -1,9 +1,12 @@
+#ifndef GRFIO_HPP
+#define GRFIO_HPP
+
+# include "sanity.hpp"
+
/// Accessor to the .gat map virtual files
// Note .gat files are mapped to .wlk files by data/resnametable.txt
// Note that there currently is a 1-1 correlation between them,
// but it is possible for a single .wlk to have multiple .gats reference it
-#ifndef GRFIO_HPP
-#define GRFIO_HPP
/// Load file into memory
# define grfio_read(resourcename) grfio_reads(resourcename, NULL)
diff --git a/src/common/lock.cpp b/src/common/lock.cpp
index 13a99c5..9075cbb 100644
--- a/src/common/lock.cpp
+++ b/src/common/lock.cpp
@@ -1,6 +1,9 @@
-#include <unistd.h>
-#include <stdio.h>
#include "lock.hpp"
+
+#include <unistd.h>
+
+#include <cstdio>
+
#include "socket.hpp"
/// Protected file writing
diff --git a/src/common/lock.hpp b/src/common/lock.hpp
index d6128d8..8b444f4 100644
--- a/src/common/lock.hpp
+++ b/src/common/lock.hpp
@@ -1,5 +1,8 @@
#ifndef LOCK_HPP
#define LOCK_HPP
+
+#include <cstdio>
+
/// Locked FILE I/O
// Changes are made in a separate file until lock_fclose
FILE *lock_fopen(const char *filename, int *info);
diff --git a/src/common/md5calc.cpp b/src/common/md5calc.cpp
index 9027bc9..e5a9fc0 100644
--- a/src/common/md5calc.cpp
+++ b/src/common/md5calc.cpp
@@ -1,5 +1,7 @@
#include "md5calc.hpp"
-#include <string.h>
+
+#include <cstring>
+
#include "mt_rand.hpp"
// auxilary data
@@ -9,7 +11,8 @@ sin() constant table
echo 'scale=40; obase=16; for (i=1;i<=64;i++) print 2^32 * sin(i), "\n"' |
bc | sed 's/^-//;s/^/0x/;s/\..*$/,/'
*/
-static const uint32_t T[64] =
+static
+const uint32_t T[64] =
{
// used by round 1
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, //0
@@ -35,29 +38,35 @@ static const uint32_t T[64] =
// auxilary functions
// note - the RFC defines these by non-CS conventions: or=v, and=(empty)
-static inline uint32_t rotate_left(uint32_t val, unsigned shift)
+static
+uint32_t rotate_left(uint32_t val, unsigned shift)
{
return val << shift | val >> (32-shift);
}
-static inline uint32_t F(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t F(uint32_t X, uint32_t Y, uint32_t Z)
{
return (X & Y) | (~X & Z);
}
-static inline uint32_t G(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t G(uint32_t X, uint32_t Y, uint32_t Z)
{
return (X & Z) | (Y & ~Z);
}
-static inline uint32_t H(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t H(uint32_t X, uint32_t Y, uint32_t Z)
{
return X ^ Y ^ Z;
}
-static inline uint32_t I(uint32_t X, uint32_t Y, uint32_t Z)
+static
+uint32_t I(uint32_t X, uint32_t Y, uint32_t Z)
{
return Y ^ (X | ~Z);
}
-static const struct
+static
+const struct
{
uint8_t k : 4;
uint8_t : 0;
@@ -165,7 +174,8 @@ void MD5_to_bin(MD5_state state, uint8_t out[0x10])
out[i] = state.val[i/4] >> 8*(i%4);
}
-static const char hex[] = "0123456789abcdef";
+static
+const char hex[] = "0123456789abcdef";
void MD5_to_str(MD5_state state, char out[0x21])
{
diff --git a/src/common/md5calc.hpp b/src/common/md5calc.hpp
index 2aed0bc..de19e0f 100644
--- a/src/common/md5calc.hpp
+++ b/src/common/md5calc.hpp
@@ -5,9 +5,9 @@
#include <netinet/in.h>
-#include <stdint.h> // uint32_t, uint8_t
-#include <stddef.h> // size_t
-#include <stdio.h> // FILE*
+#include <cstdint>
+#include <cstddef>
+#include <cstdio>
/// The digest state - becomes the output
typedef struct
@@ -35,18 +35,6 @@ MD5_state MD5_from_cstring(const char* msg);
MD5_state MD5_from_FILE(FILE* in);
-/// Output in ASCII - with lowercase hex digits, null-terminated
-// these may overlap safely
-static void MD5_String(const char *string, char output[33]) __attribute__((deprecated));
-static inline void MD5_String(const char *string, char output[33]) {
- MD5_to_str(MD5_from_cstring(string), output);
-}
-/// Output in binary
-static void MD5_String2binary(const char *string, uint8_t output[16]) __attribute__((deprecated));
-static inline void MD5_String2binary(const char *string, uint8_t output[16]) {
- MD5_to_bin(MD5_from_cstring(string), output);
-}
-
// statically-allocated output
// whoever wrote this fails basic understanding of
const char *MD5_saltcrypt(const char *key, const char *salt);
@@ -61,4 +49,4 @@ bool pass_ok(const char *password, const char *crypted);
/// This returns an in_addr because it is configurable whether it gets called at all
struct in_addr MD5_ip(char *secret, struct in_addr ip);
-#endif
+#endif // MD5CALC_HPP
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index eb8ed1c..178247c 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -2,8 +2,9 @@
#ifndef MMO_HPP
#define MMO_HPP
-# include <time.h>
-# include "utils.hpp" // LCCWIN32
+# include <ctime>
+
+# include "utils.hpp"
# define FIFOSIZE_SERVERLINK 256*1024
diff --git a/src/common/mt_rand.cpp b/src/common/mt_rand.cpp
index 91ae2e4..651620a 100644
--- a/src/common/mt_rand.cpp
+++ b/src/common/mt_rand.cpp
@@ -45,9 +45,10 @@
//
*/
-#include <time.h>
#include "mt_rand.hpp"
+#include <ctime>
+
#define N 624 // length of state vector
#define M 397 // a period parameter
#define K 0x9908B0DFU // a magic constant
@@ -57,9 +58,12 @@
#define loBits(u) ((u) & 0x7FFFFFFFU) // mask the highest bit of u
#define mixBits(u, v) (hiBit(u)|loBits(v)) // move hi bit of u to hi bit of v
-static uint32_t state[N+1]; // state vector the +1 is needed due to the coding
-static uint32_t *next; // next random value is computed from here
-static int left = -1; // can *next++ this many times before reloading
+static
+uint32_t state[N+1]; // state vector the +1 is needed due to the coding
+static
+uint32_t *next; // next random value is computed from here
+static
+int left = -1; // can *next++ this many times before reloading
void mt_seed(uint32_t seed)
{
diff --git a/src/common/nullpo.cpp b/src/common/nullpo.cpp
index ad52009..53ed37d 100644
--- a/src/common/nullpo.cpp
+++ b/src/common/nullpo.cpp
@@ -1,11 +1,14 @@
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
#include "nullpo.hpp"
-static void nullpo_info_core(const char *file, int line, const char *func);
+#include <cstdarg> // exception to "no va_list" rule
+#include <cstdio>
+#include <cstring>
+
+static
+void nullpo_info_core(const char *file, int line, const char *func);
__attribute__((format(printf, 4, 0)))
-static void nullpo_info_core(const char *file, int line, const char *func,
+static
+void nullpo_info_core(const char *file, int line, const char *func,
const char *fmt, va_list ap);
/// Null check and print format
@@ -48,7 +51,8 @@ void nullpo_info(const char *file, int line, const char *func)
}
/// Actual output function
-static void nullpo_info_core(const char *file, int line, const char *func)
+static
+void nullpo_info_core(const char *file, int line, const char *func)
{
if (!file)
file = "??";
@@ -58,7 +62,8 @@ static void nullpo_info_core(const char *file, int line, const char *func)
fprintf(stderr, "%s:%d: in func `%s': NULL pointer\n", file, line, func);
}
-static void nullpo_info_core(const char *file, int line, const char *func,
+static
+void nullpo_info_core(const char *file, int line, const char *func,
const char *fmt, va_list ap)
{
nullpo_info_core(file, line, func);
diff --git a/src/common/sanity.hpp b/src/common/sanity.hpp
index 7ffd077..c4f75e0 100644
--- a/src/common/sanity.hpp
+++ b/src/common/sanity.hpp
@@ -21,8 +21,6 @@
# error "please compile with -m32"
# endif
-/// A name for unused function arguments - can be repeated
-# define UNUSED /* empty works for C++ */
/// Convert type assumptions to use the standard types here
# include <cstdint>
/// size_t, NULL
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index fb254dc..f223b83 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -1,22 +1,20 @@
-// $Id: socket.c,v 1.1.1.1 2004/09/10 17:44:49 MagicalTux Exp $
-// original : core.c 2003/02/26 18:03:12 Rev 1.7
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <errno.h>
+#include "socket.hpp"
-#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
+#include <sys/socket.h>
#include <sys/time.h>
-#include <unistd.h>
+#include <sys/types.h>
#include <fcntl.h>
-#include <string.h>
+#include <unistd.h>
-#include "mmo.hpp" // [Valaris] thanks to fov
-#include "socket.hpp"
+#include <cerrno>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include "mmo.hpp"
#include "utils.hpp"
fd_set readfds;
@@ -29,9 +27,11 @@ const uint32_t WFIFO_SIZE = 65536;
struct socket_data *session[FD_SETSIZE];
/// Discard all input
-static void null_parse(int fd);
+static
+void null_parse(int fd);
/// Default parser for new connections
-static void(*default_func_parse)(int) = null_parse;
+static
+void(*default_func_parse)(int) = null_parse;
void set_defaultparse(void(*defaultparse)(int))
{
@@ -39,7 +39,8 @@ void set_defaultparse(void(*defaultparse)(int))
}
/// Read from socket to the queue
-static void recv_to_fifo(int fd)
+static
+void recv_to_fifo(int fd)
{
if (session[fd]->eof)
return;
@@ -58,7 +59,8 @@ static void recv_to_fifo(int fd)
}
}
-static void send_from_fifo(int fd)
+static
+void send_from_fifo(int fd)
{
if (session[fd]->eof)
return;
@@ -81,14 +83,16 @@ static void send_from_fifo(int fd)
}
}
-static void null_parse(int fd)
+static
+void null_parse(int fd)
{
printf("null_parse : %d\n", fd);
RFIFOSKIP(fd, RFIFOREST(fd));
}
-static void connect_client(int listen_fd)
+static
+void connect_client(int listen_fd)
{
struct sockaddr_in client_address;
socklen_t len = sizeof(client_address);
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index b2ef119..08dc3f6 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -3,13 +3,12 @@
# include "sanity.hpp"
-# include <stdio.h>
-
-# include <sys/types.h>
-# include <sys/socket.h>
# include <netinet/in.h>
+# include <sys/socket.h>
+# include <sys/types.h>
-# include <time.h>
+# include <cstdio>
+# include <ctime>
/// Check how much can be read
# define RFIFOREST(fd) (session[fd]->rdata_size-session[fd]->rdata_pos)
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index 8a12d19..0215b53 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -1,18 +1,23 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
+#include "timer.hpp"
#include <sys/socket.h>
#include <sys/time.h>
+#include <sys/types.h>
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
-#include "timer.hpp"
#include "utils.hpp"
-static struct TimerData *timer_data;
-static uint32_t timer_data_max, timer_data_num;
-static timer_id *free_timer_list;
-static uint32_t free_timer_list_max, free_timer_list_pos;
+static
+struct TimerData *timer_data;
+static
+uint32_t timer_data_max, timer_data_num;
+static
+timer_id *free_timer_list;
+static
+uint32_t free_timer_list_max, free_timer_list_pos;
/// Okay, I think I understand this structure now:
/// the timer heap is a magic queue that allows inserting timers and then popping them in order
@@ -20,14 +25,18 @@ static uint32_t free_timer_list_max, free_timer_list_pos;
// timer_heap[0] is the size (greatest index into the heap)
// timer_heap[1] is the first actual element
// timer_heap_max increases 256 at a time and never decreases
-static uint32_t timer_heap_max = 0;
+static
+uint32_t timer_heap_max = 0;
/// FIXME: refactor the code to put the size in a separate variable
//nontrivial because indices get multiplied
-static timer_id *timer_heap = NULL;
+static
+timer_id *timer_heap = NULL;
-static uint32_t gettick_cache;
-static uint8_t gettick_count = 0;
+static
+uint32_t gettick_cache;
+static
+uint8_t gettick_count = 0;
uint32_t gettick_nocache(void)
{
@@ -46,7 +55,8 @@ uint32_t gettick(void)
return gettick_nocache();
}
-static void push_timer_heap(timer_id index)
+static
+void push_timer_heap(timer_id index)
{
if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max)
{
@@ -71,14 +81,16 @@ static void push_timer_heap(timer_id index)
timer_heap[h + 1] = index;
}
-static timer_id top_timer_heap(void)
+static
+timer_id top_timer_heap(void)
{
if (!timer_heap || !timer_heap[0])
return -1;
return timer_heap[1];
}
-static timer_id pop_timer_heap(void)
+static
+timer_id pop_timer_heap(void)
{
if (!timer_heap || !timer_heap[0])
return -1;
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
index 732f3b1..35fdf5a 100644
--- a/src/common/utils.cpp
+++ b/src/common/utils.cpp
@@ -1,10 +1,10 @@
#include "utils.hpp"
-#include <cstring>
+#include <netinet/in.h>
+
#include <cstdio>
#include <cstdlib>
-
-#include <netinet/in.h>
+#include <cstring>
//-----------------------------------------------------
// Function to suppress control characters in a string.
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp
index aef6f73..c92fdae 100644
--- a/src/common/utils2.hpp
+++ b/src/common/utils2.hpp
@@ -1,8 +1,8 @@
// included by utils.hpp as a porting aid.
// Eventually it will be promoted to one or more normal headers.
-#include <type_traits>
#include <iterator>
+#include <type_traits>
template<class T, class E, E max>
struct earray
@@ -64,14 +64,14 @@ public:
template<class It>
class IteratorPair
{
- It b, e;
+ It _b, _e;
public:
IteratorPair(It b, It e)
- : b(b), e(e)
+ : _b(b), _e(e)
{}
- It begin() { return b; }
- It end() { return e; }
+ It begin() { return _b; }
+ It end() { return _e; }
};
template<class It>
@@ -80,27 +80,23 @@ IteratorPair<It> iterator_pair(It b, It e)
return {b, e};
}
-#ifndef HAVE_STD_UNDERLYING_TYPE
-// Note: you *must* correctly define/not define this - it conflicts!
-namespace std
+// std::underlying_type isn't supported until gcc 4.7
+// this is a poor man's emulation
+template<class E>
+struct underlying_type
{
- template<class E>
- struct underlying_type
- {
- static_assert(std::is_enum<E>::value, "Only enums have underlying type!");
- typedef typename std::conditional<
- std::is_signed<E>::value,
- typename std::make_signed<E>::type,
- typename std::make_unsigned<E>::type
- >::type type;
- };
-}
-#endif // HAVE_STD_UNDERLYING_TYPE
+ static_assert(std::is_enum<E>::value, "Only enums have underlying type!");
+ typedef typename std::conditional<
+ std::is_signed<E>::value,
+ typename std::make_signed<E>::type,
+ typename std::make_unsigned<E>::type
+ >::type type;
+};
template<class E>
class EnumValueIterator
{
- typedef typename std::underlying_type<E>::type U;
+ typedef typename underlying_type<E>::type U;
E value;
public:
EnumValueIterator(E v)
@@ -136,3 +132,6 @@ IteratorPair<EnumValueIterator<E>> erange(E b, E e)
{
return {b, e};
}
+
+namespace std { namespace placeholders {} }
+namespace ph = std::placeholders;