use time.Duration instead of int to specify session timeout

This commit is contained in:
Anton Baklanov 2015-05-14 09:14:36 +03:00
parent c96ed22afd
commit 1d354f480d
2 changed files with 10 additions and 7 deletions

14
ctx.go
View File

@ -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.

View File

@ -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 {