示例#1
0
// Create a new ajax socket.
func newSocket(s *Server) *Socket {
	a := &Socket{
		writeChan: make(chan string, global.WriteChanSize),
		readChan:  make(chan string, global.ReadChanSize),
	}

	// Set the closer function.
	a.closer = closer.New(func() {
		// Remove the ajax socket from the map.
		if len(a.uid) > 0 {
			func() {
				s.socketsMutex.Lock()
				defer s.socketsMutex.Unlock()

				delete(s.sockets, a.uid)
			}()
		}

		// Trigger the onClose function if defined.
		if a.onClose != nil {
			a.onClose()
		}
	})

	return a
}
示例#2
0
文件: socket.go 项目: so0k/ecs-sample
// Create a new websocket value.
func newSocket(ws *websocket.Conn) *Socket {
	w := &Socket{
		ws:        ws,
		writeChan: make(chan string, global.WriteChanSize),
		readChan:  make(chan string, global.ReadChanSize),
	}

	// Set the closer function.
	w.closer = closer.New(func() {
		// Send a close message to the client.
		// Ignore errors.
		w.write(websocket.CloseMessage, []byte{})

		// Close the socket.
		w.ws.Close()
	})

	return w
}
示例#3
0
文件: ajaxsocket.go 项目: epigos/glue
// Create a new ajax socket.
func newAjaxSocket() *ajaxSocket {
	a := &ajaxSocket{
		writeChan: make(chan string, writeChanSize),
		readChan:  make(chan string, readChanSize),
	}

	// Set the closer function.
	a.closer = closer.New(func() {
		// Remove the ajax socket from the map.
		if len(a.uid) > 0 {
			ajaxMutex.Lock()
			delete(ajaxSockets, a.uid)
			ajaxMutex.Unlock()
		}

		// Trigger the onClose function if defined.
		if a.onClose != nil {
			a.onClose()
		}
	})

	return a
}
示例#4
0
文件: websocket.go 项目: e4x/glue
// Create a new websocket type.
func newWebSocket(ws *websocket.Conn) *webSocket {
	w := &webSocket{
		ws:        ws,
		writeChan: make(chan string, writeChanSize),
		readChan:  make(chan string, readChanSize),
	}

	// Set the closer function.
	w.closer = closer.New(func() {
		// Send a close message to the client.
		// Ignore errors.
		w.write(websocket.CloseMessage, []byte{})

		// Close the socket.
		w.ws.Close()

		// Trigger the onClose function if defined.
		if w.onClose != nil {
			w.onClose()
		}
	})

	return w
}