@@ -8,7 +8,7 @@ use tempfile::tempfile;
8
8
cfg_if ! {
9
9
if #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ] {
10
10
use nix:: unistd:: { close, pipe, read} ;
11
- } else if #[ cfg( any( target_os = "freebsd" , target_os = "ios" , target_os = "macos" ) ) ] {
11
+ } else if #[ cfg( any( target_os = "dragonfly" , target_os = " freebsd", target_os = "ios" , target_os = "macos" ) ) ] {
12
12
use std:: net:: Shutdown ;
13
13
use std:: os:: unix:: net:: UnixStream ;
14
14
}
@@ -105,6 +105,51 @@ fn test_sendfile_freebsd() {
105
105
assert_eq ! ( expected_string, read_string) ;
106
106
}
107
107
108
+ #[ cfg( target_os = "dragonfly" ) ]
109
+ #[ test]
110
+ fn test_sendfile_dragonfly ( ) {
111
+ // Declare the content
112
+ let header_strings = vec ! [ "HTTP/1.1 200 OK\n " , "Content-Type: text/plain\n " , "\n " ] ;
113
+ let body = "Xabcdef123456" ;
114
+ let body_offset = 1 ;
115
+ let trailer_strings = vec ! [ "\n " , "Served by Make Believe\n " ] ;
116
+
117
+ // Write the body to a file
118
+ let mut tmp = tempfile ( ) . unwrap ( ) ;
119
+ tmp. write_all ( body. as_bytes ( ) ) . unwrap ( ) ;
120
+
121
+ // Prepare headers and trailers for sendfile
122
+ let headers: Vec < & [ u8 ] > = header_strings. iter ( ) . map ( |s| s. as_bytes ( ) ) . collect ( ) ;
123
+ let trailers: Vec < & [ u8 ] > = trailer_strings. iter ( ) . map ( |s| s. as_bytes ( ) ) . collect ( ) ;
124
+
125
+ // Prepare socket pair
126
+ let ( mut rd, wr) = UnixStream :: pair ( ) . unwrap ( ) ;
127
+
128
+ // Call the test method
129
+ let ( res, bytes_written) = sendfile (
130
+ tmp. as_raw_fd ( ) ,
131
+ wr. as_raw_fd ( ) ,
132
+ body_offset as off_t ,
133
+ None ,
134
+ Some ( headers. as_slice ( ) ) ,
135
+ Some ( trailers. as_slice ( ) ) ,
136
+ ) ;
137
+ assert ! ( res. is_ok( ) ) ;
138
+ wr. shutdown ( Shutdown :: Both ) . unwrap ( ) ;
139
+
140
+ // Prepare the expected result
141
+ let expected_string =
142
+ header_strings. concat ( ) + & body[ body_offset..] + & trailer_strings. concat ( ) ;
143
+
144
+ // Verify the message that was sent
145
+ assert_eq ! ( bytes_written as usize , expected_string. as_bytes( ) . len( ) ) ;
146
+
147
+ let mut read_string = String :: new ( ) ;
148
+ let bytes_read = rd. read_to_string ( & mut read_string) . unwrap ( ) ;
149
+ assert_eq ! ( bytes_written as usize , bytes_read) ;
150
+ assert_eq ! ( expected_string, read_string) ;
151
+ }
152
+
108
153
#[ cfg( any( target_os = "ios" , target_os = "macos" ) ) ]
109
154
#[ test]
110
155
fn test_sendfile_darwin ( ) {
0 commit comments