// Process an NNTP session.
Process an NNTP session.
// Process an NNTP session .
func (s *Server) Process(tc io.ReadWriteCloser) {
	defer tc.Close()
	c := textproto.NewConn(tc)
	var backend Backend
	if s.Backend!=nil {
		backend = s.Backend
	} else {
		panic("no backend set")
	}
	sess := &session{
		server:      s,
		idGenerator: s.IdGenerator,
		group:       nil,
		number:      0,
	}
	sess.setBackend(backend)
	c.PrintfLine("200 Hello!")
	for {
		l, err := c.ReadLine()
		if err != nil {
			log.Printf("Error reading from client, dropping conn: %v", err)
			return
		}
		cmd := strings.Split(l, " ")
		log.Printf("Got cmd:  %+v", cmd)
		args := []string{}
		if len(cmd) > 1 {
			args = cmd[1:]
		}
		err = sess.dispatchCommand(cmd[0], args, c)
		if err != nil {
			_, isNNTPError := err.(*NNTPError)
			switch {
			case err == io.EOF:
				return
			case isNNTPError:
				c.PrintfLine(err.Error())
			default:
				log.Printf("Error dispatching command, dropping conn: %v",
					err)
				return
			}
		}
	}
}
func ( s * Server ) Process ( tc io . ReadWriteCloser ) { defer tc . Close ( ) c := textproto . NewConn ( tc ) var backend Backend if s . Backend != nil { backend = s . Backend } else { panic ( " " ) } sess := & session { server : s , idGenerator : s . IdGenerator , group : nil , number : 0 , } sess . setBackend ( backend ) c . PrintfLine ( " " ) for { l , err := c . ReadLine ( ) if err != nil { log . Printf ( " " , err ) return } cmd := strings . Split ( l , " " ) log . Printf ( " " , cmd ) args := [ ] string { } if len ( cmd ) > 1 { args = cmd [ 1 : ] } err = sess . dispatchCommand ( cmd [ 0 ] , args , c ) if err != nil { _ , isNNTPError := err . ( * NNTPError ) switch { case err == io . EOF : return case isNNTPError : c . PrintfLine ( err . Error ( ) ) default : log . Printf ( " " , err ) return } } } }
Process an NNTP session.
Process an NNTP session .
// Drop this connection silently. They hung up