windows fixes
This commit is contained in:
30
src/esc.c
30
src/esc.c
@@ -8,7 +8,6 @@
|
||||
#include <stdarg.h>
|
||||
#include "esc.h"
|
||||
#include "utils/socket.h"
|
||||
#include "utils/buffer.h"
|
||||
#include "proto.h"
|
||||
#include "tcp_package.h"
|
||||
#include "utils/thread.h"
|
||||
@@ -18,6 +17,7 @@
|
||||
#include "tcp_messages.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define usleep Sleep
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
@@ -96,7 +96,11 @@ const node_endpoints_t* static_discover(const static_endpoint_discoverer_t* disc
|
||||
//TODO partial transfer
|
||||
ssize_t connection_send_tcp_package(esc_connection_t conn, tcp_package_t pkg) {
|
||||
char uuid_buf[37];
|
||||
fprintf(stderr, "connection_send_tcp_package: %u %u %s %lu ", pkg->command, pkg->flags, esc_uuid_format(pkg->correlation_id, uuid_buf, 37), buffer_size(pkg->data));
|
||||
#ifdef _WIN32
|
||||
fprintf(stderr, "connection_send_tcp_package: %s %u %s %llu ", get_string_for_tcp_message(pkg->command), pkg->flags, esc_uuid_format(pkg->correlation_id, uuid_buf, 37), buffer_size(pkg->data));
|
||||
#else
|
||||
fprintf(stderr, "connection_send_tcp_package: %s %u %s %lu ", get_string_for_tcp_message(pkg->command), pkg->flags, esc_uuid_format(pkg->correlation_id, uuid_buf, 37), buffer_size(pkg->data));
|
||||
#endif
|
||||
buffer_t send_buffer = tcp_package_to_buffer(pkg);
|
||||
|
||||
size_t send_buffer_size = buffer_size(send_buffer);
|
||||
@@ -125,7 +129,11 @@ tcp_package_t connection_recv_tcp_package(esc_connection_t conn) {
|
||||
uint32_t recv_size;
|
||||
ssize_t rc;
|
||||
if ((rc = socket_recv(conn->tcp_conn, (char *)&recv_size, sizeof(uint32_t))) != 4) {
|
||||
#ifdef _WIN32
|
||||
fprintf(stderr, "connection_recv_tcp_package: %lld %d\n", rc, socket_error(conn->tcp_conn));
|
||||
#else
|
||||
fprintf(stderr, "connection_recv_tcp_package: %ld %d\n", rc, socket_error(conn->tcp_conn));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
buffer_t recv_buffer = buffer_create(recv_size);
|
||||
@@ -139,7 +147,11 @@ tcp_package_t connection_recv_tcp_package(esc_connection_t conn) {
|
||||
tcp_package_t recv_pkg = tcp_package_from_buffer(recv_buffer);
|
||||
buffer_destroy(recv_buffer);
|
||||
char uuid_buf[37];
|
||||
fprintf(stderr, "connection_recv_tcp_package: %u %u %s %lu\n", recv_pkg->command, recv_pkg->flags, esc_uuid_format(recv_pkg->correlation_id, uuid_buf, 37), recv_buffer_size);
|
||||
#ifdef _WIN32
|
||||
fprintf(stderr, "connection_recv_tcp_package: %s %u %s %llu\n", get_string_for_tcp_message(recv_pkg->command), recv_pkg->flags, esc_uuid_format(recv_pkg->correlation_id, uuid_buf, 37), buffer_size(recv_pkg->data));
|
||||
#else
|
||||
fprintf(stderr, "connection_recv_tcp_package: %s %u %s %lu\n", get_string_for_tcp_message(recv_pkg->command), recv_pkg->flags, esc_uuid_format(recv_pkg->correlation_id, uuid_buf, 37), buffer_size(recv_pkg->data));
|
||||
#endif
|
||||
return recv_pkg;
|
||||
}
|
||||
|
||||
@@ -274,8 +286,8 @@ int esc_connection_connect(esc_connection_t conn) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const esc_credentials_t* esc_credentials_create(const char* username, const char* password) {
|
||||
esc_credentials_t* creds = malloc(sizeof(struct st_credentials));
|
||||
esc_credentials_t esc_credentials_create(const char* username, const char* password) {
|
||||
esc_credentials_t creds = malloc(sizeof(struct st_credentials));
|
||||
creds->username = username;
|
||||
creds->password = password;
|
||||
return creds;
|
||||
@@ -304,7 +316,7 @@ esc_resolved_event_t* resolved_event_create(EventStore__Client__Messages__Resolv
|
||||
return ev;
|
||||
}
|
||||
|
||||
const esc_all_events_slice_t* esc_connection_read_all_forward(esc_connection_t conn, const esc_position_t* last_checkpoint, unsigned int count, const esc_credentials_t* credentials) {
|
||||
esc_all_events_slice_t esc_connection_read_all_forward(esc_connection_t conn, const esc_position_t* last_checkpoint, unsigned int count, esc_credentials_t credentials) {
|
||||
EventStore__Client__Messages__ReadAllEvents send_msg;
|
||||
event_store__client__messages__read_all_events__init(&send_msg);
|
||||
send_msg.prepare_position = last_checkpoint ? last_checkpoint->prepare_position : 0;
|
||||
@@ -329,7 +341,7 @@ const esc_all_events_slice_t* esc_connection_read_all_forward(esc_connection_t c
|
||||
EventStore__Client__Messages__ReadAllEventsCompleted *recv_msg =
|
||||
event_store__client__messages__read_all_events_completed__unpack(&conn->protobuf_c_allocator, data_size, data);
|
||||
|
||||
esc_all_events_slice_t* result = malloc(sizeof(struct st_all_events_slice));
|
||||
esc_all_events_slice_t result = malloc(sizeof(struct st_all_events_slice));
|
||||
result->read_direction = "forward";
|
||||
result->is_end_of_stream = (recv_msg->events == 0 || recv_msg->n_events == 0) ? 1 : 0;
|
||||
result->from_position.prepare_position = recv_msg->prepare_position;
|
||||
@@ -351,6 +363,10 @@ void esc_connection_close(esc_connection_t conn) {
|
||||
}
|
||||
|
||||
const char* esc_position_format(const esc_position_t* position, char* buffer, size_t buf_size) {
|
||||
#ifdef _WIN32
|
||||
snprintf(buffer, buf_size, "%llu/%llu", position->prepare_position, position->commit_position);
|
||||
#else
|
||||
snprintf(buffer, buf_size, "%lu/%lu", position->prepare_position, position->commit_position);
|
||||
#endif
|
||||
return buffer;
|
||||
}
|
||||
|
Reference in New Issue
Block a user