Skip to content

Commit

Permalink
Making sure connection value is available in streams, as well as the …
Browse files Browse the repository at this point in the history
…stream itself
  • Loading branch information
ShivanshVij committed Sep 11, 2024
1 parent 5672a73 commit a60dfc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions templates/constants.templ
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{define "constants"}}
const ConnectionContextKey int = 1000
const StreamContextKey int = 1001

func SetErrorFlag(flags uint8, error bool) uint8 {
return flags | 0x2
Expand Down
4 changes: 3 additions & 1 deletion templates/server.templ
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func NewServer({{ GetServerFields .services }}, tlsConfig *tls.Config, logger ty

{{ if .numStreamMethods -}}
s.server.SetStreamHandler(func(ctx context.Context, stream *frisbee.Stream) {
streamCtx := context.WithValue(ctx, ConnectionContextKey, stream.Conn())
streamCtx = context.WithValue(streamCtx, StreamContextKey, stream)
p, err := stream.ReadPacket()
if err != nil {
return
Expand All @@ -73,7 +75,7 @@ func NewServer({{ GetServerFields .services }}, tlsConfig *tls.Config, logger ty
{{ $opIndex := call $counter -}}
{{ if or $method.IsStreamingClient $method.IsStreamingServer -}}
case {{ $opIndex }}:
s.create{{ CamelCaseName $method.Name }}Server(ctx, {{ FirstLowerCase (CamelCaseName $service.Name) }}, stream)
s.create{{ CamelCaseName $method.Name }}Server(streamCtx, {{ FirstLowerCase (CamelCaseName $service.Name) }}, stream)
{{end -}}
{{end -}}
{{end -}}
Expand Down

0 comments on commit a60dfc4

Please sign in to comment.