3#ifndef __GS_UDP_ENGINE_H__
4#define __GS_UDP_ENGINE_H__
11#include "../gt2/gt2.h"
21#define GS_UDP_DEFAULT_OUT_BUFFSIZE 1460
22#define GS_UDP_DEFAULT_IN_BUFFSIZE 1500
25#define GS_IP_ADDR_AND_PORT 22
30#define GS_UDP_MSG_HEADER_LEN 16
31#define GS_UDP_RELIABLE_MSG_HEADER 7
35typedef enum _GSUdpErrorCode
42 GS_UDP_ADDRESS_ALREADY_IN_USE,
46 GS_UDP_INVALID_MESSAGE,
47 GS_UDP_PARAMETER_ERROR,
48 GS_UDP_NOT_INITIALIZED,
52 GS_UDP_NUM_ERROR_CODES
59typedef enum _GSUdpPeerState
61 GS_UDP_PEER_CONNECTING,
62 GS_UDP_PEER_CONNECTED,
71typedef enum _GSUdpCloseReason
73 GS_UDP_CLOSED_LOCALLY,
74 GS_UDP_CLOSED_REMOTELY,
76 GS_UDP_CLOSED_BY_COMM_ERROR,
77 GS_UDP_CLOSED_BY_LOW_MEM,
87typedef void (*gsUdpErrorCallback)(GSUdpErrorCode theCode,
void *theUserData);
91typedef void (*gsUdpAppConnectAttemptCallback)(
unsigned int theIp,
unsigned short thePort,
92 int theLatency,
unsigned char *theInitMsg,
93 unsigned int theInitMsgLen,
void *theUserData);
97typedef void (*gsUdpConnClosedCallback)(
unsigned int ip,
unsigned short port, GSUdpCloseReason reason,
99typedef void (*gsUdpConnReceivedDataCallback)(
unsigned int ip,
unsigned short port,
100 unsigned char *message,
unsigned int messageLength,
101 gsi_bool reliable,
void *theUserData);
102typedef void (*gsUdpConnConnectedCallback)(
unsigned int ip,
unsigned short port,
103 GSUdpErrorCode error, gsi_bool rejected,
105typedef void (*gsUdpConnPingCallback)(
unsigned int ip,
unsigned short port,
unsigned int latency,
110typedef gsi_bool (*gsUdpUnknownMsgCallback)(
unsigned int ip,
unsigned short port,
111 unsigned char *message,
unsigned int messageLength,
118gsi_bool gsUdpEngineIsInitialized();
119GSUdpErrorCode gsUdpEngineInitialize(
unsigned short thePort,
int theIncomingBufSize,
120 int theOutgoingBufSize, gsUdpErrorCallback theAppNetworkError,
121 gsUdpConnConnectedCallback theAppConnected,
122 gsUdpConnClosedCallback theAppClosed,
123 gsUdpConnPingCallback theAppPing,
124 gsUdpConnReceivedDataCallback theAppReceive,
125 gsUdpUnknownMsgCallback theAppUnownMsg,
126 gsUdpAppConnectAttemptCallback theAppConnectAttempt,
127 void *theAppUserData);
129GSUdpErrorCode gsUdpEngineThink();
130GSUdpErrorCode gsUdpEngineShutdown();
133GSUdpErrorCode gsUdpEngineGetPeerState(
unsigned int theIp,
unsigned short thePort,
134 GSUdpPeerState *thePeerState);
135GSUdpErrorCode gsUdpEngineStartTalkingToPeer(
unsigned int theIp,
unsigned short thePort,
136 char theInitMsg[GS_UDP_MSG_HEADER_LEN],
int timeOut);
137GSUdpErrorCode gsUdpEngineAcceptPeer(
unsigned int theIp,
unsigned short thePort);
138GSUdpErrorCode gsUdpEngineRejectPeer(
unsigned int theIp,
unsigned short thePort);
148GSUdpErrorCode gsUdpEngineSendMessage(
unsigned int theIp,
unsigned short thePort,
149 char theHeader[GS_UDP_MSG_HEADER_LEN],
unsigned char *theMsg,
150 unsigned int theMsgLen, gsi_bool theReliable);
154GSUdpErrorCode gsUdpEngineAddMsgHandler(
char theInitMsg[GS_UDP_MSG_HEADER_LEN],
155 char theHeader[GS_UDP_MSG_HEADER_LEN],
156 gsUdpErrorCallback theMsgHandlerError,
157 gsUdpConnConnectedCallback theMsgHandlerConnected,
158 gsUdpConnClosedCallback theMsgHandlerClosed,
159 gsUdpConnPingCallback theMsgHandlerPing,
160 gsUdpConnReceivedDataCallback theMsgHandlerRecv,
162GSUdpErrorCode gsUdpEngineRemoveMsgHandler(
char theHeader[GS_UDP_MSG_HEADER_LEN]);
166SOCKET gsUdpEngineGetSocket();
167void gsUdpEngineAddrToString(
unsigned int theIp,
unsigned short thePort,
168 char addrstring[GS_IP_ADDR_AND_PORT]);
169unsigned int gsUdpEngineGetLocalAddr();
170unsigned short gsUdpEngineGetLocalPort();
173gsi_bool gsUdpEngineNoMoreMsgHandlers();
174gsi_bool gsUdpEngineNoApp();
178int gsUdpEngineGetPeerOutBufferFreeSpace(
unsigned int theIp,
unsigned short thePort);