diff options
author | defanor <defanor@uberspace.net> | 2023-12-07 13:54:45 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2023-12-07 14:40:51 +0300 |
commit | b349a15d9221e1e9d6736eccb7357294399eb830 (patch) | |
tree | f6168ea6ddf5c6745758ea65ca5d6bf59dafcb34 /src/rexmpp_tcp.rs | |
parent | ecbef993632c9b3bdf442b381e02e1ad24bc1c87 (diff) |
Provide a callback after socket creation, use _Bool
The callback is provided to set socket options, instead of individual
options such as path_mtu_discovery (which is now removed).
Noticed that the Rust rexmpp structure's C representation does not
match that of C, since Rust's "bool" maps to C99's "_Bool", while I
thought that it maps to "int" (c_int). Adjusted C structures to use
"bool" from stdbool.h as well, since C99 (GNU99) is used already.
Diffstat (limited to 'src/rexmpp_tcp.rs')
-rw-r--r-- | src/rexmpp_tcp.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/rexmpp_tcp.rs b/src/rexmpp_tcp.rs index d895004..56c204c 100644 --- a/src/rexmpp_tcp.rs +++ b/src/rexmpp_tcp.rs @@ -1,6 +1,6 @@ use std::os::raw::{c_int, c_char}; use libc::*; -use std::ptr::null_mut; +use std::ptr::{null_mut,null}; use std::mem; use errno::{errno}; @@ -52,7 +52,7 @@ pub struct RexmppTCPConnection { pub connection_attempts: c_int, pub next_connection_time: timespec, pub fd: c_int, - pub dns_secure: c_int + pub dns_secure: bool } #[no_mangle] @@ -150,12 +150,8 @@ fn rexmpp_tcp_socket (s: *mut rexmpp::Rexmpp, domain: c_int) -> c_int { let flags: c_int = fcntl(sock, F_GETFL, 0); fcntl(sock, F_SETFL, flags | O_NONBLOCK); - // Set path MTU discovery, if provided - if (*s).path_mtu_discovery != -1 { - setsockopt(sock, SOL_IP, IP_MTU_DISCOVER, - &mut (*s).path_mtu_discovery as *mut i32 as *mut c_void, - mem::size_of::<c_int>() as u32); - } + // Call the socket creation callback, if provided + ((*s).socket_cb).map(|cb| cb(s, sock)); return sock; } @@ -175,7 +171,7 @@ fn rexmpp_tcp_conn_init (s: *mut rexmpp::Rexmpp, (*conn).resolved_v4 = null_mut(); (*conn).resolved_v6 = null_mut(); (*conn).fd = -1; - (*conn).dns_secure = 0; + (*conn).dns_secure = false; (*conn).next_connection_time.tv_sec = 0; (*conn).next_connection_time.tv_nsec = 0; |