Seastar
High performance C++ framework for concurrent servers
udp.hh
1 /*
2  * This file is open source software, licensed to you under the terms
3  * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4  * distributed with this work for additional information regarding copyright
5  * ownership. You may not use this file except in compliance with the License.
6  *
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14  * KIND, either express or implied. See the License for the
15  * specific language governing permissions and limitations
16  * under the License.
17  */
18 /*
19  * Copyright (C) 2014 Cloudius Systems, Ltd.
20  *
21  */
22 
23 #pragma once
24 
25 #ifndef SEASTAR_MODULE
26 #include <unordered_map>
27 #include <assert.h>
28 #endif
29 
30 #include <seastar/core/shared_ptr.hh>
31 #include <seastar/net/api.hh>
32 #include <seastar/net/const.hh>
33 #include <seastar/net/net.hh>
34 #include <seastar/util/modules.hh>
35 
36 namespace seastar {
37 
38 namespace net {
39 
40 struct udp_hdr {
41  packed<uint16_t> src_port;
42  packed<uint16_t> dst_port;
43  packed<uint16_t> len;
44  packed<uint16_t> cksum;
45 
46  template<typename Adjuster>
47  auto adjust_endianness(Adjuster a) {
48  return a(src_port, dst_port, len, cksum);
49  }
50 } __attribute__((packed));
51 
53  queue<datagram> _queue;
54  // Limit number of data queued into send queue
55  semaphore _user_queue_space = {212992};
56  udp_channel_state(size_t queue_size) : _queue(queue_size) {}
57  future<> wait_for_send_buffer(size_t len) { return _user_queue_space.wait(len); }
58  void complete_send(size_t len) { _user_queue_space.signal(len); }
59 };
60 
61 }
62 
63 }
future wait(size_t nr=1) noexcept
Definition: semaphore.hh:299
void signal(size_t nr=1) noexcept
Definition: semaphore.hh:396
Definition: queue.hh:44
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: udp.hh:52
Definition: udp.hh:40
Definition: unaligned.hh:58