lint, gitignore, GNU Makefile to make things simpler
This commit is contained in:
parent
006a4f9d6d
commit
7df5779a24
5 changed files with 38 additions and 25 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.idea/
|
12
Makefile
Normal file
12
Makefile
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
test: check
|
||||||
|
|
||||||
|
check: lint
|
||||||
|
go test -v
|
||||||
|
|
||||||
|
lint:
|
||||||
|
gofmt -w=true -s=true -l=true ./
|
||||||
|
golint ./...
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
||||||
module github.com/chrj/smtpd
|
module github.com/chrj/smtpd
|
||||||
|
|
||||||
go 1.14
|
go 1.19
|
||||||
|
|
34
smtpd.go
34
smtpd.go
|
@ -66,10 +66,11 @@ type Server struct {
|
||||||
type Protocol string
|
type Protocol string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// SMTP
|
// SMTP means Simple Mail Transfer Protocol
|
||||||
SMTP Protocol = "SMTP"
|
SMTP Protocol = "SMTP"
|
||||||
|
|
||||||
// Extended SMTP
|
// ESMTP means Extended Simple Mail Transfer Protocol, because it has some extra features
|
||||||
|
// Simple Mail Transfer Protocol doesn't have
|
||||||
ESMTP = "ESMTP"
|
ESMTP = "ESMTP"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -228,7 +229,7 @@ func (srv *Server) Shutdown(wait bool) error {
|
||||||
// First close the listener
|
// First close the listener
|
||||||
srv.mu.Lock()
|
srv.mu.Lock()
|
||||||
if srv.listener != nil {
|
if srv.listener != nil {
|
||||||
lnerr = (*srv.listener).Close();
|
lnerr = (*srv.listener).Close()
|
||||||
}
|
}
|
||||||
srv.closeDoneChanLocked()
|
srv.closeDoneChanLocked()
|
||||||
srv.mu.Unlock()
|
srv.mu.Unlock()
|
||||||
|
@ -254,7 +255,7 @@ func (srv *Server) Wait() error {
|
||||||
|
|
||||||
// Address returns the listening address of the server
|
// Address returns the listening address of the server
|
||||||
func (srv *Server) Address() net.Addr {
|
func (srv *Server) Address() net.Addr {
|
||||||
return (*srv.listener).Addr();
|
return (*srv.listener).Addr()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) configureDefaults() {
|
func (srv *Server) configureDefaults() {
|
||||||
|
@ -433,28 +434,27 @@ func (session *session) close() {
|
||||||
session.conn.Close()
|
session.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// From net/http/server.go
|
// From net/http/server.go
|
||||||
|
|
||||||
func (s *Server) shuttingDown() bool {
|
func (srv *Server) shuttingDown() bool {
|
||||||
return s.inShutdown.isSet()
|
return srv.inShutdown.isSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getDoneChan() <-chan struct{} {
|
func (srv *Server) getDoneChan() <-chan struct{} {
|
||||||
s.mu.Lock()
|
srv.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer srv.mu.Unlock()
|
||||||
return s.getDoneChanLocked()
|
return srv.getDoneChanLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getDoneChanLocked() chan struct{} {
|
func (srv *Server) getDoneChanLocked() chan struct{} {
|
||||||
if s.doneChan == nil {
|
if srv.doneChan == nil {
|
||||||
s.doneChan = make(chan struct{})
|
srv.doneChan = make(chan struct{})
|
||||||
}
|
}
|
||||||
return s.doneChan
|
return srv.doneChan
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) closeDoneChanLocked() {
|
func (srv *Server) closeDoneChanLocked() {
|
||||||
ch := s.getDoneChanLocked()
|
ch := srv.getDoneChanLocked()
|
||||||
select {
|
select {
|
||||||
case <-ch:
|
case <-ch:
|
||||||
// Already closed. Don't close again.
|
// Already closed. Don't close again.
|
||||||
|
|
Loading…
Add table
Reference in a new issue