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


Golang UnixConn.Close方法代码示例

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


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

示例1: run_queue

func (r *fake_conn) run_queue(conn *net.UnixConn) {
	defer conn.Close()

	for {
		select {
		case <-r.end:
			return

		default:
			buffer := make([]byte, 1<<16)

			conn.SetReadDeadline(time.Now().Add(1000 * time.Millisecond))
			s, _, err := conn.ReadFrom(buffer)
			switch t_err := err.(type) {
			case nil:
			case net.Error:
				if !t_err.Timeout() {
					panic(err)
				}
			default:
				panic(err)
			}

			if s > 0 {
				r.queue <- buffer[0:s]
			}

		}
	}

}
开发者ID:nathanaelle,项目名称:syslog5424,代码行数:31,代码来源:listener_unixdgram.go

示例2: daemonIpcHandleConn

func daemonIpcHandleConn(conn *net.UnixConn) {
	defer cluegetterRecover("daemonIpcHandleConn")
	defer conn.Close()

	for {
		message, err := bufio.NewReader(conn).ReadString('\x00')
		if err != nil {
			if message != "" {
				Log.Info("Got %s on IPC Socket. Ignoring.", err.Error())
			}
			return
		}

		kv := strings.SplitN(message, " ", 2)
		handle := strings.TrimRightFunc(kv[0], func(v rune) bool { return v == '\x00' })
		callback := ipcHandlers[handle]
		v := ""
		if len(kv) > 1 {
			v = strings.TrimRightFunc(kv[1], func(v rune) bool { return v == '\x00' })
		}
		if callback == nil {
			Log.Debug("Received IPC message but no such pattern was registered, ignoring: <%s>%s", handle, v)
			return
		}

		callback(v)
	}
}
开发者ID:EaterOfCode,项目名称:ClueGetter,代码行数:28,代码来源:daemon.go

示例3: connectionHandler

func (i *instance) connectionHandler(c *net.UnixConn) {
	defer c.Close()
	for {
		req, err := readRequest(c)
		if err == io.EOF {
			return // Client closed the connection.
		}
		if err != nil {
			glog.Errorln("Failed to read a message from socket:", err)
		}
		f, t := funcMap[req.Type]
		if t != true {
			sendError(c, fmt.Errorf("unknown request type"))
			continue
		}
		resp, err := f(i, req)
		if err != nil {
			sendError(c, err)
			continue
		}
		err = writeResponse(c, resp)
		if err != nil {
			glog.Errorln("Failed to write a message to socket:", err)
			return
		}
	}
}
开发者ID:akramer,项目名称:lateral,代码行数:27,代码来源:server.go

示例4: handleSocket

// handle the socket connection. When data comes in on the socket write it
// to the channel so the serial port can see it. When data comes in over the
// channel translate the message and write it to the socket
func handleSocket(conn *net.UnixConn, ch chan []byte) {
	defer conn.Close()

	readCh := make(chan []byte)

	go socketRead(conn, readCh)

	for {
		select {
		case s := <-ch:
			{
				// map micro -> gui
				trans := mapMicro.ItemTranslate(string(s))
				_, err := conn.Write([]byte(trans))
				if err != nil {
					fmt.Println(err)
				}
			}
		case r := <-readCh:
			{
				ch <- r
			}
		case <-time.After(timeout):
			continue
		}
	}
}
开发者ID:jmore-reachtech,项目名称:io,代码行数:30,代码来源:sio.go

示例5: handleConn

func (srv *Server) handleConn(conn *net.UnixConn) {
	err := srv.doRequest(conn)
	resp := "Ok\n"
	if err != nil {
		resp = err.Error()
	}

	conn.Write(([]byte)(resp))
	conn.Close()
}
开发者ID:bboreham,项目名称:ambergris,代码行数:10,代码来源:server.go

示例6: HandleConnection

func HandleConnection(conn *net.UnixConn) {
	defer conn.Close()
	defer fmt.Println("closing...")
	r := bufio.NewReader(conn)
	w := bufio.NewWriter(conn)

	req, err := ReceiveRequest(r)
	if req != nil {
		fmt.Println("req.Name =", *req.Name)
		res := new(Response)
		res.Name = proto.String("hello hello!")
		SendResponse(w, res)
		w.Flush()
	} else {
		fmt.Println("Failed to receive a request:", err)
	}
}
开发者ID:yunabe,项目名称:codelab,代码行数:17,代码来源:server.go

示例7: handleConnection

func (ch *ctlSockHandler) handleConnection(conn *net.UnixConn) {
	buf := make([]byte, ReadBufSize)
	for {
		n, err := conn.Read(buf)
		if err == io.EOF {
			conn.Close()
			return
		} else if err != nil {
			tlog.Warn.Printf("ctlsock: Read error: %#v", err)
			conn.Close()
			return
		}
		if n == ReadBufSize {
			tlog.Warn.Printf("ctlsock: request too big (max = %d bytes)", ReadBufSize-1)
			conn.Close()
			return
		}
		buf = buf[:n]
		var in RequestStruct
		err = json.Unmarshal(buf, &in)
		if err != nil {
			tlog.Warn.Printf("ctlsock: Unmarshal error: %#v", err)
			errorMsg := ResponseStruct{
				ErrNo:   int32(syscall.EINVAL),
				ErrText: err.Error(),
			}
			sendResponse(&errorMsg, conn)
		}
		ch.handleRequest(&in, conn)
		// Restore original size.
		buf = buf[:cap(buf)]
	}
}
开发者ID:rfjakob,项目名称:gocryptfs,代码行数:33,代码来源:ctlsock_serve.go

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