Files
@ 27eb6c6418f6
Branch filter:
Location: DistRen/src/server/tabletennis.h - annotation
27eb6c6418f6
2.9 KiB
text/plain
Handle resolving hostnames gracefully.
Fix support for hostname:port in remoteio.
Added timeout parameter to multiio_poll().
Fix stupid mistakes in distrenslave's read handler.
The server and client may not sit and play table tennis at last :-D.
Fix support for hostname:port in remoteio.
Added timeout parameter to multiio_poll().
Fix stupid mistakes in distrenslave's read handler.
The server and client may not sit and play table tennis at last :-D.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 eb391af42d62 | /*
* Copyright 2010 Nathan Phillip Brink
*
* This file is a part of DistRen.
*
* DistRen is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DistRen 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with DistRen. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DISTREN_TABLETENNIS_H
#define _DISTREN_TABLETENNIS_H
/**
* @file For managing the PINGs and PONGs of our present life.
*
* Do not call ping pong ping pong! Any professional ping-ponger will
* be immediately offended. Use tabletennis instead and prosper.
*/
#include "distrend.h"
#include <queue.h>
#include <time.h>
struct tabletennis;
typedef struct tabletennis *tabletennis_t;
/**
* this struct should be embedded into struct distrend_client
*/
struct tabletennis_client
{
/*
* the time that the client should be processed from the
* clients_to_ping or clients_need_pong queues.
*/
time_t time_next_check;
enum tabletennis_client_state
{
/* in clients_to_ping */
TABLETENNIS_NEED_PING,
/* in clients_need_pong */
TABLETENNIS_NEED_PONG,
TABLETENNIS_HAS_PONG,
/* not in any queue */
TABLETENNIS_DELINQUENT,
} state;
};
/**
* Initializes the context data for tabletennis.
*
* @param listens to register tabletennis's PING and PONG handlers
* @param ping_interval The number of seconds to wait before sending a client a PING packet.
* @param pong_time The number of seconds to wait before checking if a client sent a PONG packet.
*/
tabletennis_t tabletennis_new(struct distrend_listens *listens, unsigned int ping_interval, unsigned int pong_time);
/**
* Add a client to the tabletennis game.
*
* @param tabletennis the tabletennis context.
* @param client the client
*/
int tabletennis_add_client(tabletennis_t tabletennis, struct distrend_client *client);
/**
* Sends PING packets to clients that need them and checks that
* clients have sent PONG packets on time.
*
* @param clients_to_ping a queue initialized
*/
int tabletennis_serve(tabletennis_t tabletennis);
/**
* Remove a client to the tabletennis game.
*
* @param tabletennis the tabletennis context.
* @param client the client
*/
int tabletennis_del_client(tabletennis_t tabletennis, struct distrend_client *client);
/**
* Deallocates and frees the tabletennis context data.
*
* Does not free the distren_client structs
*
* @param tabletennis the tabletennis context.
*/
void tabletennis_free(tabletennis_t tabletennis);
#endif
|