| 1234567891011121314151617181920212223242526272829303132333435 |
- package tinymq
- import (
- "fmt"
- "log"
- "net"
- "strconv"
- "git.me9.top/git/tinymq/config"
- "git.me9.top/git/tinymq/conn"
- "git.me9.top/git/tinymq/conn/tcp2"
- "git.me9.top/git/tinymq/conn/ws2"
- )
- // 建立连接,输出实际代码实现的协议
- // 会一直阻塞直到连接结束
- func Dail(host *conn.HostInfo, cf *config.Config) (rawProto string, conn conn.Connect, err error) {
- addr := net.JoinHostPort(host.Host, strconv.Itoa(int(host.Port)))
- if host.Version == ws2.VERSION && (host.Proto == ws2.PROTO || host.Proto == ws2.PROTO_STL) {
- rawProto = ws2.PROTO
- if cf.PrintMsg {
- log.Println("[ConnectToServer] connecting:", host.Proto, addr, host.Path, host.Hash)
- }
- conn, err = ws2.Dial(cf, host.Proto, addr, host.Path, host.Hash)
- } else if host.Version == tcp2.VERSION && host.Proto == tcp2.PROTO {
- rawProto = tcp2.PROTO
- if cf.PrintMsg {
- log.Println("[ConnectToServer] connecting:", host.Proto, addr, host.Hash)
- }
- conn, err = tcp2.Dial(cf, addr, host.Hash)
- } else {
- err = fmt.Errorf("not correct protocol and version found in: %+v", host)
- }
- return
- }
|