Makis Maropoulos 2016-06-16 00:13:56 +03:00
parent 6a77c2ed22
commit 8cddc68993
4 changed files with 18 additions and 19 deletions

View File

@ -8,14 +8,14 @@ import (
// Currently only these 5 values are used for real // Currently only these 5 values are used for real
const ( const (
// DefaultWriteTimeout 10 * time.Second // DefaultWriteTimeout 30 * time.Second
DefaultWriteTimeout = 10 * time.Second DefaultWriteTimeout = 30 * time.Second
// DefaultPongTimeout 60 * time.Second // DefaultPongTimeout 120 * time.Second
DefaultPongTimeout = 60 * time.Second DefaultPongTimeout = 120 * time.Second
// DefaultPingPeriod (DefaultPongTimeout * 9) / 10 // DefaultPingPeriod (DefaultPongTimeout * 9) / 10
DefaultPingPeriod = (DefaultPongTimeout * 9) / 10 DefaultPingPeriod = (DefaultPongTimeout * 9) / 10
// DefaultMaxMessageSize 1024 // DefaultMaxMessageSize 2048
DefaultMaxMessageSize = 1024 DefaultMaxMessageSize = 2048
) )
// //
@ -23,17 +23,17 @@ const (
// Websocket the config contains options for 'websocket' package // Websocket the config contains options for 'websocket' package
type Websocket struct { type Websocket struct {
// WriteTimeout time allowed to write a message to the connection. // WriteTimeout time allowed to write a message to the connection.
// Default value is 10 * time.Second // Default value is 30 * time.Second
WriteTimeout time.Duration WriteTimeout time.Duration
// PongTimeout allowed to read the next pong message from the connection // PongTimeout allowed to read the next pong message from the connection
// Default value is 60 * time.Second // Default value is 120 * time.Second
PongTimeout time.Duration PongTimeout time.Duration
// PingPeriod send ping messages to the connection with this period. Must be less than PongTimeout // PingPeriod send ping messages to the connection with this period. Must be less than PongTimeout
// Default value is (PongTimeout * 9) / 10 // Default value is (PongTimeout * 9) / 10
PingPeriod time.Duration PingPeriod time.Duration
// MaxMessageSize max message size allowed from connection // MaxMessageSize max message size allowed from connection
// Default value is 1024 // Default value is 2048
MaxMessageSize int MaxMessageSize int64
// Endpoint is the path which the websocket server will listen for clients/connections // Endpoint is the path which the websocket server will listen for clients/connections
// Default value is empty string, if you don't set it the Websocket server is disabled. // Default value is empty string, if you don't set it the Websocket server is disabled.
Endpoint string Endpoint string

View File

@ -359,8 +359,8 @@ func (s *Server) serve(l net.Listener) error {
return s.Server.Serve(s.listener) return s.Server.Serve(s.listener)
} }
// open opens/starts/runs/listens (to) the server, listen tls if Cert && Key is registed, listenUNIX if Mode is registed, otherwise listen // Open opens/starts/runs/listens (to) the server, listen tls if Cert && Key is registed, listenUNIX if Mode is registed, otherwise listen
func (s *Server) open() error { func (s *Server) Open() error {
if s.started { if s.started {
return errServerAlreadyStarted.Return() return errServerAlreadyStarted.Return()
} }

View File

@ -171,7 +171,7 @@ func (s *Framework) prepareTemplates() {
func (s *Framework) openServer() (err error) { func (s *Framework) openServer() (err error) {
s.initialize() s.initialize()
s.Plugins.DoPreListen(s) s.Plugins.DoPreListen(s)
if err = s.HTTPServer.open(); err == nil { if err = s.HTTPServer.Open(); err == nil {
// print the banner // print the banner
if !s.Config.DisableBanner { if !s.Config.DisableBanner {
s.Logger.PrintBanner(banner, s.Logger.PrintBanner(banner,

View File

@ -8,7 +8,6 @@ import (
"strconv" "strconv"
"github.com/iris-contrib/websocket" "github.com/iris-contrib/websocket"
"github.com/kataras/iris/config"
"github.com/kataras/iris/utils" "github.com/kataras/iris/utils"
) )
@ -80,12 +79,12 @@ func newConnection(websocketConn *websocket.Conn, s *server) *connection {
} }
func (c *connection) write(messageType int, data []byte) error { func (c *connection) write(messageType int, data []byte) error {
c.underline.SetWriteDeadline(time.Now().Add(config.DefaultWriteTimeout)) c.underline.SetWriteDeadline(time.Now().Add(c.server.config.WriteTimeout))
return c.underline.WriteMessage(messageType, data) return c.underline.WriteMessage(messageType, data)
} }
func (c *connection) writer() { func (c *connection) writer() {
ticker := time.NewTicker(config.DefaultPingPeriod) ticker := time.NewTicker(c.server.config.PingPeriod)
defer func() { defer func() {
ticker.Stop() ticker.Stop()
c.underline.Close() c.underline.Close()
@ -118,10 +117,10 @@ func (c *connection) reader() {
}() }()
conn := c.underline conn := c.underline
conn.SetReadLimit(config.DefaultMaxMessageSize) conn.SetReadLimit(c.server.config.MaxMessageSize)
conn.SetReadDeadline(time.Now().Add(config.DefaultPongTimeout)) conn.SetReadDeadline(time.Now().Add(c.server.config.PongTimeout))
conn.SetPongHandler(func(s string) error { conn.SetPongHandler(func(s string) error {
conn.SetReadDeadline(time.Now().Add(config.DefaultPongTimeout)) conn.SetReadDeadline(time.Now().Add(c.server.config.PongTimeout))
return nil return nil
}) })