Skip to content

Commit

Permalink
fix windows + fix const
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarukhov committed Jul 9, 2020
1 parent 45bdba5 commit b093f5c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/agent/app/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
const (
defaultQueueSize = 1000
defaultMaxPacketSize = 65000
defaultBufferSize = 16 * 1024 * 1024
defaultBufferSize = 4 * 1024
defaultServerWorkers = 10

jaegerModel Model = "jaeger"
Expand Down
14 changes: 11 additions & 3 deletions cmd/agent/app/servers/thriftudp/socket_buffer_linux_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

package thriftudp

import "syscall"
import (
"net"
"syscall"
)

func setSocketBuffer(fd uintptr, level, opt, value int) error {
return syscall.SetsockoptInt(int(fd), level, opt, value)
func setSocketBuffer(conn *net.UDPConn, bufferSize int) error {
file, err := conn.File()
if err != nil {
return err
}

return syscall.SetsockoptInt(int(file.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bufferSize)
}
9 changes: 6 additions & 3 deletions cmd/agent/app/servers/thriftudp/socket_buffer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

package thriftudp

import "syscall"
import (
"net"
)

func setSocketBuffer(fd uintptr, level, opt, value int) error {
return syscall.SetsockoptInt(syscall.Handle(fd), level, opt, value)
// Not supported on windows, so windows version just returns nil
func setSocketBuffer(_ *net.UDPConn, _ int) error {
return nil
}
10 changes: 2 additions & 8 deletions cmd/agent/app/servers/thriftudp/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (
"errors"
"net"
"sync/atomic"
"syscall"

"github.com/apache/thrift/lib/go/thrift"
)

//MaxLength of UDP packet
const (
MaxLength = 65000
BufferSize = 16 * 1024 * 1024
BufferSize = 4 * 1024
)

var errConnAlreadyClosed = errors.New("connection already closed")
Expand Down Expand Up @@ -85,12 +84,7 @@ func NewTUDPServerTransport(hostPort string, bufferSize int) (*TUDPTransport, er
return nil, thrift.NewTTransportException(thrift.NOT_OPEN, err.Error())
}

file, err := conn.File()
if err != nil {
return nil, err
}

if err = setSocketBuffer(file.Fd(), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bufferSize); err != nil {
if err = setSocketBuffer(conn, bufferSize); err != nil {
return nil, err
}

Expand Down

0 comments on commit b093f5c

Please sign in to comment.