Files
@ c6a12058c9da
Branch filter:
Location: DistRen/src/server/listen.h
c6a12058c9da
3.1 KiB
text/plain
- Fix up the client making outbound connections. It can now send a sort of ping request but not handle responses yet.
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 | /*
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/>.
*/
struct distrend_clientset;
struct distrend_listen;
struct distrend_client;
#ifndef _DISTREN_LISTEN_H
#define _DISTREN_LISTEN_H
#include "distrend.h"
#include "common/protocol.h"
#include <queue.h>
enum distrend_client_state
{
DISTREND_CLIENT_PREAUTH,
DISTREND_CLIENT_GOODDOGGY,
DISTREND_CLIENT_BADBOY,
DISTREND_CLIENT_DEAD
};
struct distrend_listen
{
int port;
int sock;
};
struct distrend_client
{
int sock;
enum distrend_client_state state;
size_t inlen; /*< number of bytes waiting to be processed */
size_t expectlen; /*< number of bytes that inlen has to be for a complete request to be had, 0 when waiting on header */
QUEUE *inmsgs;
QUEUE *outmsgs;
};
typedef int(*distrend_handle_request_t)(struct distrend_client *client, struct distren_request *req, void *reqdata, void *data);
/**
initializes the listens and clientset
@param config the configuration from distrend
@param clients a pointer to a struct distrend_clientset pointer which will be set to memory allocated for the clientset
*/
int distrend_listen(struct distrend_config *config, struct distrend_clientset **clients);
/**
checks states of the sockets I'm managing. If there are any new connections,
or activity on any sockets, I'll call the appropriate function.
I will block until there is some sort of activity, including
signals. If you want to cleanly shut down, it's best to register
signal handlers somewhere
*/
int distrend_accept(struct distrend_config *config, struct distrend_clientset *clients, distrend_handle_request_t handlereq, void *handlereqdata);
/**
cleans listening socket. Unnecessary for a working server, currently a stub.
*/
int distrend_unlisten(struct distrend_listen *listens, struct distrend_clientset *clients);
/**
writes message to client.
@param towrite the caller is expected to free this string. This function will
strdup() it, in essence.
*/
int distrend_client_write(struct distrend_client *client, char *towrite, size_t msglen);
/**
writes request to client.
@param client client to write to
@param req the request struct. caller must free this.
@param data the data of the request which is req->len bytes long. caller must free this.
*/
int distrend_client_write_request(struct distrend_client *client, struct distren_request *req, void *data);
/**
This is probably just NOT a placeholder for remotio
*/
void remotio_send_to_client();
#endif
|