1 /* Copyright (c) 2014, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef HEADER_PACKETED_BIO
16 #define HEADER_PACKETED_BIO
17 
18 #include <openssl/base.h>
19 #include <openssl/bio.h>
20 
21 #if defined(OPENSSL_WINDOWS)
22 OPENSSL_MSVC_PRAGMA(warning(push, 3))
23 #include <winsock2.h>
24 OPENSSL_MSVC_PRAGMA(warning(pop))
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 //
33 // During a |BIO_read|, the peer may signal the filter BIO to simulate a
34 // timeout. The operation will fail immediately. The caller must then call
35 // |PacketedBioAdvanceClock| before retrying |BIO_read|.
36 bssl::UniquePtr<BIO> PacketedBioCreate(timeval *clock);
37 
38 // PacketedBioAdvanceClock advances |bio|'s clock and returns true if there is a
39 // pending timeout. Otherwise, it returns false.
40 bool PacketedBioAdvanceClock(BIO *bio);
41 
42 
43 #endif  // HEADER_PACKETED_BIO
44