@@ -1211,13 +1211,14 @@ handle_frame(#'v1_0.attach'{handle = ?UINT(Handle)},
12111211 " link handle value (~b ) exceeds maximum link handle value (~b )" ,
12121212 [Handle , MaxHandle ]);
12131213handle_frame (# 'v1_0.attach' {name = {utf8 , NameBin } = Name ,
1214- handle = Handle ,
1214+ handle = ? UINT ( HandleInt ) = Handle ,
12151215 role = Role ,
12161216 source = Source ,
12171217 target = Target ,
12181218 snd_settle_mode = SndSettleMode ,
12191219 rcv_settle_mode = RcvSettleMode } = Attach ,
12201220 State ) ->
1221+ ok = validate_handle_not_in_use (HandleInt , State ),
12211222 try
12221223 ok = validate_attach (Attach ),
12231224 handle_attach (Attach , State )
@@ -1506,10 +1507,6 @@ handle_attach(#'v1_0.attach'{role = ?AMQP_ROLE_SENDER,
15061507 Flow = # 'v1_0.flow' {handle = Handle ,
15071508 delivery_count = DeliveryCount ,
15081509 link_credit = ? UINT (MaxLinkCredit )},
1509- % %TODO check that handle is not in use for any other open links.
1510- % %"The handle MUST NOT be used for other open links. An attempt to attach
1511- % % using a handle which is already associated with a link MUST be responded to
1512- % % with an immediate close carrying a handle-in-use session-error."
15131510 IncomingLinks = IncomingLinks0 #{HandleInt => IncomingLink },
15141511 State = State0 # state {incoming_links = IncomingLinks ,
15151512 permission_cache = PermCache },
@@ -3424,14 +3421,30 @@ validate_attach(#'v1_0.attach'{unsettled = {map, [_|_]}}) ->
34243421 exit_not_implemented (" Link recovery not supported" );
34253422validate_attach (# 'v1_0.attach' {incomplete_unsettled = true }) ->
34263423 exit_not_implemented (" Link recovery not supported" );
3427- validate_attach (
3428- # 'v1_0.attach' {snd_settle_mode = SndSettleMode ,
3429- rcv_settle_mode = ? V_1_0_RECEIVER_SETTLE_MODE_SECOND })
3424+ validate_attach (# 'v1_0.attach' {snd_settle_mode = SndSettleMode ,
3425+ rcv_settle_mode = ? V_1_0_RECEIVER_SETTLE_MODE_SECOND })
34303426 when SndSettleMode =/= ? V_1_0_SENDER_SETTLE_MODE_SETTLED ->
34313427 exit_not_implemented (" rcv-settle-mode second not supported" );
34323428validate_attach (# 'v1_0.attach' {}) ->
34333429 ok .
34343430
3431+ % % "The handle MUST NOT be used for other open links. An attempt to attach
3432+ % % using a handle which is already associated with a link MUST be responded
3433+ % % to with an immediate close carrying a handle-in-use session-error." [2.7.3]
3434+ validate_handle_not_in_use (Handle , # state {incoming_links = IL ,
3435+ outgoing_links = OL ,
3436+ incoming_management_links = IML ,
3437+ outgoing_management_links = OML })
3438+ when is_map_key (Handle , IL ) orelse
3439+ is_map_key (Handle , OL ) orelse
3440+ is_map_key (Handle , IML ) orelse
3441+ is_map_key (Handle , OML ) ->
3442+ protocol_error (? V_1_0_SESSION_ERROR_HANDLE_IN_USE ,
3443+ " handle ~b is already associated with a link" ,
3444+ [Handle ]);
3445+ validate_handle_not_in_use (_ , _ ) ->
3446+ ok .
3447+
34353448validate_multi_transfer_delivery_id (? UINT (Id ), Id ) ->
34363449 ok ;
34373450validate_multi_transfer_delivery_id (undefined , _FirstDeliveryId ) ->
0 commit comments