95 lines
2.1 KiB
C
95 lines
2.1 KiB
C
#pragma once
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#if defined(_WIN32)
|
|
#if defined(CO_GNS_BRIDGE_BUILD)
|
|
#define CO_GNS_API __declspec(dllexport)
|
|
#else
|
|
#define CO_GNS_API __declspec(dllimport)
|
|
#endif
|
|
#else
|
|
#define CO_GNS_API __attribute__((visibility("default")))
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef void* co_gns_server_handle;
|
|
|
|
enum co_gns_event_type
|
|
{
|
|
CO_GNS_EVENT_NONE = 0,
|
|
CO_GNS_EVENT_CONNECTED = 1,
|
|
CO_GNS_EVENT_DISCONNECTED = 2,
|
|
CO_GNS_EVENT_MESSAGE = 3,
|
|
CO_GNS_EVENT_OVERSIZE_MESSAGE = 4
|
|
};
|
|
|
|
enum co_gns_delivery
|
|
{
|
|
CO_GNS_DELIVERY_UNRELIABLE_SEQUENCED = 0,
|
|
CO_GNS_DELIVERY_RELIABLE_ORDERED = 1
|
|
};
|
|
|
|
enum co_gns_send_result
|
|
{
|
|
CO_GNS_SEND_ERROR = -1,
|
|
CO_GNS_SEND_SENT = 0,
|
|
CO_GNS_SEND_DROPPED = 1,
|
|
CO_GNS_SEND_BACKPRESSURE = 2,
|
|
CO_GNS_SEND_NOT_CONNECTED = 3,
|
|
CO_GNS_SEND_TOO_LARGE = 4
|
|
};
|
|
|
|
typedef struct co_gns_event
|
|
{
|
|
uint32_t type;
|
|
uint32_t connection_id;
|
|
int32_t reason;
|
|
uint32_t payload_size;
|
|
char debug[128];
|
|
} co_gns_event;
|
|
|
|
CO_GNS_API int co_gns_server_create(
|
|
const char* bind_host,
|
|
uint16_t port,
|
|
co_gns_server_handle* out_handle,
|
|
char* error_buffer,
|
|
size_t error_buffer_size);
|
|
|
|
CO_GNS_API void co_gns_server_destroy(co_gns_server_handle handle);
|
|
CO_GNS_API uint16_t co_gns_server_local_port(co_gns_server_handle handle);
|
|
CO_GNS_API uint32_t co_gns_server_connection_count(co_gns_server_handle handle);
|
|
|
|
CO_GNS_API int co_gns_server_poll(
|
|
co_gns_server_handle handle,
|
|
co_gns_event* out_event,
|
|
void* payload_buffer,
|
|
uint32_t payload_capacity);
|
|
|
|
CO_GNS_API int co_gns_server_send(
|
|
co_gns_server_handle handle,
|
|
uint32_t connection_id,
|
|
const void* payload,
|
|
uint32_t payload_size,
|
|
uint32_t delivery);
|
|
|
|
CO_GNS_API int co_gns_server_disconnect(
|
|
co_gns_server_handle handle,
|
|
uint32_t connection_id,
|
|
int32_t reason,
|
|
const char* debug);
|
|
|
|
CO_GNS_API int co_gns_server_remote_ipv4(
|
|
co_gns_server_handle handle,
|
|
uint32_t connection_id,
|
|
uint32_t* out_ipv4_host_order,
|
|
uint16_t* out_port);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|