QuickIO  0.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
client.h
Go to the documentation of this file.
1 
12 #pragma once
13 #include "quickio.h"
14 
24 
30 
35 
40 
45 };
46 
50 struct client_sub {
54  gint32 idx;
55 
59  gboolean pending;
60 
64  gboolean tombstone;
65 };
66 
70 struct client_cb {
74  guint16 id;
75 
80 
84  void *cb_data;
85 
90 
94  gint64 created;
95 };
96 
100 struct client {
105 
109  struct {
113  gboolean handshaked:1;
114 
119  struct protocol *prot;
120 
125  union {
126 
127  } flags;
128  } protocol;
129 
133  gint64 last_send;
134 
138  gint64 last_recv;
139 
148 
152  GHashTable *subs;
153 
158  GHashTable *data;
159 
163  struct {
167  __uint128_t sid;
168 
172  guint tbl;
173 
177  guint64 body_len;
178 
183  struct {
187  gboolean is_post:1;
188 
192  gboolean iframe_requested:1;
193 
197  gboolean keep_alive:1;
198 
203  gboolean in_request:1;
204 
212  gboolean incoming:1;
213  } flags;
214 
224  struct client *client;
225  } http;
226 
230  struct client_cb *cbs[4];
231 
235  guint16 cbs_id;
236 };
237 
257  struct client *client,
258  const evs_cb_fn cb_fn,
259  void *cb_data,
260  const qev_free_fn free_fn);
261 
275  struct client *client,
276  const evs_cb_t server_cb,
277  const evs_cb_t client_cb,
278  gchar *json);
279 
283 void client_cb_prune(struct client *client, const gint64 before);
284 
289 
301 gboolean client_sub_active(struct client *client, struct subscription *sub);
302 
323  struct client *client,
324  struct subscription *sub);
325 
346  struct client *client,
347  struct subscription *sub);
348 
357 void client_sub_reject(
358  struct client *client,
359  struct subscription *sub);
360 
372 gboolean client_sub_remove(struct client *client, struct subscription *sub);
373 
385  const guint64 total,
386  const guint64 pressure,
387  const guint64 min);
388 
400 void client_set(struct client *client, const GQuark key, GVariant *val);
401 
413 GVariant* client_get(struct client *client, const GQuark key);
414 
426 gboolean client_has(struct client *client, const GQuark key);
427 
436 void client_del(struct client *client, const GQuark key);
437 
441 void client_closed(struct client *client);
442 
446 void client_free_all(struct client *client);
447 
451 void client_init();
struct client::@0 protocol
What's needed to handle protocol support in the client.
guint64 body_len
How much data is left to read from the socket.
Definition: client.h:177
evs_cb_fn cb_fn
The function to be called.
Definition: client.h:79
guint16 id
To make sure that callbacks don't overlap.
Definition: client.h:74
evs_status
From handlers, these values instruct the server how to handle everything.
Definition: evs.h:59
guint64 evs_cb_t
Callbacks are just gigantic integers, 0 meaning "no callback".
Definition: evs.h:23
struct protocol * prot
Once a protocol has accepted the client, this will point to the protocol-level functions that can be ...
Definition: client.h:119
qev_free_fn free_fn
Function used to free the cb_data.
Definition: client.h:89
gboolean keep_alive
If the client is keep-alive.
Definition: client.h:197
gint32 idx
Where the client lives in the sub list.
Definition: client.h:54
gboolean tombstone
If an unsubscribe came in before evs_on_cb() came through.
Definition: client.h:64
struct client * client
Can be 1 of 3 things, depending on client type: 1) If the client is a surrogate, then points to the c...
Definition: client.h:224
void client_sub_reject(struct client *client, struct subscription *sub)
Removes a pending subscription.
enum evs_status client_cb_fire(struct client *client, const evs_cb_t server_cb, const evs_cb_t client_cb, gchar *json)
Fires a callback and frees up everything associated with it.
The subscription exists and is going to be removed, but evs_on_cb() hasn't been called by the owner...
Definition: client.h:29
The subscription already exists and is in the pending state (probably went async with verification)...
Definition: client.h:23
gboolean client_has(struct client *client, const GQuark key)
Check if the client has anything set for the given key.
gint64 last_send
When anything was last sent to the client.
Definition: client.h:133
The subscription is active and valid.
Definition: client.h:39
__uint128_t sid
The key in http's client table.
Definition: client.h:167
gboolean pending
If the subscription is pending: the on() callback went async.
Definition: client.h:59
gboolean handshaked
If the client has handshaked with its protocol.
Definition: client.h:113
void * cb_data
Data to pass to the function.
Definition: client.h:84
The client has no such subscription.
Definition: client.h:44
client_sub_state
Client subscriptions go through multiple states, explained here.
Definition: client.h:18
Information about the client's subscription to an event.
Definition: client.h:50
gboolean incoming
A new request just came in and is being processed; don't send out any updates until the new request's...
Definition: client.h:212
Everything that a client needs to function.
Definition: client.h:100
enum client_sub_state client_sub_accept(struct client *client, struct subscription *sub)
Marks the subscription as accepted.
The subscription was created and is in the pending state.
Definition: client.h:34
guint tbl
Which table the client lives in.
Definition: client.h:172
void client_init()
Initialize clients data.
GHashTable * data
Any extra data that can be attached to a client using client_{get,set,del,has}(). ...
Definition: client.h:158
gint64 created
When the callback was created (monotonic time)
Definition: client.h:94
enum client_sub_state client_sub_add(struct client *client, struct subscription *sub)
Adds the subscription to the client.
gboolean iframe_requested
If the client requested the iframe.
Definition: client.h:192
What a protocol needs to route messages around.
Definition: protocols.h:114
Information necessary to fire a callback.
Definition: client.h:70
qev_timeout_t * timeout
The only timeout that will be set on a client from QIO.
Definition: client.h:147
void client_closed(struct client *client)
A client closed and it should start to be cleaned up.
struct client::@1 http
For managing the HTTP session for the client.
Every header, definition, and whatnot QuickIO needs to run.
void client_set(struct client *client, const GQuark key, GVariant *val)
Sets a piece of data on a client.
struct client_cb * cbs[4]
The callbacks for the client.
Definition: client.h:230
void client_update_subs_config(const guint64 total, const guint64 pressure, const guint64 min)
For configuration values: update the fair pool for subs.
union client::@0::@2 flags
Any protocol-level flags should be created here as a union of bit-field structs.
gboolean client_sub_remove(struct client *client, struct subscription *sub)
Removes the subscription from the client.
void client_del(struct client *client, const GQuark key)
Remove the key from the client.
void(* qev_free_fn)(void *)
Function type for a typical free function.
Definition: qev.h:185
gint64 client_cb_prune_get_before()
Get the time before which callbacks should be pruned.
GVariant * client_get(struct client *client, const GQuark key)
Gets some data from a client.
Events are what are located at the paths, whereas subscriptions are what are located at ev_path + ev_...
Definition: sub.h:20
evs_cb_t client_cb_new(struct client *client, const evs_cb_fn cb_fn, void *cb_data, const qev_free_fn free_fn)
Creates a callback for the client.
gboolean client_sub_active(struct client *client, struct subscription *sub)
Checks if a client is subscribed to the given susbcription.
gboolean in_request
If headers have been received and the client currently processing a request.
Definition: client.h:203
void client_cb_prune(struct client *client, const gint64 before)
Prune any client callbacks that have been hanging around too long.
struct qev_timeout qev_timeout_t
You're never allowed to mess with timeout internals.
Definition: qev.h:175
void client_free_all(struct client *client)
A client is being freed and should be completely cleaned up.
enum evs_status(* evs_cb_fn)(struct client *client, const void *data, const evs_cb_t client_cb, gchar *json)
Function called when the client sends a callback to the server.
Definition: evs.h:50
guint16 cbs_id
The ID of the most recent callback.
Definition: client.h:235
gboolean is_post
If the client sent a POST.
Definition: client.h:187
Contains all of the information needed for quick-event to have a functioning client.
Definition: qev.h:254
GHashTable * subs
Maps: struct subscription -> gint32 (qev_list index)
Definition: client.h:152
gint64 last_recv
When anything was last received from the client.
Definition: client.h:138