Skip to content

Commit

Permalink
Fix for #5 (thanks to @ohler55)
Browse files Browse the repository at this point in the history
* Replaced 'static const char' with #define in natsp.h and nats.h
  • Loading branch information
kozlovic committed Nov 9, 2015
1 parent 4b64e7a commit 5ee3b6d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/nats.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
extern "C" {
#endif

static const char *NATS_DEFAULT_URL = "nats://localhost:4222";
#define NATS_DEFAULT_URL "nats://localhost:4222"

//
// Types.
Expand Down
50 changes: 25 additions & 25 deletions src/natsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@
// access
//#define DEV_MODE (1)

static const char* CString = "C";
static const char* Version = "1.0.0";

static const char* NATS_DEFAULT_URL = "nats://localhost:4222";

static const char* _OK_OP_ = "+OK";
static const char* _ERR_OP_ = "-ERR";
static const char* _MSG_OP_ = "MSG";
static const char* _PING_OP_ = "PING";
static const char* _PONG_OP_ = "PONG";
static const char* _INFO_OP_ = "INFO";

static const char* _CRLF_ = "\r\n";
static const char* _SPC_ = " ";
static const char* _PUB_P_ = "PUB ";

static const char* _PING_PROTO_ = "PING\r\n";
static const char* _PONG_PROTO_ = "PONG\r\n";
static const char* _PUB_PROTO_ = "PUB %s %s %d\r\n";
static const char* _SUB_PROTO_ = "SUB %s %s %d\r\n";
static const char* _UNSUB_PROTO_ = "UNSUB %" PRId64 " %d\r\n";
static const char* _UNSUB_NO_MAX_PROTO_ = "UNSUB %" PRId64 " \r\n";

static const char* STALE_CONNECTION = "Stale Connection";
static int STATE_CONNECTION_LEN = 16;
#define CString "C"
#define Version "1.0.0"

#define NATS_DEFAULT_URL "nats://localhost:4222"

#define _OK_OP_ "+OK"
#define _ERR_OP_ "-ERR"
#define _MSG_OP_ "MSG"
#define _PING_OP_ "PING"
#define _PONG_OP_ "PONG"
#define _INFO_OP_ "INFO"

#define _CRLF_ "\r\n"
#define _SPC_ " "
#define _PUB_P_ "PUB "

#define _PING_PROTO_ "PING\r\n"
#define _PONG_PROTO_ "PONG\r\n"
#define _PUB_PROTO_ "PUB %s %s %d\r\n"
#define _SUB_PROTO_ "SUB %s %s %d\r\n"
#define _UNSUB_PROTO_ "UNSUB %" PRId64 " %d\r\n"
#define _UNSUB_NO_MAX_PROTO_ "UNSUB %" PRId64 " \r\n"

#define STALE_CONNECTION "Stale Connection"
#define STATE_CONNECTION_LEN (16)

#define _CRLF_LEN_ (2)
#define _SPC_LEN_ (1)
Expand Down
18 changes: 8 additions & 10 deletions src/natstime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "natsp.h"

#include <assert.h>

#ifdef _WIN32
#include <sys/timeb.h>
#endif
Expand All @@ -18,13 +16,13 @@ nats_Now(void)
return (((int64_t)now.time) * 1000 + now.millitm);
#elif defined CLOCK_MONOTONIC
struct timespec ts;
int rc = clock_gettime(CLOCK_REALTIME, &ts);
assert(rc == 0);
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
abort();
return ((int64_t)ts.tv_sec) * 1000 + (((int64_t)ts.tv_nsec) / 1000000);
#else
struct timeval tv;
int rc = gettimeofday(&tv, NULL);
assert(rc == 0);
if (gettimeofday(&tv, NULL) != 0)
abort();
return ((int64_t)tv.tv_sec) * 1000 + (((int64_t)tv.tv_usec) / 1000);
#endif
}
Expand All @@ -38,13 +36,13 @@ nats_NowInNanoSeconds(void)
return (((int64_t)now.time) * 1000 + now.millitm) * 1000000L;
#elif defined CLOCK_MONOTONIC
struct timespec ts;
int rc = clock_gettime(CLOCK_REALTIME, &ts);
assert (rc == 0);
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
abort();
return ((int64_t)ts.tv_sec) * 1000000000L + ((int64_t)ts.tv_nsec);
#else
struct timeval tv;
int rc = gettimeofday(&tv, NULL);
assert(rc == 0);
if (gettimeofday(&tv, NULL) != 0)
abort();
return ((int64_t)tv.tv_sec) * 1000000000L + (((int64_t)tv.tv_usec) * 1000);
#endif
}
Expand Down
2 changes: 0 additions & 2 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ natsTimer_Reset(natsTimer *timer, int64_t interval)
void
natsTimer_Destroy(natsTimer *timer)
{
bool doStop = false;

if (timer == NULL)
return;

Expand Down

0 comments on commit 5ee3b6d

Please sign in to comment.