pub fn add_tls_stream(
		&mut self,
		stream: &TcpStream,
		server_name: &str,
		trusted_certificate: Option<&str>,
	) -> Result<WriteHandle, Error> {
		// make sure we have a client on_read handler configured
		{
			let callbacks = nioruntime_util::lockr!(self.callbacks);

			match callbacks.on_client_read {
				Some(_) => {}
				None => {
					return Err(ErrorKind::SetupError(
						"on_client_read callback must be registered first".to_string(),
					)
					.into());
				}
			}
		}

		stream.set_nonblocking(true)?;

		#[cfg(target_os = "windows")]
		{
			let fd = stream.as_raw_socket();

			let sockoptres = unsafe {
				ws2_32::setsockopt(
					fd,
					winapi::SOL_SOCKET,
					winapi::SO_SNDBUF,
					&WINSOCK_BUF_SIZE as *const _ as *const i8,
					std::mem::size_of_val(&WINSOCK_BUF_SIZE) as winapi::c_int,
				)
			};

			if sockoptres != 0 {
				log_multi!(
					ERROR,
					MAIN_LOG,
					"setsockopt resulted in error: {}",
					errno().to_string()
				);
			}
		}

		let config = make_config(trusted_certificate)?;
		let tls_client = Some(Arc::new(RwLock::new(
			ClientConnection::new(config, server_name.try_into().unwrap()).unwrap(),
		)));

		let mut rng = rand::thread_rng();
		let gd_index: usize = rng.gen();
		let gd_index = (gd_index % (self.guarded_data.len() - 1)) + 1;

		#[cfg(unix)]
		let (fd, connection_id) = self.add(
			stream.as_raw_fd(),
			ActionType::AddTlsStream,
			tls_client.clone(),
			gd_index,
		)?;
		#[cfg(target_os = "windows")]
		let (fd, connection_id) = self.add(
			stream.as_raw_socket().into(),
			ActionType::AddTlsStream,
			tls_client.clone(),
			gd_index,
		)?;

		let callback_state = Arc::new(RwLock::new(State::Init));
		Ok(WriteHandle {
			fd,
			connection_id,
			guarded_data: self.guarded_data[gd_index].clone(),
			global_lock: self.global_lock.clone(),
			callback_state,
			tls_server: None,
			tls_client,
		})
	}
/// Add a [`TcpStream`] to this EventHandler and use tls with this TcpStream.
///
/// This function adds the specified [`TcpStream`] to this [`EventHandler`] marked as tls.
/// When data is read on this [`TcpStream`], the callback specified by [`EventHandler::set_on_client_read`] will be
/// executed and the user can respond accordingly. Please note that
/// the EventHanlder is only responsible for handling reads/writes/closes (when an error occurs,
/// or the user specifies) on the stream. The calling function must ensure that the [`TcpStream`]
/// stays in scope because [`TcpStream`]'s drop function will close the socket which will result
/// in the [`EventHandler`] detecting the close of the socket and taking appropriate action.
/// Also note that the caller is responsible for managing this resource. The [`EventHandler`] will
/// never close a connection unless it is instructed by the caller through the [`WriteHandle`] interface
/// or if an error occurs or the other side of the connection closes. Also, once the [`TcpStream`] is
/// registered with the [`EventHandler`], all reads/writes to this stream should occur through the
/// [`EventHandler`] interface. Calling functions in [`TcpStream`] like [`std::io::Read`] or
/// [`std::io::Write`] will result in undefined behavior. If the stream closes for any reason, the
/// callback specified by [`EventHandler::set_on_close`] will be executed to notify the user.
/// This function returns the [`WriteHandle`]
/// that may be used to write to the socket.
/// See the example above on how to do that.
/// This function will result in an error if an i/o error occurs while trying to configure the stream
/// or the [`EventHandler`] has not been configured using the [`EventHandler::set_on_client_read`] function.
Add a [`TcpStream`] to this EventHandler and use tls with this TcpStream.
This function adds the specified [`TcpStream`] to this [`EventHandler`] marked as tls.
When data is read on this [`TcpStream`], the callback specified by [`EventHandler::set_on_client_read`] will be
executed and the user can respond accordingly. Please note that
the EventHanlder is only responsible for handling reads/writes/closes (when an error occurs,
or the user specifies) on the stream.
Add a [ ` TcpStream ` ] to this EventHandler and use tls with this TcpStream . This function adds the specified [ ` TcpStream ` ] to this [ ` EventHandler ` ] marked as tls . When data is read on this [ ` TcpStream ` ] the callback specified by [ ` EventHandler :: set_on_client_read ` ] will be executed and the user can respond accordingly . Please note that the EventHanlder is only responsible for handling reads / writes / closes ( when an error occurs or the user specifies ) on the stream .
pub fn add_tls_stream(
		&mut self,
		stream: &TcpStream,
		server_name: &str,
		trusted_certificate: Option<&str>,
	) -> Result<WriteHandle, Error> {
		// make sure we have a client on_read handler configured
		{
			let callbacks = nioruntime_util::lockr!(self.callbacks);
			match callbacks.on_client_read {
				Some(_) => {}
				None => {
					return Err(ErrorKind::SetupError(
						"on_client_read callback must be registered first".to_string(),
					)
					.into());
				}
			}
		}
		stream.set_nonblocking(true)?;
		#[cfg(target_os = "windows")]
		{
			let fd = stream.as_raw_socket();
			let sockoptres = unsafe {
				ws2_32::setsockopt(
					fd,
					winapi::SOL_SOCKET,
					winapi::SO_SNDBUF,
					&WINSOCK_BUF_SIZE as *const _ as *const i8,
					std::mem::size_of_val(&WINSOCK_BUF_SIZE) as winapi::c_int,
				)
			};
			if sockoptres != 0 {
				log_multi!(
					ERROR,
					MAIN_LOG,
					"setsockopt resulted in error: {}",
					errno().to_string()
				);
			}
		}
		let config = make_config(trusted_certificate)?;
		let tls_client = Some(Arc::new(RwLock::new(
			ClientConnection::new(config, server_name.try_into().unwrap()).unwrap(),
		)));
		let mut rng = rand::thread_rng();
		let gd_index: usize = rng.gen();
		let gd_index = (gd_index % (self.guarded_data.len() - 1)) + 1;
		#[cfg(unix)]
		let (fd, connection_id) = self.add(
			stream.as_raw_fd(),
			ActionType::AddTlsStream,
			tls_client.clone(),
			gd_index,
		)?;
		#[cfg(target_os = "windows")]
		let (fd, connection_id) = self.add(
			stream.as_raw_socket().into(),
			ActionType::AddTlsStream,
			tls_client.clone(),
			gd_index,
		)?;
		let callback_state = Arc::new(RwLock::new(State::Init));
		Ok(WriteHandle {
			fd,
			connection_id,
			guarded_data: self.guarded_data[gd_index].clone(),
			global_lock: self.global_lock.clone(),
			callback_state,
			tls_server: None,
			tls_client,
		})
	}
pub fn add_tls_stream ( & mut self , stream : & TcpStream , server_name : & str , trusted_certificate : Option < & str > , ) -> Result < WriteHandle , Error > { // make sure we have a client on_read handler configured { let callbacks = nioruntime_util :: lockr ! ( self callbacks ) ; match callbacks . on_client_read { Some ( _ ) => { } None => { return Err ( ErrorKind :: SetupError ( " " . to_string ( ) , ) . into ( ) ) ; } } } stream . set_nonblocking ( true ) ? ; # [ cfg ( target_os " " ) ] { let fd = stream . as_raw_socket ( ) ; let sockoptres = unsafe { ws2_32 :: setsockopt ( fd , winapi :: SOL_SOCKET , winapi :: SO_SNDBUF , & WINSOCK_BUF_SIZE as * const _ as * const i8 , std :: mem :: size_of_val ( & WINSOCK_BUF_SIZE ) as winapi :: c_int , ) } ; if sockoptres != 0 { log_multi ! ( ERROR MAIN_LOG " " errno ( ) to_string ( ) ) ; } } let config = make_config ( trusted_certificate ) ? ; let tls_client = Some ( Arc :: new ( RwLock :: new ( ClientConnection :: new ( config , server_name . try_into ( ) . unwrap ( ) ) . unwrap ( ) , ) ) ) ; let mut rng = rand :: thread_rng ( ) ; let gd_index : usize = rng . gen ( ) ; let gd_index = ( gd_index % ( self . guarded_data . len ( ) - 1 ) ) + 1 ; # [ cfg ( unix ) ] let ( fd , connection_id ) = self . add ( stream . as_raw_fd ( ) , ActionType :: AddTlsStream , tls_client . clone ( ) , gd_index , ) ? ; # [ cfg ( target_os " " ) ] let ( fd , connection_id ) = self . add ( stream . as_raw_socket ( ) . into ( ) , ActionType :: AddTlsStream , tls_client . clone ( ) , gd_index , ) ? ; let callback_state = Arc :: new ( RwLock :: new ( State :: Init ) ) ; Ok ( WriteHandle { fd , connection_id , guarded_data : self . guarded_data [ gd_index ] . clone ( ) , global_lock : self . global_lock . clone ( ) , callback_state , tls_server : None , tls_client , } ) }
Add a [`TcpStream`] to this EventHandler and use tls with this TcpStream.
Add a [ ` TcpStream ` ] to this EventHandler and use tls with this TcpStream .
&mut self
stream
&TcpStream
server_name
&str
trusted_certificate
Option<&str>
&mut self
stream
&TcpStream
server_name
&str
trusted_certificate
Option<&str>