package websocket import ( "net/http" "github.com/ethereum/go-ethereum/logger" ws "code.google.com/p/go.net/websocket" ) var wslogger = logger.NewLogger("WS") // Chat server. type Server struct { httpServ string pattern string messages []*Message clients map[int]*Client addCh chan *Client delCh chan *Client sendAllCh chan string doneCh chan bool errCh chan error msgFunc MsgFunc } // Create new chat server. func NewServer(pattern, httpServ string) *Server { clients := make(map[int]*Client) addCh := make(chan *Client) delCh := make(chan *Client) sendAllCh := make(chan string) doneCh := make(chan bool) errCh := make(chan error) return &Server{ httpServ, pattern, nil, clients, addCh, delCh, sendAllCh, doneCh, errCh, nil, } } func (s *Server) Add(c *Client) { s.addCh <- c } func (s *Server) Del(c *Client) { s.delCh <- c } func (s *Server) SendAll(msg string) { s.sendAllCh <- msg } func (s *Server) Done() { s.doneCh <- true } func (s *Server) Err(err error) { s.errCh <- err } func (s *Server) servHTTP() { wslogger.Debugln("Serving http", s.httpServ) err := http.ListenAndServe(s.httpServ, nil) wslogger.Warnln(err) } func (s *Server) MessageFunc(f MsgFunc) { s.msgFunc = f } // Listen and serve. // It serves client connection and broadcast request. func (s *Server) Listen() { wslogger.Debugln("Listening server...") // ws handler onConnected := func(ws *ws.Conn) { defer func() { err := ws.Close() if err != nil { s.errCh <- err } }() client := NewClient(ws, s) client.onMessage = s.msgFunc s.Add(client) client.Listen() } // Disable Origin check. Request don't need to come necessarily from origin. http.HandleFunc(s.pattern, func(w http.ResponseWriter, req *http.Request) { s := ws.Server{Handler: ws.Handler(onConnected)} s.ServeHTTP(w, req) }) wslogger.Debugln("Created handler") go s.servHTTP() for { select { // Add new a client case c := <-s.addCh: s.clients[c.id] = c // del a client case c := <-s.delCh: delete(s.clients, c.id) case err := <-s.errCh: wslogger.Debugln("Error:", err.Error()) case <-s.doneCh: return } } } lue='dependabot/npm_and_yarn/devel/electron4/files/lodash.merge-4.6.2'>dependabot/npm_and_yarn/devel/electron4/files/lodash.merge-4.6.2 FreeBSD GNOME current development ports (https://github.com/freebsd/freebsd-ports-gnome)
aboutsummaryrefslogtreecommitdiffstats
path: root/x11-wm/plank
Commit message (Expand)AuthorAgeFilesLines
* - Update to 0.10.1olivierd2015-10-123-4/+20
* - Update to 0.10.0olivierd2015-09-083-5/+8
* Remove unneeded patches (discussed with upstream)olivierd2015-05-124-56/+0
* Update to 0.9.1olivierd2015-05-068-110/+51
* - Update to 0.9.0olivierd2015-04-184-4/+25
* Fix build WITHOUT=NLS.mat2015-04-111-0/+1
* - Update to 0.8.1olivierd2015-01-305-28/+5
* Update to 0.8.0olivierd2015-01-104-10/+12
* Update to 0.7.1olivierd2014-12-033-15/+6
* The FreeBSD GNOME team proudly presents GNOME 3.14 and Cinnamon 2.2.kwm2014-11-191-1/+1
* - Set CPPFLAGS and LIBS in a number of ports so configure can find libintl.htijl2014-09-251-3/+5
* - Fix pkg-plist (after revision r363858)olivierd2014-08-031-1/+3
* - Update to 0.6.1olivierd2014-08-034-18/+105
* Avoid unnecessary bsd.port.options.mk inclusion by usingadamw2014-07-041-18/+6