~fnux/yggdrasil-go-coap

93fdf4eeaeec3f3bdc9bd72d98761982ce47f22c — Timothée Floure 1 year, 7 months ago c9c4409
Handle client-opened connections (via server.ActivateAndServe)
2 files changed, 13 insertions(+), 3 deletions(-)

M net/yggdrasillistener.go
M server.go
M net/yggdrasillistener.go => net/yggdrasillistener.go +1 -1
@@ 38,7 38,6 @@ func (l *YggdrasilListener) AcceptWithContext(ctx context.Context) (net.Conn, er
		if err != nil {
			return nil, fmt.Errorf("cannot accept connections: %v", err)
		}
    // FIXME: Handle deadline!
		rw, err := l.listener.Accept()
		if err != nil {
			if isTemporary(err) {


@@ 52,6 51,7 @@ func (l *YggdrasilListener) AcceptWithContext(ctx context.Context) (net.Conn, er

// Accept waits for a generic Conn.
func (l *YggdrasilListener) Accept() (net.Conn, error) {
	// TODO: handle deadline.
	return l.AcceptWithContext(context.Background())
}


M server.go => server.go +12 -2
@@ 358,6 358,13 @@ func (srv *Server) initServeDTLS(conn *coapNet.Conn) error {
	return srv.serveDTLSConnection(newShutdownWithContext(srv.doneChan), conn)
}

func (srv *Server) initServeYggdrasil(conn *coapNet.Conn) error {
	if srv.NotifyStartedFunc != nil {
		srv.NotifyStartedFunc()
	}
	return srv.serveYggdrasilConnection(newShutdownWithContext(srv.doneChan), conn)
}

// ActivateAndServe starts a coapserver with the PacketConn or Listener
// configured in *Server. Its main use is to start a server from systemd.
func (srv *Server) ActivateAndServe() error {


@@ 487,10 494,13 @@ func (srv *Server) activateAndServe(listener Listener, conn *coapNet.Conn, connU

		return srv.serveTCPListener(listener)
	case conn != nil:
		if strings.HasSuffix(srv.Net, "-dtls") {
		if srv.Net == "yggdrasil" {
			return srv.initServeYggdrasil(conn)
		} else if strings.HasSuffix(srv.Net, "-dtls") {
			return srv.initServeDTLS(conn)
		} else {
			return srv.initServeTCP(conn)
		}
		return srv.initServeTCP(conn)
	case connUDP != nil:
		return srv.initServeUDP(connUDP)
	}