當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.StartResponse方法代碼示例

本文整理匯總了Golang中net/textproto.Conn.StartResponse方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.StartResponse方法的具體用法?Golang Conn.StartResponse怎麽用?Golang Conn.StartResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/textproto.Conn的用法示例。


在下文中一共展示了Conn.StartResponse方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cmd

func cmd(c *textproto.Conn, expectedCode int, format string, args ...interface{}) error {
	id, err := c.Cmd(format, args...)
	if err != nil {
		return err
	}

	c.StartResponse(id)
	_, _, err = c.ReadResponse(expectedCode)
	c.EndResponse(id)

	return err
}
開發者ID:goutamtadi1,項目名稱:email-resource,代碼行數:12,代碼來源:smtpd_test.go

示例2: CloseConn

func CloseConn(conn *textproto.Conn) error {
	id, err := conn.Cmd("close")
	if err != nil {
		return err
	}
	conn.StartResponse(id)
	conn.EndResponse(id)
	err = conn.Close()
	if err != nil {
		return err
	}
	return nil
}
開發者ID:vincent-petithory,項目名稱:mpdclient,代碼行數:13,代碼來源:client.go

示例3: writeIdleResponse

func (s *server) writeIdleResponse(p *textproto.Conn, id uint, quit chan bool, subsystems []string) {
	p.StartResponse(id)
	defer p.EndResponse(id)

	req := &idleRequest{
		endTokenc:  make(chan uint),
		eventc:     make(chan string, 1),
		subsystems: subsystems,
	}
	s.idleStartc <- req
	token := <-req.endTokenc
	select {
	case name := <-req.eventc:
		p.PrintfLine("changed: %s", name)
		p.PrintfLine("OK")
		<-quit
	case <-quit:
		p.PrintfLine("OK")
	}
	s.idleEndc <- token
}
開發者ID:zefer,項目名稱:gompd,代碼行數:21,代碼來源:server.go

示例4: playScriptAgainst

// playScriptAgainst an existing connection, does not handle server greeting
func playScriptAgainst(t *testing.T, c *textproto.Conn, script []scriptStep) error {
	for i, step := range script {
		id, err := c.Cmd(step.send)
		if err != nil {
			return fmt.Errorf("Step %d, failed to send %q: %v", i, step.send, err)
		}

		c.StartResponse(id)
		code, msg, err := c.ReadResponse(step.expect)
		if err != nil {
			err = fmt.Errorf("Step %d, sent %q, expected %v, got %v: %q",
				i, step.send, step.expect, code, msg)
		}
		c.EndResponse(id)

		if err != nil {
			// Return after c.EndResponse so we don't hang the connection
			return err
		}
	}
	return nil
}
開發者ID:barbourkd,項目名稱:inbucket,代碼行數:23,代碼來源:handler_test.go

示例5: handleConnection

func (s *server) handleConnection(p *textproto.Conn) {
	id := p.Next()
	p.StartRequest(id)
	p.EndRequest(id)
	p.StartResponse(id)
	p.PrintfLine("OK MPD gompd0.1")
	p.EndResponse(id)

	endIdle := make(chan bool)
	inIdle := false
	defer p.Close()
	for {
		id := p.Next()
		p.StartRequest(id)
		req, err := s.readRequest(p)
		if err != nil {
			return
		}
		// We need to do this inside request because idle response
		// may not have ended yet, but it will end after the following.
		if inIdle {
			endIdle <- true
		}
		p.EndRequest(id)

		if req.typ == idle {
			inIdle = true
			go s.writeIdleResponse(p, id, endIdle, req.args[1:])
			// writeIdleResponse does it's own StartResponse/EndResponse
			continue
		}

		p.StartResponse(id)
		if inIdle {
			inIdle = false
		}
		switch req.typ {
		case noIdle:
		case commandListOk:
			var ok, closed bool
			ok = true
			for _, args := range req.cmdList {
				ok, closed = s.writeResponse(p, args, "list_OK")
				if closed {
					return
				}
				if !ok {
					break
				}
			}
			if ok {
				p.PrintfLine("OK")
			}
		case simple:
			if _, closed := s.writeResponse(p, req.args, "OK"); closed {
				return
			}
		}
		p.EndResponse(id)
	}
}
開發者ID:zefer,項目名稱:gompd,代碼行數:61,代碼來源:server.go


注:本文中的net/textproto.Conn.StartResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。