mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
some cleanup, and remove the test 'testwebocket2' package at all; A lower-level fast websocket impl based on gobwas/ws will be published on a different repo, it is a WIP
Former-commit-id: b680974c593196ce20865ed12778929ced6afea1
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/websocket2"
|
||||
"github.com/kataras/iris/websocket"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -19,6 +19,7 @@ var (
|
||||
)
|
||||
|
||||
const totalClients = 16000 // max depends on the OS.
|
||||
const verbose = true
|
||||
|
||||
var connectionFailures uint64
|
||||
|
||||
@@ -42,7 +43,7 @@ func collectError(op string, err error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("--------======Running tests...==========--------------")
|
||||
log.Println("--Running...")
|
||||
var err error
|
||||
f, err = os.Open("./test.data")
|
||||
if err != nil {
|
||||
@@ -85,11 +86,11 @@ func main() {
|
||||
log.Println()
|
||||
|
||||
if connectionFailures > 0 {
|
||||
log.Printf("Finished with %d/%d connection failures. Please close the server-side manually.\n", connectionFailures, totalClients)
|
||||
log.Printf("Finished with %d/%d connection failures.", connectionFailures, totalClients)
|
||||
}
|
||||
|
||||
if n := len(connectErrors); n > 0 {
|
||||
log.Printf("Finished with %d connect errors:\n", n)
|
||||
log.Printf("Finished with %d connect errors: ", n)
|
||||
var lastErr error
|
||||
var sameC int
|
||||
|
||||
@@ -123,7 +124,7 @@ func main() {
|
||||
if n := len(disconnectErrors); n > 0 {
|
||||
log.Printf("Finished with %d disconnect errors\n", n)
|
||||
for i, err := range disconnectErrors {
|
||||
if err == websocket.ErrAlreadyDisconnected {
|
||||
if err == websocket.ErrAlreadyDisconnected && i > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ func main() {
|
||||
log.Println("ALL OK.")
|
||||
}
|
||||
|
||||
log.Println("--------================--------------")
|
||||
log.Println("--Finished.")
|
||||
}
|
||||
|
||||
func connect(wg *sync.WaitGroup, alive time.Duration) {
|
||||
@@ -153,12 +154,17 @@ func connect(wg *sync.WaitGroup, alive time.Duration) {
|
||||
|
||||
disconnected := false
|
||||
c.OnDisconnect(func() {
|
||||
// log.Printf("I am disconnected after [%s].\n", alive)
|
||||
if verbose {
|
||||
log.Printf("I am disconnected after [%s].\n", alive)
|
||||
}
|
||||
|
||||
disconnected = true
|
||||
})
|
||||
|
||||
c.On("chat", func(message string) {
|
||||
// log.Printf("\n%s\n", message)
|
||||
if verbose {
|
||||
log.Printf("\n%s\n", message)
|
||||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/websocket2"
|
||||
"github.com/kataras/iris/websocket"
|
||||
)
|
||||
|
||||
const totalClients = 16000 // max depends on the OS.
|
||||
const http = true
|
||||
const verbose = true
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -62,32 +62,9 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
if http {
|
||||
app := iris.New()
|
||||
app.Get("/", ws.Handler())
|
||||
app.Run(iris.Addr(":8080"))
|
||||
return
|
||||
}
|
||||
|
||||
// ln, err := net.Listen("tcp", ":8080")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// defer ln.Close()
|
||||
// for {
|
||||
// conn, err := ln.Accept()
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
// go func() {
|
||||
// err = ws.HandleConn(conn)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
// }()
|
||||
// }
|
||||
app := iris.New()
|
||||
app.Get("/", ws.Handler())
|
||||
app.Run(iris.Addr(":8080"))
|
||||
|
||||
}
|
||||
|
||||
@@ -103,7 +80,9 @@ var count uint64
|
||||
|
||||
func handleDisconnect(c websocket.Connection) {
|
||||
atomic.AddUint64(&count, 1)
|
||||
// log.Printf("client [%s] disconnected!\n", c.ID())
|
||||
if verbose {
|
||||
log.Printf("client [%s] disconnected!\n", c.ID())
|
||||
}
|
||||
}
|
||||
|
||||
func handleErr(c websocket.Connection, err error) {
|
||||
|
||||
Reference in New Issue
Block a user