mirror of
https://github.com/libp2p/go-openssl.git
synced 2025-01-29 05:10:10 +08:00
use time.Duration instead of int to specify session timeout
This commit is contained in:
parent
c96ed22afd
commit
1d354f480d
14
ctx.go
14
ctx.go
@ -104,6 +104,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/spacemonkeygo/spacelog"
|
||||
@ -580,16 +581,17 @@ func (c *Ctx) SetSessionCacheMode(modes SessionCacheModes) SessionCacheModes {
|
||||
C.SSL_CTX_set_session_cache_mode_not_a_macro(c.ctx, C.long(modes)))
|
||||
}
|
||||
|
||||
// Set session cache timeout in seconds. Returns previously set value.
|
||||
// Set session cache timeout. Returns previously set value.
|
||||
// See https://www.openssl.org/docs/ssl/SSL_CTX_set_timeout.html
|
||||
func (c *Ctx) SetTimeout(t int) int {
|
||||
return int(C.SSL_CTX_set_timeout_not_a_macro(c.ctx, C.long(t)))
|
||||
func (c *Ctx) SetTimeout(t time.Duration) time.Duration {
|
||||
prev := C.SSL_CTX_set_timeout_not_a_macro(c.ctx, C.long(t/time.Second))
|
||||
return time.Duration(prev) * time.Second
|
||||
}
|
||||
|
||||
// Get session cache timeout in seconds.
|
||||
// Get session cache timeout.
|
||||
// See https://www.openssl.org/docs/ssl/SSL_CTX_set_timeout.html
|
||||
func (c *Ctx) GetTimeout() int {
|
||||
return int(C.SSL_CTX_get_timeout_not_a_macro(c.ctx))
|
||||
func (c *Ctx) GetTimeout() time.Duration {
|
||||
return time.Duration(C.SSL_CTX_get_timeout_not_a_macro(c.ctx)) * time.Second
|
||||
}
|
||||
|
||||
// Set session cache size. Returns previously set value.
|
||||
|
@ -16,12 +16,13 @@ package openssl
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCtxTimeoutOption(t *testing.T) {
|
||||
ctx, _ := NewCtx()
|
||||
oldTimeout1 := ctx.GetTimeout()
|
||||
newTimeout1 := oldTimeout1 + 8362
|
||||
newTimeout1 := oldTimeout1 + (time.Duration(99) * time.Second)
|
||||
oldTimeout2 := ctx.SetTimeout(newTimeout1)
|
||||
newTimeout2 := ctx.GetTimeout()
|
||||
if oldTimeout1 != oldTimeout2 {
|
||||
|
Loading…
Reference in New Issue
Block a user