Coda Distributed File System
Loading...
Searching...
No Matches
cookie.h
Go to the documentation of this file.
1/* BLURB lgpl
2
3 Coda File System
4 Release 8
5
6 Copyright (c) 2026 Carnegie Mellon University
7 Additional copyrights listed below
8
9This code is distributed "AS IS" without warranty of any kind under
10the terms of the GNU Library General Public Licence Version 2, as
11shown in the file LICENSE. The technical and financial contributors to
12Coda are listed in the file CREDITS.
13
14 Additional copyrights
15
16#*/
17
18/* File-transfer cookie table. Pure data: no libuv, no gnutls, no LWP types,
19 * so it can be unit-tested on its own. Every app-side file registration owns
20 * one entry, keyed by a 64-bit cookie; the daemon's CT_FILEDONE (demuxed in
21 * codatunnel_recvfrom) delivers a terminal status, and the waiting app side
22 * reads it before releasing the slot. */
23
24#ifndef _CODATUNNEL_COOKIE_H_
25#define _CODATUNNEL_COOKIE_H_
26
27#include <stdint.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/* Maximum number of concurrent registrations the table can track. Chosen to
34 * comfortably exceed any realistic number of in-flight transfers on one
35 * venus/codasrv, at a cost of a 256-entry scan per look-up. */
36#define CT_COOKIE_MAX 256
37
38/* ct_cookie_get() returns this when the cookie is known but the daemon has
39 * not yet delivered a terminal status. A plain -1 means the cookie is
40 * unknown; 0 means a status is available. */
41#define CT_COOKIE_PENDING (-2)
42
43/* Allocate a slot for cookie. cookie 0 is reserved (the "no cookie" sentinel).
44 * Returns 0 on success, -1 if cookie is 0, already present, or the table is
45 * full. waiter is opaque per-entry state (the daemon's registration record,
46 * NULL on the app side); the table stores it but never dereferences it. */
47int ct_cookie_add(uint64_t cookie, void *waiter);
48
49/* Record the terminal status for a cookie. Called by the CT_FILEDONE demux.
50 * Returns 0 if the cookie is known (status/nbytes stored), -1 if unknown and
51 * the delivery is dropped (peer already forgot the registration). */
52int ct_cookie_deliver(uint64_t cookie, uint32_t status, uint64_t nbytes);
53
54/* If the cookie is known and a status has been delivered, store *status and
55 * *nbytes (when non-NULL) and return 0. Returns CT_COOKIE_PENDING if the
56 * cookie is known but not yet finished, and -1 if the cookie is unknown. */
57int ct_cookie_get(uint64_t cookie, uint32_t *status, uint64_t *nbytes);
58
59/* Return the opaque per-entry state stored for the cookie, or NULL if
60 * unknown. The app side passes NULL (its waiters wake on one shared event);
61 * the daemon stores its registration record here. */
62void *ct_cookie_waiter(uint64_t cookie);
63
64/* Free the slot. Returns 0 if the cookie existed, -1 otherwise. */
65int ct_cookie_remove(uint64_t cookie);
66
67/* Iterate every in-use cookie in table order. fn is called with the cookie,
68 * its opaque waiter (the daemon's registration record), and arg. Used to fail
69 * pending transfers when their channel is torn down. */
70typedef void (*ct_cookie_visitor_t)(uint64_t cookie, void *waiter, void *arg);
72
73#ifdef __cplusplus
74}
75#endif
76
77#endif /* _CODATUNNEL_COOKIE_H_ */
unsigned int uint32_t
Definition coda.h:105
int ct_cookie_add(uint64_t cookie, void *waiter)
Definition cookie.c:63
void(* ct_cookie_visitor_t)(uint64_t cookie, void *waiter, void *arg)
Definition cookie.h:70
void ct_cookie_foreach(ct_cookie_visitor_t fn, void *arg)
Definition cookie.c:117
void * ct_cookie_waiter(uint64_t cookie)
Definition cookie.c:100
int ct_cookie_remove(uint64_t cookie)
Definition cookie.c:108
int ct_cookie_deliver(uint64_t cookie, uint32_t status, uint64_t nbytes)
Definition cookie.c:75
int ct_cookie_get(uint64_t cookie, uint32_t *status, uint64_t *nbytes)
Definition cookie.c:86
Definition rpc2.h:596