Exemple #1
0
func (c *Client) writeLoop() {
	c.wg.Add(1)
	defer func() {
		c.wg.Done()
		c.Close()
	}()

	var (
		err    error
		putErr *rpc.PutError
		ctx    *rpc.Reply
		flag   []byte
		w      = bufio.NewWriter(c.conn)
		args   = make([]rpc.Item, 1)
	)

	for !c.state.IsClosed() {
		select {
		case err = <-c.errChan:
			if logex.Equal(err, io.EOF) {
				return
			}
			if err != nil {
				logex.Error(err)
			}
			args[0] = rpc.NewError(err)
			flag = rpc.FlagReply
		case putErr = <-c.putErrChan:
			if logex.Equal(putErr.Err, io.EOF) {
				return
			}
			if putErr.Err != nil {
				logex.Error(putErr)
			}
			args[0] = rpc.NewStruct(putErr)
			flag = rpc.FlagReply
		case ctx = <-c.incoming:
			args[0] = rpc.NewStruct(ctx)
			flag = rpc.FlagMsgPush
		case <-c.parentStopChan:
			return
		case <-c.stopChan:
			return
		}

		err = rpc.Write(w, flag, args)
		if err == nil {
			err = logex.Trace(w.Flush())
		}
		if err != nil {
			logex.Error(err)
			return
		}
	}
}
Exemple #2
0
func (a *Ins) Delete(topicName string) error {
	perr := rpc.NewError(nil)
	a.doReq(rpc.MDelete, []rpc.Item{
		rpc.NewString(topicName),
	}, perr)
	err := perr.Err()
	if err == nil {
		return nil
	}
	if err.Error() == ErrTopicNotFound.Error() {
		err = ErrTopicNotFound.Trace()
	}
	return err
}
Exemple #3
0
func (a *Ins) Ping(payload *rpc.String) error {
	perr := rpc.NewError(nil)
	a.doReq(rpc.MPing, []rpc.Item{payload}, perr)
	return perr.Err()
}