Skip to content

Commit

Permalink
feat: support windows dev env (#101)
Browse files Browse the repository at this point in the history
Works in Git Bash and PowerShell in Windows 10
  • Loading branch information
hn8 committed Aug 30, 2021
1 parent 32daa25 commit 6a88bcc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
28 changes: 1 addition & 27 deletions pkg/rtc/config.go
Expand Up @@ -3,7 +3,6 @@ package rtc
import (
"errors"
"net"
"syscall"

"github.com/pion/ice/v2"
"github.com/pion/ion-sfu/pkg/buffer"
Expand Down Expand Up @@ -82,16 +81,7 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
})
s.SetICEUDPMux(udpMux)
if !conf.Development {
val, err := checkUDPReadBuffer()
if err == nil {
if val < minUDPBufferSize {
logger.Warnw("UDP receive buffer is too small for a production set-up", nil,
"current", val,
"suggested", minUDPBufferSize)
} else {
logger.Debugw("UDP receive buffer size", "current", val)
}
}
checkUDPReadBuffer()
}
}
}
Expand Down Expand Up @@ -139,19 +129,3 @@ func (c *WebRTCConfig) SetBufferFactory(factory *buffer.Factory) {
c.BufferFactory = factory
c.SettingEngine.BufferFactory = factory.GetOrNew
}

func checkUDPReadBuffer() (int, error) {
conn, err := net.ListenUDP("udp4", nil)
if err != nil {
return 0, err
}
defer func() { _ = conn.Close() }()
_ = conn.SetReadBuffer(defaultUDPBufferSize)
fd, err := conn.File()
if err != nil {
return 0, nil
}
defer func() { _ = fd.Close() }()

return syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
}
40 changes: 40 additions & 0 deletions pkg/rtc/rtc_unix.go
@@ -0,0 +1,40 @@
//go:build !windows
// +build !windows

package rtc

import (
"net"
"syscall"

"github.com/livekit/livekit-server/pkg/logger"
)

func checkUDPReadBuffer() {
val, err := getUDPReadBuffer()
if err == nil {
if val < minUDPBufferSize {
logger.Warnw("UDP receive buffer is too small for a production set-up", nil,
"current", val,
"suggested", minUDPBufferSize)
} else {
logger.Debugw("UDP receive buffer size", "current", val)
}
}
}

func getUDPReadBuffer() (int, error) {
conn, err := net.ListenUDP("udp4", nil)
if err != nil {
return 0, err
}
defer func() { _ = conn.Close() }()
_ = conn.SetReadBuffer(defaultUDPBufferSize)
fd, err := conn.File()
if err != nil {
return 0, nil
}
defer func() { _ = fd.Close() }()

return syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
}
7 changes: 7 additions & 0 deletions pkg/rtc/rtc_windows.go
@@ -0,0 +1,7 @@
//go:build windows
// +build windows

package rtc

func checkUDPReadBuffer() {
}

0 comments on commit 6a88bcc

Please sign in to comment.