diff options
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/server.go b/server.go new file mode 100644 index 000000000..0c7488787 --- /dev/null +++ b/server.go @@ -0,0 +1,55 @@ +package main + +import ( + "container/list" + "time" +) + +type Server struct { + // Channel for shutting down the server + shutdownChan chan bool + // DB interface + db *Database + // Peers (NYI) + peers *list.List +} + +func NewServer() (*Server, error) { + db, err := NewDatabase() + if err != nil { + return nil, err + } + + server := &Server{ + shutdownChan: make(chan bool), + db: db, + peers: list.New(), + } + + return server, nil +} + +// Start the server +func (s *Server) Start() { + // For now this function just blocks the main thread + for { + time.Sleep( time.Second ) + } +} + +func (s *Server) Stop() { + // Close the database + defer s.db.Close() + + // Loop thru the peers and close them (if we had them) + for e := s.peers.Front(); e != nil; e = e.Next() { + // peer close etc + } + + s.shutdownChan <- true +} + +// This function will wait for a shutdown and resumes main thread execution +func (s *Server) WaitForShutdown() { + <- s.shutdownChan +} |