Skip to content

Commit

Permalink
Merge pull request #342 from cnlh/dev
Browse files Browse the repository at this point in the history
fix version v0.25.4
  • Loading branch information
ffdfgdfg authored Dec 29, 2019
2 parents 3875bbf + fe1c6e1 commit e69b596
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 29 deletions.
22 changes: 20 additions & 2 deletions build.android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@
#fyne-cross --targets=linux/amd64,windows/amd64,darwin/amd64 gui/npc/npc.go

cd /go
go get -u fyne.io/fyne fyne.io/fyne/cmd/fyne

apt-get install libegl1-mesa-dev libgles2-mesa-dev libx11-dev -y
#go get -u fyne.io/fyne/cmd/fyne fyne.io/fyne
mkdir -p /go/src/fyne.io
cd src/fyne.io
git clone https://github.com/fyne-io/fyne.git
cd fyne
git checkout v1.2.0
go install -v ./cmd/fyne
#fyne package -os android fyne.io/fyne/cmd/hello
echo "fyne install success"
mkdir -p /go/src/github.com/cnlh/nps
cp -R /app/* /go/src/github.com/cnlh/nps
cd /go/src/github.com/cnlh/nps
#go get -u fyne.io/fyne fyne.io/fyne/cmd/fyne
rm cmd/npc/sdk.go
#go get -u ./...
#go mod tidy
#rm -rf /go/src/golang.org/x/mobile
echo "tidy success"
cd /go/src/github.com/cnlh/nps
go mod vendor
cd vendor
cp -R * /go/src
cd ..
rm -rf vendor
#rm -rf ~/.cache/*
echo "vendor success"
cd gui/npc
#rm -rf /go/src/golang.org/x/mobile
#go get -u fyne.io/fyne/cmd/[email protected]
#export ANDROID_NDK_HOME=/usr/local/android_sdk/ndk-bundle
fyne package -appID org.nps.client -os android -icon ../../docs/logo.png
mv npc.apk /app/android_client.apk
25 changes: 2 additions & 23 deletions lib/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"os"
"sync/atomic"
"syscall"
"time"

"github.com/astaxie/beego/logs"
Expand Down Expand Up @@ -64,26 +63,6 @@ func NewMux(c net.Conn, connType string) *Mux {
return m
}

func getConnFd(c net.Conn) (fd *os.File, err error) {
switch c.(type) {
case *net.TCPConn:
fd, err = c.(*net.TCPConn).File()
if err != nil {
return
}
return
case *net.UDPConn:
fd, err = c.(*net.UDPConn).File()
if err != nil {
return
}
return
default:
err = errors.New("mux:unknown conn type, only tcp or kcp")
return
}
}

func (s *Mux) NewConn() (*conn, error) {
if s.IsClose {
return nil, errors.New("the mux has closed")
Expand Down Expand Up @@ -442,7 +421,7 @@ func (Self *bandwidth) SetCopySize(n uint16) {

func (Self *bandwidth) calcBandWidth() {
t := Self.readStart.Sub(Self.lastReadStart)
bufferSize, err := syscall.GetsockoptInt(int(Self.fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
bufferSize, err := sysGetSock(Self.fd)
//logs.Warn(bufferSize)
if err != nil {
logs.Warn(err)
Expand All @@ -451,7 +430,7 @@ func (Self *bandwidth) calcBandWidth() {
}
if Self.bufLength >= uint32(bufferSize) {
atomic.StoreUint64(&Self.readBandwidth, math.Float64bits(float64(Self.bufLength)/t.Seconds()))
// calculate the hole socket buffer, the time meaning to fill the buffer
// calculate the whole socket buffer, the time meaning to fill the buffer
//logs.Warn(Self.Get())
} else {
Self.calcThreshold = uint32(bufferSize)
Expand Down
15 changes: 11 additions & 4 deletions lib/mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/cnlh/nps/lib/common"
"github.com/cnlh/nps/lib/goroutine"
"github.com/xtaci/kcp-go"
"io"
"log"
"net"
Expand Down Expand Up @@ -33,7 +34,8 @@ func TestNewMux(t *testing.T) {
//poolConnCopy, _ := ants.NewPoolWithFunc(200000, common.copyConn, ants.WithNonblocking(false))
time.Sleep(time.Second * 3)
go func() {
m2 := NewMux(conn2, "tcp")
//m2 := NewMux(conn2, "tcp")
m2 := NewMux(conn2, "kcp")
for {
//logs.Warn("npc starting accept")
c, err := m2.Accept()
Expand Down Expand Up @@ -82,7 +84,8 @@ func TestNewMux(t *testing.T) {
}()

go func() {
m1 := NewMux(conn1, "tcp")
//m1 := NewMux(conn1, "tcp")
m1 := NewMux(conn1, "kcp")
l, err := net.Listen("tcp", "127.0.0.1:7777")
if err != nil {
logs.Warn(err)
Expand Down Expand Up @@ -144,12 +147,14 @@ func TestNewMux(t *testing.T) {

func server() {
var err error
l, err := net.Listen("tcp", "127.0.0.1:9999")
//l, err := net.Listen("tcp", "127.0.0.1:9999")
l, err := kcp.Listen("127.0.0.1:9999")
if err != nil {
logs.Warn(err)
}
go func() {
conn1, err = l.Accept()
logs.Info("accept", conn1)
if err != nil {
logs.Warn(err)
}
Expand All @@ -159,7 +164,9 @@ func server() {

func client() {
var err error
conn2, err = net.Dial("tcp", "127.0.0.1:9999")
//conn2, err = net.Dial("tcp", "127.0.0.1:9999")
logs.Warn("dial")
conn2, err = kcp.Dial("127.0.0.1:9999")
if err != nil {
logs.Warn(err)
}
Expand Down
46 changes: 46 additions & 0 deletions lib/mux/sysGetsock_nowindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// +build !windows

package mux

import (
"errors"
"github.com/xtaci/kcp-go"
"net"
"os"
"syscall"
)

func sysGetSock(fd *os.File) (bufferSize int, err error) {
if fd != nil {
return syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
} else {
return 1400 * 320, nil
}
}

func getConnFd(c net.Conn) (fd *os.File, err error) {
switch c.(type) {
case *net.TCPConn:
fd, err = c.(*net.TCPConn).File()
if err != nil {
return
}
return
case *net.UDPConn:
fd, err = c.(*net.UDPConn).File()
if err != nil {
return
}
return
case *kcp.UDPSession:
//fd, err = (*net.UDPConn)(unsafe.Pointer(c.(*kcp.UDPSession))).File()
//if err != nil {
// return
//}
// Todo
return
default:
err = errors.New("mux:unknown conn type, only tcp or kcp")
return
}
}
46 changes: 46 additions & 0 deletions lib/mux/sysGetsock_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// +build windows

package mux

import (
"errors"
"github.com/xtaci/kcp-go"
"net"
"os"
)

func sysGetSock(fd *os.File) (bufferSize int, err error) {
// https://github.com/golang/sys/blob/master/windows/syscall_windows.go#L1184
// not support, WTF???
// Todo
// return syscall.GetsockoptInt((syscall.Handle)(unsafe.Pointer(fd.Fd())), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
bufferSize = 10 * 1024 * 1024
return
}

func getConnFd(c net.Conn) (fd *os.File, err error) {
switch c.(type) {
case *net.TCPConn:
//fd, err = c.(*net.TCPConn).File()
//if err != nil {
// return
//}
return
case *net.UDPConn:
//fd, err = c.(*net.UDPConn).File()
//if err != nil {
// return
//}
return
case *kcp.UDPSession:
//fd, err = (*net.UDPConn)(unsafe.Pointer(c.(*kcp.UDPSession))).File()
//if err != nil {
// return
//}
// Todo
return
default:
err = errors.New("mux:unknown conn type, only tcp or kcp")
return
}
}

0 comments on commit e69b596

Please sign in to comment.