代码拉取完成,页面将自动刷新
同步操作将从 Hprose/hprose-go 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* hprose/stream_service.go *
* *
* hprose stream service for Go. *
* *
* LastModified: May 25, 2015 *
* Authors: Ma Bingyao <andot@hprose.com> *
* Ore_Ash <nanohugh@gmail.com> *
* *
\**********************************************************/
package hprose
import (
"net"
"time"
)
// StreamService is the base service for TcpService and UnixService
type StreamService struct {
*BaseService
timeout interface{}
readTimeout interface{}
readBuffer interface{}
writeTimeout interface{}
writeBuffer interface{}
}
// StreamContext is the hprose stream context for service
type StreamContext struct {
*BaseContext
net.Conn
}
func newStreamService() (service *StreamService) {
service = new(StreamService)
service.BaseService = NewBaseService()
return
}
// SetTimeout for stream service
func (service *StreamService) SetTimeout(d time.Duration) {
service.timeout = d
}
// SetReadTimeout for stream service
func (service *StreamService) SetReadTimeout(d time.Duration) {
service.readTimeout = d
}
// SetReadBuffer for stream service
func (service *StreamService) SetReadBuffer(bytes int) {
service.readBuffer = bytes
}
// SetWriteTimeout for stream service
func (service *StreamService) SetWriteTimeout(d time.Duration) {
service.writeTimeout = d
}
// SetWriteBuffer for stream service
func (service *StreamService) SetWriteBuffer(bytes int) {
service.writeBuffer = bytes
}
func (service *StreamService) serve(conn net.Conn) {
var data []byte
var err error
for {
if service.readTimeout != nil {
err = conn.SetReadDeadline(time.Now().Add(service.readTimeout.(time.Duration)))
}
if err == nil {
data, err = receiveDataOverStream(conn)
}
if err == nil {
data = service.Handle(data, &StreamContext{BaseContext: NewBaseContext(), Conn: conn})
if service.writeTimeout != nil {
err = conn.SetWriteDeadline(time.Now().Add(service.writeTimeout.(time.Duration)))
}
if err == nil {
err = sendDataOverStream(conn, data)
}
}
if err != nil {
conn.Close()
break
}
}
}
// Serve ...
func (service *StreamService) Serve(conn net.Conn) (err error) {
if service.timeout != nil {
if err = conn.SetDeadline(time.Now().Add(service.timeout.(time.Duration))); err != nil {
return err
}
}
go service.serve(conn)
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。