From f58b2d3d21b197e06ec99d1cbb85bfa4f3a2ce26 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 12 Nov 2014 12:53:30 +0100 Subject: [PATCH] api: fixes for windows (to finish) --- api.c | 39 +++++++++++++++++++++++++-------------- ccminer.vcxproj | 4 +++- ccminer.vcxproj.filters | 4 ++-- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/api.c b/api.c index 6f4f02e..190c3b6 100644 --- a/api.c +++ b/api.c @@ -10,6 +10,12 @@ */ #define APIVERSION "1.0" +#ifdef _MSC_VER +# define _WINSOCK_DEPRECATED_NO_WARNINGS +# include +# include +#endif + #include #include #include @@ -29,7 +35,7 @@ #include "compat.h" #include "miner.h" -#ifndef WIN32 +#ifndef _MSC_VER # include # include # include @@ -43,12 +49,12 @@ # define SOCKETINIT {} # define SOCKERRMSG strerror(errno) #else -# include # define SOCKETTYPE SOCKET # define SOCKETFAIL(a) ((a) == SOCKET_ERROR) # define INVSOCK INVALID_SOCKET # define INVINETADDR INADDR_NONE # define CLOSESOCKET closesocket +#define in_addr_t uint32_t #endif #define GROUP(g) (toupper(g)) @@ -125,7 +131,9 @@ static void gpustatus(int thr_id) } else #endif - gt = gf = gp = 0; + { + gt = 0.0; gf = gp = 0; + } // todo: can be 0 if set by algo (auto) if (opt_intensity == 0 && opt_work_size) { @@ -186,7 +194,7 @@ struct CMDS { #define CMDMAX 2 -static void send_result(int c, char *result) +static void send_result(SOCKETTYPE c, char *result) { int n; @@ -194,7 +202,7 @@ static void send_result(int c, char *result) result = ""; // ignore failure - it's closed immediately anyway - n = write(c, result, strlen(result)+1); + n = send(c, result, strlen(result) + 1, 0); } /* @@ -211,7 +219,7 @@ static void setup_ipaccess() int ipcount, mask, octet, i; char group; - buf = malloc(strlen(opt_api_allow) + 1); + buf = (char*) calloc(1, strlen(opt_api_allow) + 1); if (unlikely(!buf)) proper_exit(1);//, "Failed to malloc ipaccess buf"); @@ -223,7 +231,11 @@ static void setup_ipaccess() ipcount++; // possibly more than needed, but never less + #ifdef _MSC_VER + ipaccess = (IP4ACCESS *) calloc(ipcount, sizeof(struct IP4ACCESS)); + #else ipaccess = calloc(ipcount, sizeof(struct IP4ACCESS)); + #endif if (unlikely(!ipaccess)) proper_exit(1);//, "Failed to calloc ipaccess"); @@ -354,7 +366,7 @@ static void api() } } - apisock = calloc(1, sizeof(*apisock)); + apisock = (SOCKETTYPE*) calloc(1, sizeof(*apisock)); *apisock = INVSOCK; sleep(1); @@ -420,7 +432,7 @@ static void api() return; } - buffer = malloc(MYBUFSIZ+1); + buffer = (char *) calloc(1, MYBUFSIZ + 1); counter = 0; while (bye == 0) { @@ -441,10 +453,9 @@ static void api() connectaddr, addrok ? "Accepted" : "Ignored"); if (addrok) { - n = read(c, &buf[0], BUFSIZ-1); - if (n < 0) - close(c); - else { + n = recv(c, &buf[0], BUFSIZ - 1, 0); + // applog(LOG_DEBUG, "API: recv command: (%d) '%s'", n, buf); + if (!SOCKETFAIL(n)) { buf[n] = '\0'; params = strchr(buf, '|'); if (params != NULL) @@ -454,7 +465,7 @@ static void api() if (strcmp(buf, cmds[i].name) == 0) { result = (cmds[i].func)(params); send_result(c, result); - close(c); + CLOSESOCKET(c); break; } } @@ -476,4 +487,4 @@ void *api_thread(void *userdata) tq_freeze(mythr->q); return NULL; -} \ No newline at end of file +} diff --git a/ccminer.vcxproj b/ccminer.vcxproj index 5e5190d..9d5603b 100644 --- a/ccminer.vcxproj +++ b/ccminer.vcxproj @@ -240,7 +240,9 @@ - + + /Tp %(AdditionalOptions) + diff --git a/ccminer.vcxproj.filters b/ccminer.vcxproj.filters index caac514..6d1ff7c 100644 --- a/ccminer.vcxproj.filters +++ b/ccminer.vcxproj.filters @@ -192,7 +192,7 @@ Source Files - + Source Files @@ -482,4 +482,4 @@ Source Files\CUDA\x11 - + \ No newline at end of file