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


Golang UnixConn.SetWriteBuffer方法代码示例

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


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

示例1: ServeUnix

// ServeUnix ...
func (service *UnixService) ServeUnix(conn *net.UnixConn) (err error) {
	if service.readBuffer != nil {
		if err = conn.SetReadBuffer(service.readBuffer.(int)); err != nil {
			return err
		}
	}
	if service.writeBuffer != nil {
		if err = conn.SetWriteBuffer(service.writeBuffer.(int)); err != nil {
			return err
		}
	}
	return ((*StreamService)(service)).Serve(conn)
}
开发者ID:henrypfhu,项目名称:hprose-go,代码行数:14,代码来源:unix_service.go

示例2: serveConn

func (s *Server) serveConn(in, out *net.UnixConn) {
	defer in.Close()
	defer out.Close()

	go func() {
		for {
			vals := []int{}
			incomingMu.Lock()
			for k := range incoming {
				vals = append(vals, k)
			}
			incomingMu.Unlock()
			sort.Ints(vals)
			log.Infof("the server: values still being waited on: %#v", vals)
			time.Sleep(5 * time.Second)
		}
	}()

	inBuff := bufio.NewReader(in)
	for {
		msg := &ClientMsg{}

		select {
		case err := <-s.decoder(msg, inBuff):
			if err != nil {
				log.Errorf("problem with client message: %s", err)
				continue
			}
		case <-time.After(30 * time.Second):
			return
		}

		incomingMu.Lock()
		incoming[int(msg.ID)] = true
		incomingMu.Unlock()

		if msg.Type == ClientKeepAlive {
			log.Infof("%#v", msg)
			continue
		}

		log.Infof("server received msg.ID = %d", msg.ID)
		reg, ok := s.registry[msg.Handler]
		if !ok {
			log.Infof("can not locate Handler %q", msg.Handler)
			continue
		}

		go func(msg *ClientMsg, reg *register) {
			srvMsg, err := reg.handler(msg)
			if err != nil {
				srvMsg.ID = msg.ID
				srvMsg.Data = []byte(fmt.Sprintf("handler(%s) error: %s", msg.Handler, err))
				reg.Lock()
				defer reg.Unlock()
				log.Infof("server: writing error response to client for ID: %d", msg.ID)
				if err := srvMsg.Encode(out); err != nil {
					log.Infof("cannot write to the client: %s", err)
				}
				return
			}
			reg.Lock()
			defer reg.Unlock()
			log.Infof("server: writing response to client for ID: %d", msg.ID)
			for {
				if err := srvMsg.Encode(out); err != nil {
					log.Infof("cannot write to the client: %s", err)
					s.bufferSize += serverMsgHeader + len(srvMsg.Data)
					if err := out.SetWriteBuffer(s.bufferSize); err != nil {
						log.Infof("cannot extend the write buffer, call will fail: %s", err)
						srvMsg = &ServerMsg{ID: msg.ID, Data: []byte("buffer cannot be made large enough to hold output message")}
						if err := srvMsg.Encode(out); err != nil {
							// TODO(johnsiilver): make this an exponential backoff with a time limit on iterations.
							log.Infof("can't send error message")
							continue
						}
						break
					}
					continue
				}
				break
			}
			incomingMu.Lock()
			delete(incoming, int(msg.ID))
			incomingMu.Unlock()
		}(msg, reg)
	}
}
开发者ID:johnsiilver,项目名称:golib,代码行数:88,代码来源:server.go


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