Skip to content

Commit a6b0f18

Browse files
authored
support ABSTRACT_UNIX_SOCKET (#469)
this PR add supports for this feature: https://curl.se/libcurl/c/CURLOPT_ABSTRACT_UNIX_SOCKET.html
1 parent b62fa94 commit a6b0f18

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

curl-sys/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ pub const CURLOPT_PROXY_SSL_CIPHER_LIST: CURLoption = CURLOPTTYPE_OBJECTPOINT +
605605
pub const CURLOPT_PROXY_CRLFILE: CURLoption = CURLOPTTYPE_OBJECTPOINT + 260;
606606
pub const CURLOPT_PROXY_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 261;
607607

608+
pub const CURLOPT_ABSTRACT_UNIX_SOCKET: CURLoption = CURLOPTTYPE_OBJECTPOINT + 264;
609+
608610
pub const CURLOPT_DOH_URL: CURLoption = CURLOPTTYPE_OBJECTPOINT + 279;
609611
pub const CURLOPT_UPLOAD_BUFFERSIZE: CURLoption = CURLOPTTYPE_LONG + 280;
610612

src/easy/handle.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ impl Easy {
170170
self.inner.unix_socket_path(path)
171171
}
172172

173+
/// Same as [`Easy2::abstract_unix_socket`](struct.Easy2.html#method.abstract_unix_socket)
174+
///
175+
/// NOTE: this API can only be used on Linux OS.
176+
#[cfg(target_os = "linux")]
177+
pub fn abstract_unix_socket(&mut self, addr: &[u8]) -> Result<(), Error> {
178+
self.inner.abstract_unix_socket(addr)
179+
}
180+
173181
// =========================================================================
174182
// Callback options
175183

src/easy/handler.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,21 @@ impl<H> Easy2<H> {
807807
}
808808
}
809809

810+
/// Provides the ABSTRACT UNIX SOCKET which this handle will work with.
811+
///
812+
/// This function is an alternative to [`Easy2::unix_socket`] and [`Easy2::unix_socket_path`] that supports
813+
/// ABSTRACT_UNIX_SOCKET(`man 7 unix` on Linux) address.
814+
///
815+
/// By default this option is not set and corresponds to
816+
/// [`CURLOPT_ABSTRACT_UNIX_SOCKET`](https://curl.haxx.se/libcurl/c/CURLOPT_ABSTRACT_UNIX_SOCKET.html).
817+
///
818+
/// NOTE: this API can only be used on Linux OS.
819+
#[cfg(target_os = "linux")]
820+
pub fn abstract_unix_socket(&mut self, addr: &[u8]) -> Result<(), Error> {
821+
let addr = CString::new(addr)?;
822+
self.setopt_str(curl_sys::CURLOPT_ABSTRACT_UNIX_SOCKET, &addr)
823+
}
824+
810825
// =========================================================================
811826
// Internal accessors
812827

systest/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ fn main() {
219219
s == "CURLSSLOPT_NO_REVOKE" ||
220220

221221
// A lot of curl versions doesn't support unix sockets
222-
s == "CURLOPT_UNIX_SOCKET_PATH" || s == "CURL_VERSION_UNIX_SOCKETS"
222+
s == "CURLOPT_UNIX_SOCKET_PATH" || s == "CURL_VERSION_UNIX_SOCKETS" || s ==
223+
"CURLOPT_ABSTRACT_UNIX_SOCKET"
223224
});
224225

225226
if cfg!(target_env = "msvc") {

0 commit comments

Comments
 (0)