]> git.meshlink.io Git - meshlink/commitdiff
windows compatibility
authorNiklas Hofmann <niklas.hofmann@everbase.net>
Sat, 25 Oct 2014 20:17:51 +0000 (22:17 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sat, 27 Dec 2014 17:13:28 +0000 (18:13 +0100)
examples/Makefile.am
examples/manynodes.c
src/Makefile.am
src/devtools.c
src/discovery.c
src/event.h
src/net.c
src/net_socket.c

index 8653adc6175173f252e3413949ead77c971abeff..816a00b04e96805f6fb61abac3b2fa28fca4ed51 100644 (file)
@@ -3,16 +3,16 @@ bin_PROGRAMS = meshlinkapp chat chatpp manynodes channels
 AM_CPPFLAGS = -I../src
 
 meshlinkapp_SOURCES = meshlinkapp.c
-meshlinkapp_LDADD = ../src/libmeshlink.la
+meshlinkapp_LDADD = ../src/libmeshlink.la ../catta/src/libcatta.la
 
 chat_SOURCES = chat.c
-chat_LDADD = ../src/libmeshlink.la
+chat_LDADD = ../src/libmeshlink.la ../catta/src/libcatta.la
 
 chatpp_SOURCES = chatpp.cc
-chatpp_LDADD = ../src/libmeshlink.la
+chatpp_LDADD = ../src/libmeshlink.la ../catta/src/libcatta.la
 
 manynodes_SOURCES = manynodes.cc
-manynodes_LDADD = ../src/libmeshlink.la
+manynodes_LDADD = ../src/libmeshlink.la ../catta/src/libcatta.la
 
 channels_SOURCES = channels.c
-channels_LDADD = ../src/libmeshlink.la
+channels_LDADD = ../src/libmeshlink.la ../catta/src/libcatta.la
index 3f59ec38448366da194e442807d83e3ca095ad1c..393d586d35fc05128e31339f13bda46558ab6ea2 100644 (file)
@@ -4,7 +4,10 @@
 #include <strings.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#ifndef _WIN32
 #include <linux/limits.h>
+#endif
 
 #include "../src/meshlink.h"
 #include "../src/devtools.h"
@@ -118,6 +121,7 @@ void exportmeshgraph_timer(int signum)
        exportmeshgraph(name);
 }
 
+#ifndef _WIN32
 static bool exportmeshgraph_started = false;
 
 static bool exportmeshgraph_end(const char* none)
@@ -172,6 +176,17 @@ static bool exportmeshgraph_begin(const char* timeout_str)
 
        return true;
 }
+#else
+static bool exportmeshgraph_end(const char* none)
+{
+       return false;
+}
+
+static bool exportmeshgraph_begin(const char* timeout_str)
+{
+       return false;
+}
+#endif
 
 static void parse_command(char *buf) {
        char *arg = strchr(buf, ' ');
@@ -365,7 +380,11 @@ int main(int argc, char *argv[]) {
        mesh = calloc(n, sizeof *mesh);
 
        meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_message);
+#ifndef _WIN32
        mkdir(basebase, 0750);
+#else
+       mkdir(basebase);
+#endif
 
        char filename[PATH_MAX];
        char nodename[100];
index 89ca0e8e9ff0fa4bc5fb92d83be11fb06d782b68..11dc219e6f1ba3794ed1a108ad937d53865ae246 100644 (file)
@@ -111,7 +111,11 @@ libmeshlink_la_SOURCES = \
 
 libmeshlink_la_CFLAGS = -fPIC -I../catta/include/
 
-libmeshlink_la_LIBADD = -lpthread ../catta/src/.libs/libcatta.a
+if MINGW
+libmeshlink_la_CFLAGS += -I../catta/src/compat/windows/include/
+endif
+
+libmeshlink_la_LIBADD = -lpthread ../catta/src/libcatta.la
 
 libmeshlink_la_SOURCES += \
        ed25519/ecdh.c \
index d287f3c99ae298ae4c265ea28bd861baa7e722b4..2102e9bc49529bdc5dfadef425d3dac7c6029080 100644 (file)
@@ -31,7 +31,7 @@ static bool fstrwrite(const char* str, FILE* stream)
        return true;
 }
 
-static const char* itoa(int value)
+static const char* __itoa(int value)
 {
        static char buffer[sizeof(int) * 8 + 1];        // not thread safe
 
@@ -73,10 +73,10 @@ bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE* stream)
                if(!fstrwrite("\t\t\t\"name\": \"", stream) || !fstrwrite(((node_t*)nodes[i])->name, stream) || !fstrwrite("\",\n", stream))
                        goto fail;
 
-               if(!fstrwrite("\t\t\t\"options\": ", stream) || !fstrwrite(itoa(((node_t*)nodes[i])->options), stream) || !fstrwrite(",\n", stream))
+               if(!fstrwrite("\t\t\t\"options\": ", stream) || !fstrwrite(__itoa(((node_t*)nodes[i])->options), stream) || !fstrwrite(",\n", stream))
                        goto fail;
 
-               if(!fstrwrite("\t\t\t\"devclass\": ", stream) || !fstrwrite(itoa(((node_t*)nodes[i])->devclass), stream) || !fstrwrite("\n", stream))
+               if(!fstrwrite("\t\t\t\"devclass\": ", stream) || !fstrwrite(__itoa(((node_t*)nodes[i])->devclass), stream) || !fstrwrite("\n", stream))
                        goto fail;
 
                if(!fstrwrite((i+1) != node_count ? "\t\t},\n" : "\t\t}\n", stream))
@@ -120,10 +120,10 @@ bool devtool_export_json_all_edges_state(meshlink_handle_t *mesh, FILE* stream)
 
                free(address);
 
-               if(!fstrwrite("\t\t\t\"options\": ", stream) || !fstrwrite(itoa(edges[i]->options), stream) || !fstrwrite(",\n", stream))
+               if(!fstrwrite("\t\t\t\"options\": ", stream) || !fstrwrite(__itoa(edges[i]->options), stream) || !fstrwrite(",\n", stream))
                        goto fail;
 
-               if(!fstrwrite("\t\t\t\"weight\": ", stream) || !fstrwrite(itoa(edges[i]->weight), stream) || !fstrwrite("\n", stream))
+               if(!fstrwrite("\t\t\t\"weight\": ", stream) || !fstrwrite(__itoa(edges[i]->weight), stream) || !fstrwrite("\n", stream))
                        goto fail;
 
                if(!fstrwrite((i+1) != edge_count ? "\t\t},\n" : "\t\t}\n", stream))
index 08ed9aea7ecaeb1a1baaafc42ca7e17af235c504..b6ed37c5ab8a1040fc616b72501181455661289b 100644 (file)
@@ -1,11 +1,3 @@
-
-#include "meshlink_internal.h"
-#include "discovery.h"
-#include "sockaddr.h"
-#include "logger.h"
-
-#include <pthread.h>
-
 #include <catta/core.h>
 #include <catta/lookup.h>
 #include <catta/publish.h>
@@ -15,6 +7,13 @@
 #include <catta/alternative.h>
 #include <catta/error.h>
 
+#include "meshlink_internal.h"
+#include "discovery.h"
+#include "sockaddr.h"
+#include "logger.h"
+
+#include <pthread.h>
+
 #include <netinet/in.h>
 
 #define MESHLINK_MDNS_SERVICE_TYPE "_%s._tcp"
@@ -214,7 +213,7 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat
     pthread_mutex_unlock(&(mesh->mesh_mutex));
 }
 
-static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfIndex interface, CattaProtocol protocol, CattaResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const CattaAddress *address, uint16_t port, CattaStringList *txt, CattaLookupResultFlags flags, void* userdata)
+static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfIndex interface_, CattaProtocol protocol, CattaResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const CattaAddress *address, uint16_t port, CattaStringList *txt, CattaLookupResultFlags flags, void *userdata)
 {
     meshlink_handle_t *mesh = userdata;
 
@@ -350,7 +349,7 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI
     pthread_mutex_unlock(&(mesh->mesh_mutex));
 }
 
-static void discovery_browse_callback(CattaSServiceBrowser *browser, CattaIfIndex interface, CattaProtocol protocol, CattaBrowserEvent event, const char *name, const char *type, const char *domain, CattaLookupResultFlags flags, void* userdata)
+static void discovery_browse_callback(CattaSServiceBrowser *browser, CattaIfIndex interface_, CattaProtocol protocol, CattaBrowserEvent event, const char *name, const char *type, const char *domain, CattaLookupResultFlags flags, void* userdata)
 {
        meshlink_handle_t *mesh = userdata;
 
@@ -383,7 +382,7 @@ static void discovery_browse_callback(CattaSServiceBrowser *browser, CattaIfInde
                    function we free it. Ifthe server is terminated before
                    the callback function is called the server will free
                    the resolver for us. */
-                if(!(catta_s_service_resolver_new(mesh->catta_server, interface, protocol, name, type, domain, CATTA_PROTO_UNSPEC, 0, discovery_resolve_callback, mesh)))
+                if(!(catta_s_service_resolver_new(mesh->catta_server, interface_, protocol, name, type, domain, CATTA_PROTO_UNSPEC, 0, discovery_resolve_callback, mesh)))
                 {
                     logger(mesh, MESHLINK_DEBUG, "Failed to resolve service '%s': %s\n", name, catta_strerror(catta_server_errno(mesh->catta_server)));
                 }
index 53559f80368bcf6606c3e440a917399e57fbf40e..0b664e178c395262840598cc9e5906fc102a8a18 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "splay_tree.h"
 #include "system.h"
+#include <pthread.h>
 
 #define IO_READ 1
 #define IO_WRITE 2
index 8400b936bd4f08d18ed8c5fe44a31e053098ed1c..faa29dcf9801afa3974e16bae2d3bc5c770ecaac 100644 (file)
--- a/src/net.c
+++ b/src/net.c
 
 #include <assert.h>
 
+#if !defined(min)
 static const int min(int a, int b) {
        return a < b ? a : b;
 }
+#endif
 
 /*
   Terminate a connection:
index d5786e5bc24c15be129f0abe508326ca90b0459a..55e7d31540a9188a5d4df13f73bcbde19d2cd121 100644 (file)
 #define SOL_TCP IPPROTO_TCP
 #endif
 
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
 int addressfamily = AF_UNSPEC;
 int seconds_till_retry = 5;
 int max_connection_burst = 100;