当前位置: 首页>>代码示例>>Golang>>正文


Golang bitmonster.Socket类代码示例

本文整理汇总了Golang中github.com/desertbit/bitmonster.Socket的典型用法代码示例。如果您正苦于以下问题:Golang Socket类的具体用法?Golang Socket怎么用?Golang Socket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Socket类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: setCachedCurrentUser

func setCachedCurrentUser(s *bitmonster.Socket, user *User) {
	// Set the socket value.
	s.SetValue(cacheUserSocketValueKey, user)

	// Remove the cached value after the timeout.
	s.DeleteValueAfterTimeout(cacheUserSocketValueKey, clearCacheInterval)
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:7,代码来源:cache.go

示例2: checkSocketAuthentication

func checkSocketAuthentication(s *bitmonster.Socket) {
	// Get the auth socket value.
	av := getAuthSocketValue(s)
	if av == nil {
		return
	}

	// Skip if not authenticated.
	if !av.isAuth {
		return
	}

	// Debug log.
	log.L.WithFields(logrus.Fields{
		"remoteAddress": s.RemoteAddr(),
	}).Debugf("auth: reauthentication requested")

	// Trigger the event to reauthenticate.
	eventReauth.TriggerSocket(s)

	// Start a timeout to logout the socket session.
	av.reauthTimer = time.AfterFunc(reauthTimeout, func() {
		// Reset the socket authentication values.
		resetAuthSocketValue(s)
	})
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:26,代码来源:auth.go

示例3: getCachedCurrentUser

// getCachedCurrentUser returns the current cached user value or nil.
func getCachedCurrentUser(s *bitmonster.Socket) *User {
	// Obtain the user from the cache if present.
	userI := s.Value(cacheUserSocketValueKey)
	if userI == nil {
		return nil
	}

	// Assertion.
	user, ok := userI.(*User)
	if !ok {
		return nil
	}

	return user
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:16,代码来源:cache.go

示例4: getAuthSocketValue

// getAuthSocketValue obtains the authentication socket value from the socket.
// If not present, then this function creates the value.
func getAuthSocketValue(s *bitmonster.Socket) *authSocketValue {
	// Get or create the value.
	v := s.Value(authSocketValueKey, func() interface{} {
		// Not present. Create it.
		return newAuthSocketValue()
	})

	// Cast.
	av, ok := v.(*authSocketValue)
	if !ok {
		return nil
	}

	return av
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:17,代码来源:auth.go

示例5: onNewSocket

func onNewSocket(s *bitmonster.Socket) {
	// Start a goroutine to check the authentication state in an interval.
	go func() {
		ticker := time.NewTicker(checkAuthInterval)
		defer ticker.Stop()

		for {
			select {
			case <-s.ClosedChan():
				// Just release this goroutine.
				return

			case <-ticker.C:
				checkSocketAuthentication(s)
			}
		}
	}()
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:18,代码来源:auth.go

示例6: resetAuthSocketValue

// resetAuthSocketValue removes the socket authentication values and triggers
// the socket Check method.
func resetAuthSocketValue(s *bitmonster.Socket) {
	// Debug log.
	log.L.WithFields(logrus.Fields{
		"remoteAddress": s.RemoteAddr(),
	}).Debugf("auth: authentication state resetted")

	// Get the auth socket value.
	av := getAuthSocketValue(s)
	if av != nil {
		// Stop the reauth timer if present.
		if av.reauthTimer != nil {
			av.reauthTimer.Stop()
		}
	}

	// Remove the socket auth value to delete the authenticated infos.
	s.DeleteValue(authSocketValueKey)

	// Clear the cache.
	clearCache(s)

	// Rerun the event hooks.
	// This will unbind events which require authentication.
	s.Check()
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:27,代码来源:auth.go

示例7: clearCache

// clearCache clears all cached values of the socket.
func clearCache(s *bitmonster.Socket) {
	s.DeleteValue(cacheUserSocketValueKey)
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:4,代码来源:cache.go

示例8: onNewSocket

func onNewSocket(s *bitmonster.Socket) {
	fmt.Printf("new socket: %s", s.ID())
}
开发者ID:desertbit,项目名称:bitmonster,代码行数:3,代码来源:sample.go


注:本文中的github.com/desertbit/bitmonster.Socket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。