当前位置: 首页>>代码示例>>Golang>>正文


Golang Server.ReadTimeout方法代码示例

本文整理汇总了Golang中net/http.Server.ReadTimeout方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.ReadTimeout方法的具体用法?Golang Server.ReadTimeout怎么用?Golang Server.ReadTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net/http.Server的用法示例。


在下文中一共展示了Server.ReadTimeout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: serveSmart

func (c *conn) serveSmart() {
	defer func() {
		if err := recover(); err != nil {
			const size = 4096
			buf := make([]byte, size)
			buf = buf[:runtime.Stack(buf, false)]
			log.Printf("http: panic serving %v: %v\n%s", c.remoteAddr, err, buf)
		}
		if !c.hijacked() {
			c.close()
		}
	}()

	if tlsConn, ok := c.rwc.(*tls.Conn); ok {
		if d := c.server.ReadTimeout; d != 0 {
			c.rwc.SetReadDeadline(time.Now().Add(d))
		}
		if d := c.server.WriteTimeout; d != 0 {
			c.rwc.SetWriteDeadline(time.Now().Add(d))
		}
		if err := tlsConn.Handshake(); err != nil {
			return
		}
		c.tlsState = new(tls.ConnectionState)
		*c.tlsState = tlsConn.ConnectionState()
		if proto := c.tlsState.NegotiatedProtocol; validNPN(proto) {
			if fn := c.server.TLSNextProto[proto]; fn != nil {
				h := initNPNRequest{tlsConn, serverHandler{c.server}}
				fn(c.server, tlsConn, h)
			}
			return
		}
	}
	initial_bytes := make([]byte, start_bytes)
	// add smart detection
	n, err := c.rwc.Read(initial_bytes)
	if err != nil || n != start_bytes {
		return
	}

	if checkspdy(initial_bytes) {
		s := c.server
		z := new(http.Server)
		z.Addr = s.Addr
		z.Handler = s.inner_h
		z.ReadTimeout = s.ReadTimeout
		z.WriteTimeout = s.WriteTimeout
		z.MaxHeaderBytes = s.MaxHeaderBytes
		server_session := spdy.NewServerSession(NewSmartConn(c.rwc, initial_bytes), z)
		server_session.Serve()
		return
	}

	c2, err := c.server.newConn(NewSmartConn(c.rwc, initial_bytes))
	if err != nil {
		return
	}
	c2.serve()
}
开发者ID:nileshjagnik,项目名称:spdy_http_smartserver,代码行数:59,代码来源:smart_server.go

示例2: NewServer

/*
NewServer returns an intialized endlessServer Object. Calling Serve on it will
actually "start" the server.
*/
func NewServer(addr string, handler http.Handler) *endlessServer {
	var srv http.Server

	srv.Addr = addr
	srv.ReadTimeout = DefaultReadTimeOut
	srv.WriteTimeout = DefaultWriteTimeOut
	srv.MaxHeaderBytes = DefaultMaxHeaderBytes
	srv.Handler = handler

	return New(srv)
}
开发者ID:birkirb,项目名称:endless,代码行数:15,代码来源:endless.go

示例3: nextproto3

func nextproto3(s *Server, c *tls.Conn, h Handler) {
	z := new(http.Server)
	z.Addr = s.Addr
	z.Handler = s.inner_h
	z.ReadTimeout = s.ReadTimeout
	z.WriteTimeout = s.WriteTimeout
	z.MaxHeaderBytes = s.MaxHeaderBytes
	if z.Handler == nil {
		z.Handler = http.DefaultServeMux
	}
	server_session := spdy.NewServerSession(c, z)
	server_session.Serve()
}
开发者ID:nileshjagnik,项目名称:spdy_http_smartserver,代码行数:13,代码来源:smart_server.go


注:本文中的net/http.Server.ReadTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。