good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jrpc
Manage
Activity
Members
Labels
Plan
Issues
6
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
jrpc
Commits
7f99ccd6
Verified
Commit
7f99ccd6
authored
1 year ago
by
a
Browse files
Options
Downloads
Patches
Plain Diff
reorganize
parent
99e494dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!15
Draft: V2
,
!13
Draft: Move Openrpc Package
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/server/server.go
+17
-31
17 additions, 31 deletions
pkg/server/server.go
pkg/server/util.go
+21
-0
21 additions, 0 deletions
pkg/server/util.go
with
38 additions
and
31 deletions
pkg/server/server.go
+
17
−
31
View file @
7f99ccd6
...
...
@@ -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
)
}
This diff is collapsed.
Click to expand it.
pkg/server/util.go
0 → 100644
+
21
−
0
View file @
7f99ccd6
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
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment