func UnmarshalPQMessage(msgId string, buf []byte) *PQMessage { p := PQMessage{Id: msgId} if err := p.Unmarshal(buf); err != nil { log.Error("Could not unmarshal message: %s", msgId) return nil } return &p }
// Connection dispatcher. Entry point to start connection handling. func (s *SessionHandler) DispatchConn() { go s.quitListenter() addr := s.conn.RemoteAddr().String() log.Info("Client connected: %s", addr) s.writeResponse(common.NewStrResponse("HELLO FIREMPQ-0.1")) for s.active { cmdTokens, err := s.tokenizer.ReadTokens(s.conn) if err == nil { err = s.processCmdTokens(cmdTokens) } if err != nil { errTxt := err.Error() if err != io.EOF && !(strings.Index(errTxt, "use of closed") > 0) { log.Error(errTxt) } break } } log.Debug("Client disconnected: %s", addr) }
func main() { // Initialize logging to a default INFO level to be able to log config error. log.InitLogging() err := conf.ReadConfig() if err != nil { log.Error(err.Error()) return } // Reinitialize log level according to the config data. log.InitLogging() iface := fmt.Sprintf("%s:%d", conf.CFG.Interface, conf.CFG.Port) srv, err := server.GetServer(server.SIMPLE_SERVER, iface) if err != nil { log.Critical("Error: %s", err.Error()) return } srv.Start() }
func (this *CommandServer) Start() { signal.Notify(this.signalChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) go this.waitForSignal() defer this.listener.Close() for { conn, err := this.listener.Accept() if err == nil { go this.handleConnection(conn) } else { select { case <-this.quitChan: this.Shutdown() return default: log.Error("Could not accept incoming request: %s", err.Error()) } } } }
// Adds message into expiration heap. Not thread safe! func (pq *PQueue) trackExpiration(msg *PQMessage) { ok := pq.expireHeap.PushItem(msg.Id, msg.CreatedTs+int64(pq.config.MsgTtl)) if !ok { log.Error("Error! Item already exists in the expire heap: %s", msg.Id) } }