예제 #1
0
// newClient creates new ready to communicate client.
func newClient(app *Application, s session) (*client, error) {
	c := client{
		UID:       ConnID(uuid.NewV4().String()),
		app:       app,
		sess:      s,
		closeChan: make(chan struct{}),
	}
	app.RLock()
	staleCloseDelay := app.config.StaleConnectionCloseDelay
	queueInitialCapacity := app.config.ClientQueueInitialCapacity
	c.maxQueueSize = app.config.ClientQueueMaxSize
	c.sendTimeout = app.config.MessageSendTimeout
	app.RUnlock()
	c.messages = bytequeue.New(queueInitialCapacity)
	go c.sendMessages()
	if staleCloseDelay > 0 {
		c.staleTimer = time.AfterFunc(staleCloseDelay, c.closeUnauthenticated)
	}
	return &c, nil
}
예제 #2
0
// newClient creates new ready to communicate client.
func newClient(app *Application, s session) (*client, error) {
	uid, err := uuid.NewV4()
	if err != nil {
		return nil, err
	}
	c := client{
		UID:       ConnID(uid.String()),
		app:       app,
		sess:      s,
		messages:  bytequeue.New(),
		closeChan: make(chan struct{}),
	}
	go c.sendMessages()
	app.RLock()
	staleCloseDelay := app.config.StaleConnectionCloseDelay
	c.maxQueueSize = app.config.MaxClientQueueSize
	app.RUnlock()
	if staleCloseDelay > 0 {
		c.staleTimer = time.AfterFunc(staleCloseDelay, c.closeUnauthenticated)
	}
	return &c, nil
}