good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 7f99ccd6 authored by a's avatar a
Browse files

reorganize

parent 99e494dd
No related branches found
No related tags found
2 merge requests!15Draft: V2,!13Draft: Move Openrpc Package
......@@ -176,6 +176,18 @@ func (s *Server) ServeCodec(pctx context.Context, remote codec.ReaderWriter) {
}
}
// Stop stops reading new requests, waits for stopPendingRequestTimeout to allow pending
// requests to finish, then closes all codecs which will cancel pending requests and
// subscriptions.
func (s *Server) Stop() {
if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
s.codecs.Each(func(c any) bool {
c.(codec.ReaderWriter).Close()
return true
})
}
}
type callResponder struct {
toSend chan *callEnv
toNotify chan *notifyEnv
......@@ -298,16 +310,16 @@ func (c *callResponder) send(ctx context.Context, env *callEnv) error {
return nil
}
type callEnv struct {
responses []*callRespWriter
batch bool
}
type notifyEnv struct {
method string
dat func(io.Writer) error
}
type callEnv struct {
responses []*callRespWriter
batch bool
}
var _ codec.ResponseWriter = (*callRespWriter)(nil)
type callRespWriter struct {
......@@ -349,29 +361,3 @@ func (c *callRespWriter) Notify(method string, v any) error {
}
return nil
}
// Stop stops reading new requests, waits for stopPendingRequestTimeout to allow pending
// requests to finish, then closes all codecs which will cancel pending requests and
// subscriptions.
func (s *Server) Stop() {
if atomic.CompareAndSwapInt32(&s.run, 1, 0) {
s.codecs.Each(func(c any) bool {
c.(codec.ReaderWriter).Close()
return true
})
}
}
type peerInfoContextKey struct{}
// PeerInfoFromContext returns information about the client's network connection.
// Use this with the context passed to RPC method handler functions.
//
// The zero value is returned if no connection info is present in ctx.
func PeerInfoFromContext(ctx context.Context) codec.PeerInfo {
info, _ := ctx.Value(peerInfoContextKey{}).(codec.PeerInfo)
return info
}
func ContextWithPeerInfo(ctx context.Context, c codec.PeerInfo) context.Context {
return context.WithValue(ctx, peerInfoContextKey{}, c)
}
package server
import (
"context"
"gfx.cafe/open/jrpc/pkg/codec"
)
type peerInfoContextKey struct{}
// PeerInfoFromContext returns information about the client's network connection.
// Use this with the context passed to RPC method handler functions.
//
// The zero value is returned if no connection info is present in ctx.
func PeerInfoFromContext(ctx context.Context) codec.PeerInfo {
info, _ := ctx.Value(peerInfoContextKey{}).(codec.PeerInfo)
return info
}
func ContextWithPeerInfo(ctx context.Context, c codec.PeerInfo) context.Context {
return context.WithValue(ctx, peerInfoContextKey{}, c)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment