Browse Source

api: fixes for windows (to finish)

master
Tanguy Pruvot 10 years ago
parent
commit
f58b2d3d21
  1. 37
      api.c
  2. 4
      ccminer.vcxproj
  3. 2
      ccminer.vcxproj.filters

37
api.c

@ -10,6 +10,12 @@
*/ */
#define APIVERSION "1.0" #define APIVERSION "1.0"
#ifdef _MSC_VER
# define _WINSOCK_DEPRECATED_NO_WARNINGS
# include <winsock2.h>
# include <mstcpip.h>
#endif
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
@ -29,7 +35,7 @@
#include "compat.h" #include "compat.h"
#include "miner.h" #include "miner.h"
#ifndef WIN32 #ifndef _MSC_VER
# include <errno.h> # include <errno.h>
# include <sys/socket.h> # include <sys/socket.h>
# include <netinet/in.h> # include <netinet/in.h>
@ -43,12 +49,12 @@
# define SOCKETINIT {} # define SOCKETINIT {}
# define SOCKERRMSG strerror(errno) # define SOCKERRMSG strerror(errno)
#else #else
# include <winsock2.h>
# define SOCKETTYPE SOCKET # define SOCKETTYPE SOCKET
# define SOCKETFAIL(a) ((a) == SOCKET_ERROR) # define SOCKETFAIL(a) ((a) == SOCKET_ERROR)
# define INVSOCK INVALID_SOCKET # define INVSOCK INVALID_SOCKET
# define INVINETADDR INADDR_NONE # define INVINETADDR INADDR_NONE
# define CLOSESOCKET closesocket # define CLOSESOCKET closesocket
#define in_addr_t uint32_t
#endif #endif
#define GROUP(g) (toupper(g)) #define GROUP(g) (toupper(g))
@ -125,7 +131,9 @@ static void gpustatus(int thr_id)
} }
else else
#endif #endif
gt = gf = gp = 0; {
gt = 0.0; gf = gp = 0;
}
// todo: can be 0 if set by algo (auto) // todo: can be 0 if set by algo (auto)
if (opt_intensity == 0 && opt_work_size) { if (opt_intensity == 0 && opt_work_size) {
@ -186,7 +194,7 @@ struct CMDS {
#define CMDMAX 2 #define CMDMAX 2
static void send_result(int c, char *result) static void send_result(SOCKETTYPE c, char *result)
{ {
int n; int n;
@ -194,7 +202,7 @@ static void send_result(int c, char *result)
result = ""; result = "";
// ignore failure - it's closed immediately anyway // 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; int ipcount, mask, octet, i;
char group; char group;
buf = malloc(strlen(opt_api_allow) + 1); buf = (char*) calloc(1, strlen(opt_api_allow) + 1);
if (unlikely(!buf)) if (unlikely(!buf))
proper_exit(1);//, "Failed to malloc ipaccess buf"); proper_exit(1);//, "Failed to malloc ipaccess buf");
@ -223,7 +231,11 @@ static void setup_ipaccess()
ipcount++; ipcount++;
// possibly more than needed, but never less // possibly more than needed, but never less
#ifdef _MSC_VER
ipaccess = (IP4ACCESS *) calloc(ipcount, sizeof(struct IP4ACCESS));
#else
ipaccess = calloc(ipcount, sizeof(struct IP4ACCESS)); ipaccess = calloc(ipcount, sizeof(struct IP4ACCESS));
#endif
if (unlikely(!ipaccess)) if (unlikely(!ipaccess))
proper_exit(1);//, "Failed to calloc 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; *apisock = INVSOCK;
sleep(1); sleep(1);
@ -420,7 +432,7 @@ static void api()
return; return;
} }
buffer = malloc(MYBUFSIZ+1); buffer = (char *) calloc(1, MYBUFSIZ + 1);
counter = 0; counter = 0;
while (bye == 0) { while (bye == 0) {
@ -441,10 +453,9 @@ static void api()
connectaddr, addrok ? "Accepted" : "Ignored"); connectaddr, addrok ? "Accepted" : "Ignored");
if (addrok) { if (addrok) {
n = read(c, &buf[0], BUFSIZ-1); n = recv(c, &buf[0], BUFSIZ - 1, 0);
if (n < 0) // applog(LOG_DEBUG, "API: recv command: (%d) '%s'", n, buf);
close(c); if (!SOCKETFAIL(n)) {
else {
buf[n] = '\0'; buf[n] = '\0';
params = strchr(buf, '|'); params = strchr(buf, '|');
if (params != NULL) if (params != NULL)
@ -454,7 +465,7 @@ static void api()
if (strcmp(buf, cmds[i].name) == 0) { if (strcmp(buf, cmds[i].name) == 0) {
result = (cmds[i].func)(params); result = (cmds[i].func)(params);
send_result(c, result); send_result(c, result);
close(c); CLOSESOCKET(c);
break; break;
} }
} }

4
ccminer.vcxproj

@ -240,7 +240,9 @@
<ClCompile Include="groestlcoin.cpp" /> <ClCompile Include="groestlcoin.cpp" />
<ClCompile Include="hashlog.cpp" /> <ClCompile Include="hashlog.cpp" />
<ClCompile Include="stats.cpp" /> <ClCompile Include="stats.cpp" />
<ClCompile Include="api.c" /> <ClCompile Include="api.c">
<AdditionalOptions>/Tp %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Include="hefty1.c" /> <ClCompile Include="hefty1.c" />
<ClCompile Include="myriadgroestl.cpp" /> <ClCompile Include="myriadgroestl.cpp" />
<ClCompile Include="scrypt.c"> <ClCompile Include="scrypt.c">

2
ccminer.vcxproj.filters

@ -192,7 +192,7 @@
<ClCompile Include="stats.cpp"> <ClCompile Include="stats.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="api.cpp"> <ClCompile Include="api.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save