1 /** @file
2 *
3 * A brief file description
4 *
5 * @section license License
6 *
7 * Licensed to the Apache Software Foundation (ASF) under one
8 * or more contributor license agreements. See the NOTICE file
9 * distributed with this work for additional information
10 * regarding copyright ownership. The ASF licenses this file
11 * to you under the Apache License, Version 2.0 (the
12 * "License"); you may not use this file except in compliance
13 * with the License. You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24 #include "QUICStream.h"
25 #include "QUICBidirectionalStream.h"
26 #include "QUICUnidirectionalStream.h"
27 #include "QUICStreamFactory.h"
28
29 ClassAllocator<QUICBidirectionalStream> quicBidiStreamAllocator("quicBidiStreamAllocator");
30 ClassAllocator<QUICSendStream> quicSendStreamAllocator("quicSendStreamAllocator");
31 ClassAllocator<QUICReceiveStream> quicReceiveStreamAllocator("quicReceiveStreamAllocator");
32
33 QUICStreamVConnection *
create(QUICStreamId sid,uint64_t local_max_stream_data,uint64_t remote_max_stream_data)34 QUICStreamFactory::create(QUICStreamId sid, uint64_t local_max_stream_data, uint64_t remote_max_stream_data)
35 {
36 QUICStreamVConnection *stream = nullptr;
37 switch (QUICTypeUtil::detect_stream_direction(sid, this->_info->direction())) {
38 case QUICStreamDirection::BIDIRECTIONAL:
39 // TODO Free the stream somewhere
40 stream = THREAD_ALLOC(quicBidiStreamAllocator, this_ethread());
41 new (stream) QUICBidirectionalStream(this->_rtt_provider, this->_info, sid, local_max_stream_data, remote_max_stream_data);
42 break;
43 case QUICStreamDirection::SEND:
44 // TODO Free the stream somewhere
45 stream = THREAD_ALLOC(quicSendStreamAllocator, this_ethread());
46 new (stream) QUICSendStream(this->_info, sid, remote_max_stream_data);
47 break;
48 case QUICStreamDirection::RECEIVE:
49 // server side
50 // TODO Free the stream somewhere
51 stream = THREAD_ALLOC(quicReceiveStreamAllocator, this_ethread());
52 new (stream) QUICReceiveStream(this->_rtt_provider, this->_info, sid, local_max_stream_data);
53 break;
54 default:
55 ink_assert(false);
56 break;
57 }
58
59 return stream;
60 }
61
62 void
delete_stream(QUICStreamVConnection * stream)63 QUICStreamFactory::delete_stream(QUICStreamVConnection *stream)
64 {
65 if (!stream) {
66 return;
67 }
68
69 stream->~QUICStreamVConnection();
70 switch (stream->direction()) {
71 case QUICStreamDirection::BIDIRECTIONAL:
72 THREAD_FREE(static_cast<QUICBidirectionalStream *>(stream), quicBidiStreamAllocator, this_thread());
73 break;
74 case QUICStreamDirection::SEND:
75 THREAD_FREE(static_cast<QUICSendStream *>(stream), quicSendStreamAllocator, this_thread());
76 break;
77 case QUICStreamDirection::RECEIVE:
78 THREAD_FREE(static_cast<QUICReceiveStream *>(stream), quicReceiveStreamAllocator, this_thread());
79 break;
80 default:
81 ink_assert(false);
82 break;
83 }
84 }
85