more cleanup
[m6w6/libmemcached] / src / libmemcached / udp.hpp
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #define MAX_UDP_DATAGRAM_LENGTH 1400
19 #define UDP_DATAGRAM_HEADER_LENGTH 8
20 #define UDP_REQUEST_ID_MSG_SIG_DIGITS 10
21 #define UDP_REQUEST_ID_THREAD_MASK 0xFFFF << UDP_REQUEST_ID_MSG_SIG_DIGITS
22 #define get_udp_datagram_request_id(A) ntohs((A)->request_id)
23 #define get_udp_datagram_seq_num(A) ntohs((A)->sequence_number)
24 #define get_udp_datagram_num_datagrams(A) ntohs((A)->num_datagrams)
25 #define get_msg_num_from_request_id(A) ((A) & (~(UDP_REQUEST_ID_THREAD_MASK)))
26 #define get_thread_id_from_request_id(A) \
27 ((A) & (UDP_REQUEST_ID_THREAD_MASK)) >> UDP_REQUEST_ID_MSG_SIG_DIGITS
28 #define generate_udp_request_thread_id(A) (A) << UDP_REQUEST_ID_MSG_SIG_DIGITS
29 #define UDP_REQUEST_ID_MAX_THREAD_ID get_thread_id_from_request_id(0xFFFF)
30
31 struct udp_datagram_header_st {
32 uint16_t request_id;
33 uint16_t sequence_number;
34 uint16_t num_datagrams;
35 uint16_t reserved;
36 };
37
38 bool memcached_io_init_udp_header(memcached_instance_st *, const uint16_t thread_id);
39 void increment_udp_message_id(memcached_instance_st *);