mirror of
https://github.com/libp2p/go-openssl.git
synced 2025-03-26 13:40:09 +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"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/spacemonkeygo/spacelog"
|
"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)))
|
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
|
// See https://www.openssl.org/docs/ssl/SSL_CTX_set_timeout.html
|
||||||
func (c *Ctx) SetTimeout(t int) int {
|
func (c *Ctx) SetTimeout(t time.Duration) time.Duration {
|
||||||
return int(C.SSL_CTX_set_timeout_not_a_macro(c.ctx, C.long(t)))
|
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
|
// See https://www.openssl.org/docs/ssl/SSL_CTX_set_timeout.html
|
||||||
func (c *Ctx) GetTimeout() int {
|
func (c *Ctx) GetTimeout() time.Duration {
|
||||||
return int(C.SSL_CTX_get_timeout_not_a_macro(c.ctx))
|
return time.Duration(C.SSL_CTX_get_timeout_not_a_macro(c.ctx)) * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set session cache size. Returns previously set value.
|
// Set session cache size. Returns previously set value.
|
||||||
|
@ -16,12 +16,13 @@ package openssl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCtxTimeoutOption(t *testing.T) {
|
func TestCtxTimeoutOption(t *testing.T) {
|
||||||
ctx, _ := NewCtx()
|
ctx, _ := NewCtx()
|
||||||
oldTimeout1 := ctx.GetTimeout()
|
oldTimeout1 := ctx.GetTimeout()
|
||||||
newTimeout1 := oldTimeout1 + 8362
|
newTimeout1 := oldTimeout1 + (time.Duration(99) * time.Second)
|
||||||
oldTimeout2 := ctx.SetTimeout(newTimeout1)
|
oldTimeout2 := ctx.SetTimeout(newTimeout1)
|
||||||
newTimeout2 := ctx.GetTimeout()
|
newTimeout2 := ctx.GetTimeout()
|
||||||
if oldTimeout1 != oldTimeout2 {
|
if oldTimeout1 != oldTimeout2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user