]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/docs/api/mg_set_user_connection_data.md
buildsys: switch source download to quincy
[ceph.git] / ceph / src / civetweb / docs / api / mg_set_user_connection_data.md
1 # Civetweb API Reference
2
3 ### `mg_set_user_connection_data( conn, data );`
4
5 ### Parameters
6
7 | Parameter | Type | Description |
8 | :--- | :--- | :--- |
9 |**`conn`**|`struct mg_connection *`|connection to add the user data|
10 |**`data`**|`void *`|Pointer to the user data|
11
12 ### Return Value
13
14 *none*
15
16 ### Description
17
18 The function `mg_set_user_connection_data()` can be used to set a user defined
19 data pointer attached to a connection. This value can be read using
20 `mg_get_user_connection_data()`.
21 Any call to `mg_set_user_connection_data()` will overwrite a previously
22 assigned user data pointer.
23
24 `mg_set_user_connection_data()` requires a non-const
25 `struct mg_connection *` to set the user data pointer. It is save to use the
26 `const struct mg_connection *` passed to a websocket connect handler (with a
27 const cast), since `const` just means you must not use `mg_read()` or
28 `mg_write()` in this context.
29
30 Alternatively, you can use the `init_connection` callback in
31 `struct mg_callbacks` to set the user data pointer.
32 In this case, typically `init_connection` is used to allocate memory for
33 a user defined `struct`, while `connection_close` is used to free this
34 memory again.
35
36
37 ### See Also
38
39 * [`mg_get_user_connection_data();`](mg_get_user_connection_data.md)
40 * [`struct mg_callbacks`](mg_callbacks.md)
41 * [`mg_set_websocket_handler();`](mg_set_websocket_handler.md)
42 * [`mg_read();`](mg_read.md)
43 * [`mg_write();`](mg_write.md)
44