Esempio n. 1
0
func NewServer(key int, h MsgHandler) (*Server, error) {
	var handler MsgHandler
	if h == nil {
		handler = &DefaultHandler{}
	} else {
		handler = h
	}

	key = ftok("/home/thor", key)
	q, err := sysv_mq.NewMessageQueue(&sysv_mq.QueueConfig{
		Key:     key,
		MaxSize: 1024,
		Mode:    sysv_mq.IPC_CREAT | 0644,
	})
	if err != nil {
		return nil, err
	}
	return &Server{
		q: q,
		h: handler,
	}, nil
}
Esempio n. 2
0
func main() {
	log.SetFlags(0)

	mq, err := sysv_mq.NewMessageQueue(&sysv_mq.QueueConfig{
		Key:     1234,
		MaxSize: 8 * 1024,
		Mode:    sysv_mq.IPC_CREAT | 0600,
	})
	if err != nil {
		log.Fatalln(err)
	}
	defer mq.Close()
	defer mq.Destroy()
	for {
		msg, typ, err := mq.ReceiveBytes(0, 0)
		if err != nil {
			log.Fatalln(err)
		}
		log.Println("received", typ, string(msg))
	}

}
Esempio n. 3
0
func main() {
	log.SetFlags(0)

	if len(os.Args) < 2 {
		log.Fatalln("expected mode")
	}

	mq, err := sysv_mq.NewMessageQueue(&sysv_mq.QueueConfig{
		Key:     1001,
		MaxSize: 8 * 1024,
		Mode:    sysv_mq.IPC_CREAT | 0600,
	})
	if err != nil {
		log.Fatalln(err)
	}
	defer mq.Close()

	switch os.Args[1] {
	case "server":
		server(mq)
	case "client":
		client(mq)
	}
}