Esempio n. 1
0
func (self *Server) listen() {
	errors := ErrorHandler()
	var EOF bool
	for !EOF {
		con, err := self.ln.AcceptTCP()
		if netutils.IsEOF(err) {
			EOF = true
		} else if err != nil {
			log.Panic(err)
		} else {
			send := netutils.TCPWriter(con, errors)
			recv := netutils.TCPReader(con, errors)
			go self.Connection(send, recv).Serve()
		}
	}
}
Esempio n. 2
0
func (s *YAKVS) accept(cid uint64, conn *net.TCPConn, errChan chan error) *connection {
	c := new(connection)

	c.cid = cid
	c.s = s
	c.send = netutils.TCPWriter(conn, errChan)
	c.recv = netutils.TCPReader(conn, errChan)
	c.closedLock = new(sync.Mutex)
	c.lastAccessLock = new(sync.Mutex)

	c.lastAccessLock.Lock()
	c.lastAccess = time.Now()
	c.lastAccessLock.Unlock()

	s.connectionsLock.Lock()
	s.connections[cid] = c
	s.connectionsLock.Unlock()

	return c
}