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


Golang textproto.NewConn函数代码示例

本文整理汇总了Golang中net/textproto.NewConn函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConn函数的具体用法?Golang NewConn怎么用?Golang NewConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: getTestClient

// Returns a test client and the end of a connection pipe
func getTestClient() (*transaction, *textproto.Conn) {
	sc, cc := net.Pipe()
	sconn, cconn := textproto.NewConn(sc), textproto.NewConn(cc)

	client := &transaction{
		Mode:    stateHELO,
		Message: new(mailbox.Message),
		text:    sconn,
		host: &mockHost{
			QueryMock: func(addr *mail.Address) int {
				switch strings.Split(addr.Address, "@")[0] {
				case "not_found":
					return mailbox.QueryNotFound
				case "not_local":
					return mailbox.QueryNotLocal
				case "success":
					return mailbox.QuerySuccess
				}

				return mailbox.QueryError
			},
			SettingsMock: func() jamon.Group { return jamon.Group{} },
			DigestMock:   func(c *transaction) error { return nil },
		},
	}

	return client, cconn
}
开发者ID:gbbr,项目名称:gomez,代码行数:29,代码来源:commands_test.go

示例2: DialTimeout

// DialTimeout initializes the connection to the specified ftp server address.
//
// It is generally followed by a call to Login() as most FTP commands require
// an authenticated user.
func DialTimeout(addr string, timeout time.Duration) (*ServerConn, error) {
	tconn, err := net.DialTimeout("tcp", addr, timeout)
	if err != nil {
		return nil, err
	}

	conn := textproto.NewConn(tconn)

	a := strings.SplitN(addr, ":", 2)
	c := &ServerConn{
		conn:     conn,
		host:     a[0],
		timeout:  timeout,
		features: make(map[string]string),
	}

	_, _, err = c.conn.ReadResponse(StatusReady)
	if err != nil {
		c.Quit()
		return nil, err
	}

	err = c.feat()
	if err != nil {
		c.Quit()
		return nil, err
	}

	return c, nil
}
开发者ID:YunmiaoGames,项目名称:ftp,代码行数:34,代码来源:ftp.go

示例3: SendStartTLS

func SendStartTLS(conn net.Conn, config *tls.Config) (econn *textproto.Conn, state tls.ConnectionState, err error) {
	_, err = io.WriteString(conn, "STARTTLS\r\n")
	if err == nil {
		r := bufio.NewReader(conn)
		var line string
		line, err = r.ReadString(10)
		if strings.HasPrefix(line, "382 ") {
			// we gud
			tconn := tls.Client(conn, config)
			err = tconn.Handshake()
			if err == nil {
				// tls okay
				state = tconn.ConnectionState()
				econn = textproto.NewConn(tconn)
			} else {
				log.Println("STARTTLS failed", err)
				tconn.Close()
			}
		} else {
			// it won't do tls
			err = TlsNotSupported
		}
		r = nil
	}
	return
}
开发者ID:ZiRo-,项目名称:srndv2,代码行数:26,代码来源:tls.go

示例4: syncPull

// do a oneshot pull based sync with another server
func (self NNTPDaemon) syncPull(proxy_type, proxy_addr, remote_addr string) {
	c, err := self.dialOut(proxy_type, proxy_addr, remote_addr)
	if err == nil {
		conn := textproto.NewConn(c)
		// we connected
		nntp := createNNTPConnection()
		nntp.name = remote_addr + "-sync"
		// do handshake
		_, reader, err := nntp.outboundHandshake(conn)
		if reader {
			// we can do it
			err = nntp.scrapeServer(self, conn)
			if err == nil {
				log.Println(nntp.name, "Scrape successful")
				nntp.Quit(conn)
			} else {
				log.Println(nntp.name, "scrape failed", err)
				conn.Close()
			}
		} else if err == nil {
			// we can't do it
			log.Println(nntp.name, "does not support reader mode, cancel scrape")
			nntp.Quit(conn)
		} else {
			// error happened
			log.Println(nntp.name, "error occurred when scraping", err)
		}
	}
}
开发者ID:4cdn,项目名称:srndv2,代码行数:30,代码来源:daemon.go

示例5: TestClientNotify

// It should reply using the attached network connection
func TestClientNotify(t *testing.T) {
	sc, cc := net.Pipe()
	cconn := textproto.NewConn(cc)

	testClient := &transaction{text: textproto.NewConn(sc)}

	go testClient.notify(reply{200, "Hello"})
	msg, err := cconn.ReadLine()
	if err != nil {
		t.Errorf("Error reading end of pipe (%s)", err)
	}

	if msg != "200 Hello" {
		t.Errorf("Got '%s' but expected '%s'", msg, "200 Hello")
	}
}
开发者ID:gbbr,项目名称:gomez,代码行数:17,代码来源:transaction_test.go

示例6: persistFeed

func (self NNTPDaemon) persistFeed(conf FeedConfig, mode string) {
	for {
		if self.running {
			conn, err := self.dialOut(conf.proxy_type, conf.proxy_addr, conf.addr)
			if err != nil {
				time.Sleep(time.Second * 5)
				continue
			}
			nntp := createNNTPConnection()
			nntp.policy = conf.policy
			nntp.name = conf.name + "-" + mode
			c := textproto.NewConn(conn)
			stream, reader, err := nntp.outboundHandshake(c)
			if err == nil {
				if mode == "reader" && !reader {
					log.Println(nntp.name, "we don't support reader on this feed, dropping")
					return
				}
				self.register_outfeed <- nntp
				nntp.runConnection(self, false, stream, reader, mode, c)
				self.deregister_outfeed <- nntp

			} else {
				log.Println("error doing outbound hanshake", err)
			}
		}
		time.Sleep(1 * time.Second)
	}
}
开发者ID:4cdn,项目名称:srndv2,代码行数:29,代码来源:daemon.go

示例7: connect

//Connect establishes a connection with the local Freeswitch server.
func (client *Client) connect() (err error) {
	//Connect to Freeswitch Event Socket.
	conn, err := net.DialTimeout("tcp", client.addr, time.Duration(5*time.Second))
	if err != nil {
		return
	}
	//Convert the raw TCP connection to a textproto connection.
	client.connMu.Lock()
	defer client.connMu.Unlock()
	if client.eventConn != nil {
		client.eventConn.Close()
	}
	client.eventConn = textproto.NewConn(conn)

	//Read the welcome message.
	resp, err := client.eventConn.ReadMIMEHeader()
	if err != nil {
		return
	}

	//Send authentication request to server.
	client.eventConn.PrintfLine("auth %s\r\n", client.password)
	if resp, err = client.eventConn.ReadMIMEHeader(); err != nil {
		return
	}

	//Check the command was processed OK.
	if resp.Get("Reply-Text") == "+OK accepted" {
		return
	}

	return errors.New("Authentication failed: " + resp.Get("Reply-Text"))
}
开发者ID:mehulsbhatt,项目名称:fsclient,代码行数:34,代码来源:fsclient.go

示例8: NewAmiConn

func NewAmiConn(ctx context.Context, conn io.ReadWriteCloser, c *AmiServer) *AmiConn {
	var (
		sctx   context.Context
		cancel context.CancelFunc
	)
	sctx, cancel = context.WithCancel(ctx)
	amic := &AmiConn{
		Context:   sctx,
		cancel:    cancel,
		uuid:      uuid.New("C"),
		srv:       c,
		messageCh: make(chan textproto.MIMEHeader, 100),
		connRaw:   conn,
		conn:      textproto.NewConn(conn),
	}
	go amic.doHeartBeat()
	go amic.doReader()
	go amic.doWriter()
	go func(amic *AmiConn) {
		<-amic.Done()
		amic.Close()
	}(amic)
	amic.conn.PrintfLine("Asterisk Call Manager")
	return amic
}
开发者ID:party79,项目名称:gami,代码行数:25,代码来源:mock.go

示例9: TestServerCreateClient

// Should create a client that picks up commands
// and greet the connection with 220 status
func TestServerCreateClient(t *testing.T) {
	var wg sync.WaitGroup

	cc, sc := mocks.Pipe(
		&mocks.Conn{RAddr: "1.1.1.1:123"},
		&mocks.Conn{RAddr: "1.1.1.1:123"},
	)

	cconn := textproto.NewConn(cc)

	testServer := server{
		spec: commandSpec{
			"EXIT": func(ctx *transaction, params string) error {
				return io.EOF
			},
		},
		config: jamon.Group{"host": "mecca.local"},
	}

	wg.Add(1)

	go func() {
		testServer.createTransaction(sc)
		wg.Done()
	}()

	_, _, err := cconn.ReadResponse(220)
	if err != nil {
		t.Errorf("Expected code 220 but got %+v", err)
	}

	cconn.PrintfLine("EXIT")
	wg.Wait()
}
开发者ID:gbbr,项目名称:gomez,代码行数:36,代码来源:server_test.go

示例10: newOutboundConn

// create a new connection from an established connection
func newOutboundConn(c net.Conn, s *Server, conf *config.FeedConfig) Conn {

	sname := s.Name()

	if len(sname) == 0 {
		sname = "nntp.anon.tld"
	}
	storage := s.Storage
	if storage == nil {
		storage = store.NewNullStorage()
	}
	return &v1OBConn{
		conf: conf,
		C: v1Conn{
			hooks: s,
			state: ConnState{
				FeedName: conf.Name,
				HostName: conf.Addr,
				Open:     true,
			},
			serverName: sname,
			storage:    storage,
			C:          textproto.NewConn(c),
			conn:       c,
			hdrio:      message.NewHeaderIO(),
		},
	}
}
开发者ID:majestrate,项目名称:nntpchan,代码行数:29,代码来源:conn_v1.go

示例11: serve

func (s *Server) serve(conn net.Conn) {
	c := textproto.NewConn(conn)

	// state controlled processing here

	for {
		cr, err := NewCommandRequest(c)
		if err != nil {
			log.Println(err)
			continue
		}

		// start of a muxer
		// s.handler[verb](c)

		sr := &StatusResponse{}

		if s.mux == nil {
			panic("awp: no servemux specified")
		}
		s.mux.ServeAWP(cr, sr)

		c.PrintfLine("%d %s\r\n", sr.Code, sr.Status)

	}
}
开发者ID:JalfResi,项目名称:commandserver,代码行数:26,代码来源:server.go

示例12: NewTestConnection

// NewTestConnection is for test facilitation.
// Creates a server and then dials the server, returning the connection,
// allowing test to inject state and wait for an expected response
// The connection must be started manually with `go conn.Start()`
// once desired state has been injected
func NewTestConnection(transcript io.Writer) (s *Server, clientConn *textproto.Conn, serverConn *conn.Conn, server *Server, err error) {
	mStore := mailstore.NewDummyMailstore()
	s = NewServer(mStore)
	s.Addr = ":10143"
	s.Transcript = transcript
	if err = s.Listen(); err != nil {
		return nil, nil, nil, nil, err
	}

	c, err := net.Dial("tcp4", "localhost:10143")
	if err != nil {
		return nil, nil, nil, nil, err
	}

	textc := textproto.NewConn(c)
	clientConn = textc

	conn, err := s.listener.Accept()
	if err != nil {
		return nil, nil, nil, nil, err
	}
	fmt.Fprintf(s.Transcript, "Client connected\n")
	serverConn, err = s.newConn(conn)

	return s, clientConn, serverConn, s, nil
}
开发者ID:CIS-rdbrown,项目名称:imap-server,代码行数:31,代码来源:server.go

示例13: upgradeTLS

// handle inbound STARTTLS command
func upgradeTLS(c *v1Conn, line string, hooks EventHooks) (err error) {
	if c.tlsConfig == nil {
		err = c.printfLine("%s TLS not supported", RPL_TLSRejected)
	} else {
		err = c.printfLine("%s Continue with TLS Negotiation", RPL_TLSContinue)
		if err == nil {
			tconn := tls.Server(c.conn, c.tlsConfig)
			err = tconn.Handshake()
			if err == nil {
				// successful tls handshake
				c.tlsConn = tconn
				c.C = textproto.NewConn(c.tlsConn)
			} else {
				// tls failed
				log.WithFields(log.Fields{
					"pkg":   "nntp-conn",
					"addr":  c.conn.RemoteAddr(),
					"state": c.state,
				}).Warn("TLS Handshake failed ", err)
				// fall back to plaintext
				err = nil
			}
		}
	}
	return
}
开发者ID:majestrate,项目名称:nntpchan,代码行数:27,代码来源:conn_v1.go

示例14: NewLilyConn

func NewLilyConn(address string) *LilyConn {
	localAddress, _ := net.ResolveTCPAddr("0.0.0.0:0")
	lilyAddress, err := net.ResolveTCPAddr(address)

	if err != nil {
		logger.Logf("failed resolving %s: %s", address, err)
		return nil
	}

	tcpConn, err := net.DialTCP("tcp", localAddress, lilyAddress)

	if err != nil {
		logger.Logf("failed connecting to %s: %s", address, err)
		return nil
	}

	var newLilyConn LilyConn

	newLilyConn.tcpConn = tcpConn
	newLilyConn.textConn = textproto.NewConn(tcpConn)
	newLilyConn.incomingChannel = make(chan *LilyMessage, 100)
	newLilyConn.outgoingChannel = make(chan *LilyMessage, 100)
	newLilyConn.handleMap = make(map[string]*LilyHandle)

	newLilyConn.SendOptions()

	go newLilyConn.Dispatch()

	return &newLilyConn
}
开发者ID:strtok,项目名称:lilirc,代码行数:30,代码来源:lily.go

示例15: newInboundConn

func newInboundConn(s *Server, c net.Conn) Conn {
	sname := s.Name
	if len(sname) == 0 {
		sname = "nntp.anon.tld"
	}
	storage := s.Storage
	if storage == nil {
		storage = store.NewNullStorage()
	}
	return &v1IBConn{
		C: v1Conn{
			authenticated: true,
			serverName:    sname,
			storage:       storage,
			acceptor:      s.Acceptor,
			hdrio:         message.NewHeaderIO(),
			C:             textproto.NewConn(c),
			conn:          c,
			cmds: map[string]lineHandlerFunc{
				"IHAVE":        nntpRecvArticle,
				"POST":         nntpPostArticle,
				"MODE":         switchModeInbound,
				"QUIT":         quitConnection,
				"CAPABILITIES": sendCapabilities,
				"CHECK":        streamingLine,
				"TAKETHIS":     streamingLine,
				"LIST":         newsgroupList,
				"GROUP":        switchNewsgroup,
			},
		},
	}
}
开发者ID:ZiRo-,项目名称:srndv2,代码行数:32,代码来源:conn_v1.go


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