Fixed TLS build on Windows GCC/MVSC

Cleanup TLS compile
This commit is contained in:
BenDr0id 2018-03-01 17:44:15 +01:00
parent bc110ef162
commit 972f542901
13 changed files with 66 additions and 51 deletions

View file

@ -10,6 +10,11 @@
#include <sys/types.h>
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
/*
* Default buffer size.
*/

View file

@ -26,37 +26,22 @@ typedef struct net_s net_t;
typedef struct addrinfo net_ai;
typedef struct sockaddr_in socketPair_t;
#define NET_FIELDS \
NET_CONNECTION_FIELDS \
NET_UV_FIELDS \
NET_TLS_FIELDS \
#define NET_CONNECTION_FIELDS \
char *hostname; \
int port; \
int connected; \
#define NET_UV_FIELDS \
uv_getaddrinfo_t *resolver; \
uv_loop_t *loop; \
uv_tcp_t *handle; \
uv_connect_t *conn; \
#ifndef XMRIG_NO_TLS
#define NET_TLS_FIELDS \
int use_ssl; \
int tls_established; \
tls_t *tls;
#else
#define NET_TLS_FIELDS \
int use_ssl; \
int tls_established;
#endif
struct net_s {
NET_FIELDS;
char *hostname;
int port;
int connected;
uv_getaddrinfo_t *resolver;
uv_loop_t *loop;
uv_tcp_t *handle;
uv_connect_t *conn;
int use_ssl;
int tls_established;
#ifndef XMRIG_NO_TLS
tls_t *tls;
#endif
void *data;
void (*conn_cb)(net_t*);
void (*read_cb)(net_t*, size_t, char*);

View file

@ -213,14 +213,15 @@ net_connect_cb(uv_connect_t *conn, int err) {
do {
read = tls_bio_read(net->tls, 0);
if (read > 0) {
char buf[read];
char* buf = (char *) calloc(read, 1);
uv_write_t * req = malloc(sizeof(uv_write_t));
req->data = net;
memset(buf, 0, read);
memcpy(buf, net->tls->buf, read);
uv_buf_t uvbuf = uv_buf_init(buf, read);
uv_write(req, (uv_stream_t*)net->handle, &uvbuf, 1, net_write_cb);
}
free(buf);
}
} while (read > 0);
}
#endif
@ -267,13 +268,14 @@ net_read(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
do {
read = tls_bio_read(net->tls, 0);
if (read > 0) {
char buf2[read];
char* buf2 = (char *) calloc(read, 1);
uv_write_t * req = malloc(sizeof(uv_write_t));
req->data = net;
memset(buf2, 0, read);
memcpy(buf2, net->tls->buf, read);
uv_buf_t uvbuf = uv_buf_init(buf2, read);
uv_write(req, (uv_stream_t*)net->handle, &uvbuf, 1, net_write_cb);
free(buf2);
}
} while (read > 0);