{
UDPC_INTERNAL_PacketInfo *pinfo = UDPC_Deque_index_ptr(
ctx->receivedPackets, sizeof(UDPC_INTERNAL_PacketInfo), x);
- ctx->callbackReceived(ctx->callbackReceivedUserData, pinfo->data, pinfo->size);
+ ctx->callbackReceived(
+ ctx->callbackReceivedUserData,
+ pinfo->addr,
+ pinfo->data,
+ pinfo->size);
free(pinfo->data);
}
UDPC_Deque_clear(ctx->receivedPackets);
*/
typedef void (*UDPC_callback_disconnected)(void*, uint32_t);
-/// (void *userData, char *packetData, uint32_t packetSize)
+/// (void *userData, uint32_t address, char *packetData, uint32_t packetSize)
/*!
* The data pointed to by the packetData argument is to data internally managed
* by the UDPC_Context. It will change every time this callback is called so do
* not depend on it persisting. This means you should copy the data out of it
* when the callback is invoked and work with the copied data.
*/
-typedef void (*UDPC_callback_received)(void*, char*, uint32_t);
+typedef void (*UDPC_callback_received)(void*, uint32_t, char*, uint32_t);
/// This struct should not be used outside of this library
typedef struct {
{
int isConnected;
int hasConnectedOnce;
+ uint32_t addr;
} TestContext;
void printUsage()
TestContext *ctx = userdata;
ctx->isConnected = 1;
ctx->hasConnectedOnce = 1;
+ ctx->addr = addr;
printf("Connected callback called\n");
}
printf("Disconnected callback called\n");
}
-void recCallback(void *userdata, char *data, uint32_t size)
+void recCallback(void *userdata, uint32_t addr, char *data, uint32_t size)
{
+ TestContext *ctx = userdata;
+ if(ctx->addr == addr && size == 7 && data[6] == '\0')
+ {
+ printf("Got %s\n", data);
+ }
+}
+
+void updateSendBuffer(uint32_t *index, char *buffer)
+{
+ ++(*index);
+ if(*index >= 26 * 26 * 26 * 26 * 26 * 26)
+ {
+ *index = 0;
+ }
+
+ uint32_t temp;
+ for(int x = 0; x < 6; ++x)
+ {
+ temp = 1;
+ for(int y = 0; y < x; ++y)
+ {
+ temp *= 26;
+ }
+ buffer[x] = (*index / temp) % 26 + 'a';
+ }
}
int main(int argc, char** argv)
uint16_t listenPort = 0;
TestContext testCtx = {0, 0};
+ uint32_t sendIndex = 0;
+ char sendBuffer[7] = {
+ 'a', 'a', 'a',
+ 'a', 'a', 'a',
+ '\0'
+ };
+
--argc; ++argv;
while(argc > 0)
{
UDPC_set_logging_type(ctx, 4);
UDPC_set_callback_connected(ctx, conCallback, &testCtx);
UDPC_set_callback_disconnected(ctx, discCallback, &testCtx);
- UDPC_set_callback_received(ctx, recCallback, NULL);
+ UDPC_set_callback_received(ctx, recCallback, &testCtx);
while(UDPC_get_error(ctx) == UDPC_SUCCESS)
{
if(isClient && testCtx.isConnected == 0)
}
if(isThreaded == 0) { UDPC_update(ctx); }
UDPC_check_events(ctx);
+ if(testCtx.isConnected != 0 && UDPC_get_queue_send_available(ctx, testCtx.addr) > 0)
+ {
+ UDPC_queue_send(ctx, testCtx.addr, 0, sendBuffer, 7);
+ updateSendBuffer(&sendIndex, sendBuffer);
+ }
thrd_sleep(&(struct timespec){0, 16666666}, NULL);
if(testCtx.hasConnectedOnce != 0 && testCtx.isConnected == 0)
{