Example #1
0
func newConn(client *Client) (*Conn, error) {
	c := new(Conn)

	c.client = client
	c.cfg = client.cfg

	var n string = "tcp"
	if strings.Contains(c.cfg.BrokerAddr, "/") {
		n = "unix"
	}

	var err error
	if c.conn, err = net.Dial(n, c.cfg.BrokerAddr); err != nil {
		return nil, err
	}

	c.decoder = proto.NewDecoder(c.conn)

	c.grab = make(chan struct{}, 1)
	c.grab <- struct{}{}

	c.channels = make(map[string]*Channel)

	c.wait = make(chan *proto.Proto, 1)

	c.closed = false

	c.lastHeartbeat = 0

	c.keepAlive()

	go c.run()

	return c, nil
}
Example #2
0
func newConn(app *App, co net.Conn) *conn {
	c := new(conn)

	c.app = app
	c.c = co

	c.decoder = proto.NewDecoder(co)

	c.checkKeepAlive()

	c.channels = make(map[string]*channel)

	return c
}