use raw_fd since owned object would close fd on drop
Signed-off-by: Adrian Catangiu <acatan@amazon.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::RawFd;
|
||||||
|
|
||||||
use crate::common::ascii::{CR, CRLF_LEN, LF};
|
use crate::common::ascii::{CR, CRLF_LEN, LF};
|
||||||
use crate::common::Body;
|
use crate::common::Body;
|
||||||
@@ -56,8 +56,8 @@ pub struct HttpConnection<T> {
|
|||||||
/// The latest file that has been received and which must be associated
|
/// The latest file that has been received and which must be associated
|
||||||
/// with the pending request.
|
/// with the pending request.
|
||||||
rx_file: Option<File>,
|
rx_file: Option<File>,
|
||||||
/// The enqueued file that should be sent with contents of `response_buffer`.
|
/// The enqueued file descriptor that should be sent with contents of `response_buffer`.
|
||||||
tx_file: Option<File>,
|
tx_file: Option<RawFd>,
|
||||||
/// Optional payload max size.
|
/// Optional payload max size.
|
||||||
payload_max_size: usize,
|
payload_max_size: usize,
|
||||||
}
|
}
|
||||||
@@ -441,9 +441,9 @@ impl<T: Read + Write + ScmSocket> HttpConnection<T> {
|
|||||||
if let Some(response_buffer_vec) = self.response_buffer.as_mut() {
|
if let Some(response_buffer_vec) = self.response_buffer.as_mut() {
|
||||||
let bytes_to_be_written = response_buffer_vec.len();
|
let bytes_to_be_written = response_buffer_vec.len();
|
||||||
let write_result = match self.tx_file.take() {
|
let write_result = match self.tx_file.take() {
|
||||||
Some(file) => self
|
Some(raw_fd) => self
|
||||||
.stream
|
.stream
|
||||||
.send_with_fd(response_buffer_vec.as_slice(), file.as_raw_fd())
|
.send_with_fd(response_buffer_vec.as_slice(), raw_fd)
|
||||||
.map_err(|e| std::io::Error::from_raw_os_error(e.errno())),
|
.map_err(|e| std::io::Error::from_raw_os_error(e.errno())),
|
||||||
None => self.stream.write(response_buffer_vec.as_slice()),
|
None => self.stream.write(response_buffer_vec.as_slice()),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{Error as WriteError, Write};
|
use std::io::{Error as WriteError, Write};
|
||||||
|
use std::os::unix::io::RawFd;
|
||||||
|
|
||||||
use crate::ascii::{COLON, CR, LF, SP};
|
use crate::ascii::{COLON, CR, LF, SP};
|
||||||
use crate::common::{Body, Version};
|
use crate::common::{Body, Version};
|
||||||
@@ -194,8 +194,8 @@ pub struct Response {
|
|||||||
status_line: StatusLine,
|
status_line: StatusLine,
|
||||||
headers: ResponseHeaders,
|
headers: ResponseHeaders,
|
||||||
body: Option<Body>,
|
body: Option<Body>,
|
||||||
/// The optional file associated with the response.
|
/// The optional file descriptor associated with the response.
|
||||||
pub file: Option<File>,
|
pub file: Option<RawFd>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for Response {
|
impl PartialEq for Response {
|
||||||
|
|||||||
Reference in New Issue
Block a user