Skip to content
Snippets Groups Projects
dap_udp_client.h 2.46 KiB
Newer Older
armatusmiles's avatar
armatusmiles committed
/*
 Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc
  All rights reserved.

 This file is part of DAP (Deus Applications Prototypes) the open source project

    DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DAP is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with any DAP based project.  If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
anta999's avatar
anta999 committed

#ifndef WIN32
armatusmiles's avatar
armatusmiles committed
#include <sys/queue.h>
anta999's avatar
anta999 committed
#endif

armatusmiles's avatar
armatusmiles committed
#include "uthash.h"

anta999's avatar
anta999 committed
#include "dap_client_remote.h"
armatusmiles's avatar
armatusmiles committed

typedef struct dap_udp_server dap_udp_server_t;
struct dap_udp_client;

anta999's avatar
anta999 committed
#define UDP_CLIENT_BUF 65535
armatusmiles's avatar
armatusmiles committed

anta999's avatar
anta999 committed
typedef struct dap_udp_client {

    dap_client_remote_t *client;
armatusmiles's avatar
armatusmiles committed
    uint64_t host_key; //key contains host address in first 4 bytes and port in last 4 bytes

    UT_hash_handle hh;
anta999's avatar
anta999 committed

armatusmiles's avatar
armatusmiles committed
    struct dap_udp_client *next, *prev;   //pointers for writing queue
    pthread_mutex_t mutex_on_client;

anta999's avatar
anta999 committed
    void *_inheritor; // Internal data to specific client type, usualy states for state machine

armatusmiles's avatar
armatusmiles committed
} dap_udp_client_t; // Node of bidirectional list of clients

#define DAP_UDP_CLIENT(a) ((dap_udp_client_t *) (a)->_inheritor)

anta999's avatar
anta999 committed
dap_client_remote_t *dap_udp_client_create( dap_server_t *sh, EPOLL_HANDLE efd, unsigned long host, unsigned short port ); // Create new client and add it to the list
dap_client_remote_t *dap_udp_client_find( dap_server_t *sh, unsigned long host, unsigned short port ); // Find client by host and port
armatusmiles's avatar
armatusmiles committed

anta999's avatar
anta999 committed
void dap_udp_client_ready_to_read( dap_client_remote_t *sc, bool is_ready );
void dap_udp_client_ready_to_write( dap_client_remote_t *sc, bool is_ready );
armatusmiles's avatar
armatusmiles committed

anta999's avatar
anta999 committed
size_t dap_udp_client_write( dap_client_remote_t *sc, const void * data, size_t data_size );
size_t dap_udp_client_write_f( dap_client_remote_t *a_client, const char * a_format, ... );
armatusmiles's avatar
armatusmiles committed

anta999's avatar
anta999 committed
void add_waiting_client( dap_client_remote_t *client ); // Add client to writing queue
armatusmiles's avatar
armatusmiles committed

anta999's avatar
anta999 committed
void dap_udp_client_get_address( dap_client_remote_t *client, unsigned int *host, unsigned short *port );