Skip to content

Commit c776af7

Browse files
sagebindalexcrichton
authored andcommitted
Getters on easy handles when attached to multi (#296)
Expose read-only getters that are save to invoke while an easy handle is attached to a multi handle. Also allow users to access the underlying curl pointer if the safe interface is not flexible enough for a given use-case. Fixes #273.
1 parent 382e6a4 commit c776af7

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

src/multi.rs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use libc::{c_char, c_int, c_long, c_short, c_void};
1010
#[cfg(unix)]
1111
use libc::{pollfd, POLLIN, POLLOUT, POLLPRI};
1212

13-
use easy::{Easy, Easy2};
13+
use easy::{Easy, Easy2, List};
1414
use panic;
1515
use {Error, MultiError};
1616

@@ -695,6 +695,60 @@ impl Drop for Multi {
695695
}
696696
}
697697

698+
macro_rules! impl_easy_getters {
699+
() => {
700+
impl_easy_getters! {
701+
time_condition_unmet -> bool,
702+
effective_url -> Option<&str>,
703+
effective_url_bytes -> Option<&[u8]>,
704+
response_code -> u32,
705+
http_connectcode -> u32,
706+
filetime -> Option<i64>,
707+
download_size -> f64,
708+
content_length_download -> f64,
709+
total_time -> Duration,
710+
namelookup_time -> Duration,
711+
connect_time -> Duration,
712+
appconnect_time -> Duration,
713+
pretransfer_time -> Duration,
714+
starttransfer_time -> Duration,
715+
redirect_time -> Duration,
716+
redirect_count -> u32,
717+
redirect_url -> Option<&str>,
718+
redirect_url_bytes -> Option<&[u8]>,
719+
header_size -> u64,
720+
request_size -> u64,
721+
content_type -> Option<&str>,
722+
content_type_bytes -> Option<&[u8]>,
723+
os_errno -> i32,
724+
primary_ip -> Option<&str>,
725+
primary_port -> u16,
726+
local_ip -> Option<&str>,
727+
local_port -> u16,
728+
cookies -> List,
729+
}
730+
};
731+
732+
($($name:ident -> $ret:ty,)*) => {
733+
$(
734+
impl_easy_getters!($name, $ret, concat!(
735+
"Same as [`Easy2::",
736+
stringify!($name),
737+
"`](../easy/struct.Easy2.html#method.",
738+
stringify!($name),
739+
")."
740+
));
741+
)*
742+
};
743+
744+
($name:ident, $ret:ty, $doc:expr) => {
745+
#[doc = $doc]
746+
pub fn $name(&mut self) -> Result<$ret, Error> {
747+
self.easy.$name()
748+
}
749+
};
750+
}
751+
698752
impl EasyHandle {
699753
/// Sets an internal private token for this `EasyHandle`.
700754
///
@@ -710,6 +764,8 @@ impl EasyHandle {
710764
}
711765
}
712766

767+
impl_easy_getters!();
768+
713769
/// Unpause reading on a connection.
714770
///
715771
/// Using this function, you can explicitly unpause a connection that was
@@ -737,6 +793,11 @@ impl EasyHandle {
737793
pub fn unpause_write(&self) -> Result<(), Error> {
738794
self.easy.unpause_write()
739795
}
796+
797+
/// Get a pointer to the raw underlying CURL handle.
798+
pub fn raw(&self) -> *mut curl_sys::CURL {
799+
self.easy.raw()
800+
}
740801
}
741802

742803
impl fmt::Debug for EasyHandle {
@@ -767,6 +828,8 @@ impl<H> Easy2Handle<H> {
767828
}
768829
}
769830

831+
impl_easy_getters!();
832+
770833
/// Unpause reading on a connection.
771834
///
772835
/// Using this function, you can explicitly unpause a connection that was
@@ -794,6 +857,11 @@ impl<H> Easy2Handle<H> {
794857
pub fn unpause_write(&self) -> Result<(), Error> {
795858
self.easy.unpause_write()
796859
}
860+
861+
/// Get a pointer to the raw underlying CURL handle.
862+
pub fn raw(&self) -> *mut curl_sys::CURL {
863+
self.easy.raw()
864+
}
797865
}
798866

799867
impl<H: fmt::Debug> fmt::Debug for Easy2Handle<H> {

0 commit comments

Comments
 (0)