45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
#include <stdio.h>
|
|
|
|
#include "mutex.h"
|
|
#include "esc.h"
|
|
|
|
int main() {
|
|
#ifdef _WIN32
|
|
WSADATA wsaData;
|
|
WSAStartup(MAKEWORD(2,0), &wsaData);
|
|
#endif
|
|
|
|
const esc_connection_t* conn = esc_connection_create(esc_default_connection_settings, "tcp://127.0.0.1:1113", NULL);
|
|
if (conn == 0) {
|
|
return -1;
|
|
}
|
|
if (esc_connection_connect(conn) != 0) {
|
|
return -2;
|
|
}
|
|
const esc_credentials_t* credentials = esc_credentials_create("admin", "changeit");
|
|
|
|
const esc_all_events_slice_t *result = 0;
|
|
do {
|
|
result = esc_connection_read_all_forward(conn, result ? &result->next_position : NULL, 1024, credentials);
|
|
if (result == 0) {
|
|
return -3;
|
|
}
|
|
char posbuf1[44];
|
|
char posbuf2[44];
|
|
printf("%s %s %s %u\n", result->read_direction,
|
|
esc_position_format(&result->from_position, posbuf1, 44),
|
|
esc_position_format(&result->next_position, posbuf2, 44),
|
|
result->is_end_of_stream);
|
|
char uuid_buf[37];
|
|
for (size_t i = 0; i < result->n_events; i++) {
|
|
printf("%s %s\n", esc_uuid_format(result->events[i]->event->event_id, uuid_buf, 37),
|
|
result->events[i]->event->event_type);
|
|
}
|
|
} while(result->is_end_of_stream == 0);
|
|
|
|
#ifdef _WIN32
|
|
WSACleanup();
|
|
#endif
|
|
return 0;
|
|
}
|