ca564c7a91a267ad01386b7765321f5f9c1bb5a2
[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 #define MAX_UDP_DATAGRAM_LENGTH 1400
17 #define UDP_DATAGRAM_HEADER_LENGTH 8
18 #define UDP_REQUEST_ID_MSG_SIG_DIGITS 10
19 #define UDP_REQUEST_ID_THREAD_MASK 0xFFFF << UDP_REQUEST_ID_MSG_SIG_DIGITS
20 #define get_udp_datagram_request_id(A) ntohs((A)->request_id)
21 #define get_udp_datagram_seq_num(A) ntohs((A)->sequence_number)
22 #define get_udp_datagram_num_datagrams(A) ntohs((A)->num_datagrams)
23 #define get_msg_num_from_request_id(A) ((A) & (~(UDP_REQUEST_ID_THREAD_MASK)))
24 #define get_thread_id_from_request_id(A) \
25 ((A) & (UDP_REQUEST_ID_THREAD_MASK)) >> UDP_REQUEST_ID_MSG_SIG_DIGITS
26 #define generate_udp_request_thread_id(A) (A) << UDP_REQUEST_ID_MSG_SIG_DIGITS
27 #define UDP_REQUEST_ID_MAX_THREAD_ID get_thread_id_from_request_id(0xFFFF)
28
29 struct udp_datagram_header_st {
30 uint16_t request_id;
31 uint16_t sequence_number;
32 uint16_t num_datagrams;
33 uint16_t reserved;
34 };
35
36 bool memcached_io_init_udp_header(memcached_instance_st *, const uint16_t thread_id);
37 void increment_udp_message_id(memcached_instance_st *);