1 // Copyright 2014 The BoringSSL Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef HEADER_PACKETED_BIO
16 #define HEADER_PACKETED_BIO
17 
18 #include <functional>
19 
20 #include <openssl/base.h>
21 #include <openssl/bio.h>
22 
23 #if defined(OPENSSL_WINDOWS)
24 #include <winsock2.h>
25 #else
26 #include <sys/time.h>
27 #endif
28 
29 
30 // PacketedBioCreate creates a filter BIO which implements a reliable in-order
31 // blocking datagram socket. It uses the value of |*clock| as the clock.
32 // |get_timeout| should output what the |SSL| object believes is the next
33 // timeout, or return false if there is none. It will be compared against
34 // assertions from the runner. |set_mtu| will be called when the runner asks to
35 // change the MTU.
36 //
37 // During a |BIO_read|, the peer may signal the filter BIO to simulate a
38 // timeout. The operation will fail immediately. The caller must then call
39 // |PacketedBioAdvanceClock| before retrying |BIO_read|.
40 bssl::UniquePtr<BIO> PacketedBioCreate(
41     timeval *clock, std::function<bool(timeval *)> get_timeout,
42     std::function<bool(uint32_t)> set_mtu);
43 
44 // PacketedBioAdvanceClock advances |bio|'s clock and returns true if there is a
45 // pending timeout. Otherwise, it returns false.
46 bool PacketedBioAdvanceClock(BIO *bio);
47 
48 // PacketedBioAdvanceClock return's |bio|'s clock.
49 timeval *PacketedBioGetClock(BIO *bio);
50 
51 
52 #endif  // HEADER_PACKETED_BIO
53