@@ -338,6 +338,82 @@ pub unsafe fn set_mwindow_file_limit(limit: libc::size_t) -> Result<(), Error> {
338338 Ok ( ( ) )
339339}
340340
341+ /// Get server connect timeout in milliseconds
342+ ///
343+ /// # Safety
344+ /// This function is modifying a C global without synchronization, so it is not
345+ /// thread safe, and should only be called before any thread is spawned.
346+ pub unsafe fn get_server_connect_timeout_in_milliseconds ( ) -> Result < libc:: c_int , Error > {
347+ crate :: init ( ) ;
348+
349+ let mut server_connect_timeout = 0 ;
350+
351+ try_call ! ( raw:: git_libgit2_opts(
352+ raw:: GIT_OPT_GET_SERVER_CONNECT_TIMEOUT as libc:: c_int,
353+ & mut server_connect_timeout
354+ ) ) ;
355+
356+ Ok ( server_connect_timeout)
357+ }
358+
359+ /// Set server connect timeout in milliseconds
360+ ///
361+ /// # Safety
362+ /// This function is modifying a C global without synchronization, so it is not
363+ /// thread safe, and should only be called before any thread is spawned.
364+ pub unsafe fn set_server_connect_timeout_in_milliseconds (
365+ timeout : libc:: c_int ,
366+ ) -> Result < ( ) , Error > {
367+ crate :: init ( ) ;
368+
369+ let error = raw:: git_libgit2_opts (
370+ raw:: GIT_OPT_SET_SERVER_CONNECT_TIMEOUT as libc:: c_int ,
371+ timeout,
372+ ) ;
373+ // This function cannot actually fail, but the function has an error return
374+ // for other options that can.
375+ debug_assert ! ( error >= 0 ) ;
376+
377+ Ok ( ( ) )
378+ }
379+
380+ /// Get server timeout in milliseconds
381+ ///
382+ /// # Safety
383+ /// This function is modifying a C global without synchronization, so it is not
384+ /// thread safe, and should only be called before any thread is spawned.
385+ pub unsafe fn get_server_timeout_in_milliseconds ( ) -> Result < libc:: c_int , Error > {
386+ crate :: init ( ) ;
387+
388+ let mut server_timeout = 0 ;
389+
390+ try_call ! ( raw:: git_libgit2_opts(
391+ raw:: GIT_OPT_GET_SERVER_TIMEOUT as libc:: c_int,
392+ & mut server_timeout
393+ ) ) ;
394+
395+ Ok ( server_timeout)
396+ }
397+
398+ /// Set server timeout in milliseconds
399+ ///
400+ /// # Safety
401+ /// This function is modifying a C global without synchronization, so it is not
402+ /// thread safe, and should only be called before any thread is spawned.
403+ pub unsafe fn set_server_timeout_in_milliseconds ( timeout : libc:: c_int ) -> Result < ( ) , Error > {
404+ crate :: init ( ) ;
405+
406+ let error = raw:: git_libgit2_opts (
407+ raw:: GIT_OPT_SET_SERVER_TIMEOUT as libc:: c_int ,
408+ timeout as libc:: c_int ,
409+ ) ;
410+ // This function cannot actually fail, but the function has an error return
411+ // for other options that can.
412+ debug_assert ! ( error >= 0 ) ;
413+
414+ Ok ( ( ) )
415+ }
416+
341417#[ cfg( test) ]
342418mod test {
343419 use super :: * ;
@@ -370,4 +446,20 @@ mod test {
370446 assert ! ( get_mwindow_file_limit( ) . unwrap( ) == 1024 ) ;
371447 }
372448 }
449+
450+ #[ test]
451+ fn server_connect_timeout ( ) {
452+ unsafe {
453+ assert ! ( set_server_connect_timeout_in_milliseconds( 5000 ) . is_ok( ) ) ;
454+ assert ! ( get_server_connect_timeout_in_milliseconds( ) . unwrap( ) == 5000 ) ;
455+ }
456+ }
457+
458+ #[ test]
459+ fn server_timeout ( ) {
460+ unsafe {
461+ assert ! ( set_server_timeout_in_milliseconds( 10_000 ) . is_ok( ) ) ;
462+ assert ! ( get_server_timeout_in_milliseconds( ) . unwrap( ) == 10_000 ) ;
463+ }
464+ }
373465}
0 commit comments