Commit 212d2e56 authored by Yan-Jie Lin's avatar Yan-Jie Lin
Browse files

reuse socket option function for SCTPConn

parent 665f3c62
......@@ -244,13 +244,15 @@ func setInitOpts(fd int, options InitMsg) error {
return err
}
func getRtoInfo(fd int) (RtoInfo, error) {
var rtoInfo RtoInfo
func getRtoInfo(fd int) (*RtoInfo, error) {
rtoInfo := RtoInfo{}
rtolen := unsafe.Sizeof(rtoInfo)
_, _, err := getsockopt(fd, SCTP_RTOINFO, uintptr(unsafe.Pointer(&rtoInfo)), uintptr(unsafe.Pointer(&rtolen)))
if err != nil {
return nil, err
}
return rtoInfo, err
return &rtoInfo, err
}
func setRtoInfo(fd int, rtoInfo RtoInfo) error {
......@@ -259,6 +261,22 @@ func setRtoInfo(fd int, rtoInfo RtoInfo) error {
return err
}
func getAssocInfo(fd int) (*AssocInfo, error) {
info := AssocInfo{}
optlen := unsafe.Sizeof(info)
_, _, err := getsockopt(fd, SCTP_ASSOCINFO, uintptr(unsafe.Pointer(&info)), uintptr(unsafe.Pointer(&optlen)))
if err != nil {
return nil, err
}
return &info, nil
}
func setAssocInfo(fd int, info AssocInfo) error {
optlen := unsafe.Sizeof(info)
_, _, err := setsockopt(fd, SCTP_ASSOCINFO, uintptr(unsafe.Pointer(&info)), uintptr(optlen))
return err
}
func setNumOstreams(fd, num int) error {
return setInitOpts(fd, InitMsg{NumOstreams: uint16(num)})
}
......
......@@ -202,41 +202,19 @@ func (c *SCTPConn) SetNonBlock(nonBlock bool) error {
}
func (c *SCTPConn) GetRtoInfo() (*RtoInfo, error) {
var rtoInfo RtoInfo
rtolen := unsafe.Sizeof(rtoInfo)
_, _, err := getsockopt(c.fd(), SCTP_RTOINFO, uintptr(unsafe.Pointer(&rtoInfo)), uintptr(unsafe.Pointer(&rtolen)))
if err != nil {
return nil, err
}
return &rtoInfo, nil
return getRtoInfo(c.fd())
}
func (c *SCTPConn) SetRtoInfo(rtoInfo RtoInfo) error {
rtolen := unsafe.Sizeof(rtoInfo)
_, _, err := setsockopt(c.fd(), SCTP_RTOINFO, uintptr(unsafe.Pointer(&rtoInfo)), uintptr(rtolen))
return err
return setRtoInfo(c.fd(), rtoInfo)
}
func (c *SCTPConn) GetAssocInfo() (*AssocInfo, error) {
info := AssocInfo{}
optlen := unsafe.Sizeof(info)
_, _, err := getsockopt(c.fd(), SCTP_ASSOCINFO, uintptr(unsafe.Pointer(&info)), uintptr(unsafe.Pointer(&optlen)))
if err != nil {
return nil, err
}
return &info, nil
return getAssocInfo(c.fd())
}
func (c *SCTPConn) SetAssocInfo(info AssocInfo) error {
optlen := unsafe.Sizeof(info)
_, _, err := setsockopt(c.fd(), SCTP_ASSOCINFO, uintptr(unsafe.Pointer(&info)), uintptr(optlen))
return err
}
func setAssocInfo(fd int, info AssocInfo) error {
optlen := unsafe.Sizeof(info)
_, _, err := setsockopt(fd, SCTP_ASSOCINFO, uintptr(unsafe.Pointer(&info)), uintptr(optlen))
return err
return setAssocInfo(c.fd(), info)
}
// ListenSCTP - start listener on specified address/port
......
......@@ -23,7 +23,6 @@ import (
"sync"
"syscall"
"testing"
"unsafe"
)
type resolveSCTPAddrTest struct {
......@@ -224,23 +223,13 @@ func TestSCTPSetRto(t *testing.T) {
if err != nil {
fails++
} else {
if !reflect.DeepEqual(rtoInfo, tt.expectedRto) {
if !reflect.DeepEqual(*rtoInfo, tt.expectedRto) {
t.Errorf("RTO[0x%x] \t ExpectedRTO[0x%x]\n", rtoInfo, tt.expectedRto)
}
}
}
}
func getAssocInfo(fd int) (*AssocInfo, error) {
info := AssocInfo{}
optlen := unsafe.Sizeof(info)
_, _, err := getsockopt(fd, SCTP_ASSOCINFO, uintptr(unsafe.Pointer(&info)), uintptr(unsafe.Pointer(&optlen)))
if err != nil {
return nil, err
}
return &info, nil
}
func TestSctpSetAssocInfo(t *testing.T) {
initMsg := InitMsg{NumOstreams: 3, MaxInstreams: 5, MaxAttempts: 4, MaxInitTimeout: 8}
fails := 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment