Skip to content

Commit

Permalink
use time.Duration instead of int to specify session timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bak1an committed May 14, 2015
1 parent c96ed22 commit 1d354f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import (
"io/ioutil"
"os"
"runtime"
"time"
"unsafe"

"github.com/spacemonkeygo/spacelog"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1d354f4

Please sign in to comment.