本文整理汇总了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)
}
示例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)
}
}