@@ -207,40 +207,40 @@ func rejectStreamWithError(stream Stream, code moqt.RequestErrorCode, reason str
207207// On any error before the stream is established and the first message
208208// written, the stream (if any) is reset and the error is returned.
209209func (s * Session ) OpenRequest (first message.Message ) (Stream , error ) {
210- return s .openStreamWith (first , nil )
210+ stream , err := s .conn .OpenStream ()
211+ if err != nil {
212+ return nil , err
213+ }
214+ return writeFirst (stream , first )
211215}
212216
213- // openStreamWith opens a new outbound bidirectional stream, runs prepare (if
214- // non-nil) now that the open has succeeded, then writes first as the stream's
215- // initial message. prepare is the hook where a fresh Request ID is assigned, so
216- // a failed open (e.g. ErrNoStreamCredit) consumes no ID — the §10.1 sequence
217- // stays untouched. On a write failure the stream is reset and the error
218- // returned.
219- func (s * Session ) openStreamWith (first message.Message , prepare func ()) (Stream , error ) {
217+ // openAllocRequest opens a request stream for m and assigns m a freshly
218+ // allocated Request ID (§10.1) only after the open succeeds — so a failed open
219+ // (e.g. ErrNoStreamCredit) consumes no ID and the §10.1 sequence stays
220+ // untouched — then writes it as the stream's first message. It does NOT await
221+ // the peer's response — the caller owns the read side. It is the single
222+ // primitive beneath every typed request opener (Publish, Subscribe, Fetch,
223+ // TrackStatus, the namespace requests) and the non-blocking
224+ // [Session.OpenPublish] used for relay fan-out.
225+ func (s * Session ) openAllocRequest (m message.WithRequestID ) (Stream , error ) {
220226 stream , err := s .conn .OpenStream ()
221227 if err != nil {
222228 return nil , err
223229 }
224- if prepare != nil {
225- prepare ()
226- }
230+ m .SetRequestID (s .AllocRequestID ())
231+ return writeFirst (stream , m )
232+ }
233+
234+ // writeFirst marshals first as the initial message of a freshly opened request
235+ // stream. On a write failure the stream is reset and the error is returned.
236+ func writeFirst (stream Stream , first message.Message ) (Stream , error ) {
227237 if err := message .Marshal (stream , first ); err != nil {
228238 resetStream (stream )
229239 return nil , fmt .Errorf ("moqt/session: write request first message: %w" , err )
230240 }
231241 return stream , nil
232242}
233243
234- // openAllocRequest opens a request stream for m and assigns m a freshly
235- // allocated Request ID (§10.1) only after the open succeeds, then writes it as
236- // the stream's first message. It does NOT await the peer's response — the
237- // caller owns the read side. It is the single primitive beneath every typed
238- // request opener (Publish, Subscribe, Fetch, TrackStatus, the namespace
239- // requests) and the non-blocking [Session.OpenPublish] used for relay fan-out.
240- func (s * Session ) openAllocRequest (m message.WithRequestID ) (Stream , error ) {
241- return s .openStreamWith (m , func () { m .SetRequestID (s .AllocRequestID ()) })
242- }
243-
244244// readResponse parses one message from stream, honoring ctx. message.Parse
245245// reads from a context-free io.Reader, so cancellation is bridged by resetting
246246// the stream's read side with StreamResetCancelled (§3.3.3), which unblocks the
0 commit comments