#include #include "mutex.h" #include "thread.h" #include "socket.h" #include "esc.h" /* unsigned long my_first_thread(void* arg) { mutex_t mut = arg; mutex_lock(mut); printf("1\n"); mutex_unlock(mut); return 0; } unsigned long my_second_thread(void* arg) { mutex_t mut = arg; mutex_lock(mut); printf("2\n"); mutex_unlock(mut); return 0; } */ 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 = esc_connection_read_all_forward(conn, 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\n", esc_uuid_format(result->events[i]->event->event_id, uuid_buf, 37)); } /* socket_t s = socket_create(IPPROTO_TCP); socket_connect(s, "www.google.ca", 80); char* req = "GET / HTTP/1.1\r\nHost: www.google.ca\r\nConnection: close\r\n\r\n"; socket_send(s, req, strlen(req)); char buffer[4096]; memset(buffer, 0, 4096); int rc; while ((rc = socket_recv(s, buffer, 4096)) > 0) { printf_s("%s", buffer); memset(buffer, 0, 4096); } socket_close(s); mutex_t sync = mutex_create(); thread_t one = thread_create(my_first_thread, sync); thread_t two = thread_create(my_second_thread, sync); thread_start(one); thread_start(two); printf("Hello, World!\n"); thread_destroy(one); thread_destroy(two); mutex_destroy(sync); */ #ifdef _WIN32 WSACleanup(); #endif return 0; }