Skip to content

Commit 36c9a28

Browse files
Rename end of request to end of response for accuracy; code
simplification.
1 parent 2328199 commit 36c9a28

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

src/oracledb/impl/thin/capabilities.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cdef class Capabilities:
4141
uint32_t max_string_size
4242
bint supports_fast_auth
4343
bint supports_oob
44-
bint supports_end_of_request
44+
bint supports_end_of_response
4545
uint32_t sdu
4646

4747
def __init__(self):
@@ -60,19 +60,19 @@ cdef class Capabilities:
6060
if flags & TNS_ACCEPT_FLAG_FAST_AUTH:
6161
self.supports_fast_auth = True
6262
if protocol_version >= TNS_VERSION_MIN_END_OF_RESPONSE \
63-
and flags & TNS_ACCEPT_FLAG_HAS_END_OF_REQUEST:
64-
self.compile_caps[TNS_CCAP_TTC4] |= TNS_CCAP_END_OF_REQUEST
65-
self.supports_end_of_request = True
63+
and flags & TNS_ACCEPT_FLAG_HAS_END_OF_RESPONSE:
64+
self.compile_caps[TNS_CCAP_TTC4] |= TNS_CCAP_END_OF_RESPONSE
65+
self.supports_end_of_response = True
6666

6767
@cython.boundscheck(False)
6868
cdef void _adjust_for_server_compile_caps(self, bytearray server_caps):
6969
if server_caps[TNS_CCAP_FIELD_VERSION] < self.ttc_field_version:
7070
self.ttc_field_version = server_caps[TNS_CCAP_FIELD_VERSION]
7171
self.compile_caps[TNS_CCAP_FIELD_VERSION] = self.ttc_field_version
7272
if self.ttc_field_version < TNS_CCAP_FIELD_VERSION_23_4 \
73-
and self.supports_end_of_request:
74-
self.compile_caps[TNS_CCAP_TTC4] ^= TNS_CCAP_END_OF_REQUEST
75-
self.supports_end_of_request = False
73+
and self.supports_end_of_response:
74+
self.compile_caps[TNS_CCAP_TTC4] ^= TNS_CCAP_END_OF_RESPONSE
75+
self.supports_end_of_response = False
7676

7777
@cython.boundscheck(False)
7878
cdef void _adjust_for_server_runtime_caps(self, bytearray server_caps):

src/oracledb/impl/thin/constants.pxi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cdef enum:
4747

4848
# data flags
4949
cdef enum:
50-
TNS_DATA_FLAGS_END_OF_REQUEST = 0x2000
50+
TNS_DATA_FLAGS_END_OF_RESPONSE = 0x2000
5151
TNS_DATA_FLAGS_EOF = 0x0040
5252

5353
# marker types
@@ -412,7 +412,7 @@ cdef enum:
412412
TNS_MSG_TYPE_ONEWAY_FN = 26
413413
TNS_MSG_TYPE_IMPLICIT_RESULTSET = 27
414414
TNS_MSG_TYPE_RENEGOTIATE = 28
415-
TNS_MSG_TYPE_END_OF_REQUEST = 29
415+
TNS_MSG_TYPE_END_OF_RESPONSE = 29
416416
TNS_MSG_TYPE_FAST_AUTH = 34
417417

418418
# parameter keyword numbers
@@ -714,7 +714,7 @@ cdef enum:
714714
TNS_CCAP_DRCP = 0x10
715715
TNS_CCAP_ZLNP = 0x04
716716
TNS_CCAP_INBAND_NOTIFICATION = 0x04
717-
TNS_CCAP_END_OF_REQUEST = 0x20
717+
TNS_CCAP_END_OF_RESPONSE = 0x20
718718
TNS_CCAP_CLIENT_FN_MAX = 12
719719
TNS_CCAP_VECTOR_SUPPORT = 0x08
720720

@@ -749,7 +749,7 @@ cdef enum:
749749
# accept flags
750750
cdef enum:
751751
TNS_ACCEPT_FLAG_FAST_AUTH = 0x10000000
752-
TNS_ACCEPT_FLAG_HAS_END_OF_REQUEST = 0x02000000
752+
TNS_ACCEPT_FLAG_HAS_END_OF_RESPONSE = 0x02000000
753753

754754
# transaction switching op codes
755755
cdef enum:

src/oracledb/impl/thin/messages.pyx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ cdef class Message:
5656
bint retry
5757
object warning
5858

59+
cdef int _check_and_raise_exception(self) except -1:
60+
"""
61+
Checks to see if an error has occurred. If one has, an error object is
62+
created and then the appropriate exception raised. Note that if a "dead
63+
connection" error is detected, the connection is forced closed
64+
immediately.
65+
"""
66+
if self.error_occurred:
67+
error = errors._Error(self.error_info.message,
68+
code=self.error_info.num,
69+
offset=self.error_info.pos)
70+
if error.is_session_dead:
71+
self.conn_impl._protocol._force_close()
72+
raise error.exc_type(error)
73+
5974
cdef int _initialize(self, BaseThinConnImpl conn_impl) except -1:
6075
"""
6176
Initializes the message to contain the connection and a place to store
@@ -172,7 +187,7 @@ cdef class Message:
172187

173188
# an error message marks the end of a response if no explicit end of
174189
# response is available
175-
if not buf._caps.supports_end_of_request:
190+
if not buf._caps.supports_end_of_response:
176191
self.end_of_response = True
177192

178193
cdef int _process_message(self, ReadBuffer buf,
@@ -184,13 +199,13 @@ cdef class Message:
184199
elif message_type == TNS_MSG_TYPE_STATUS:
185200
buf.read_ub4(&self.call_status)
186201
buf.read_ub2(&self.end_to_end_seq_num)
187-
if not buf._caps.supports_end_of_request:
202+
if not buf._caps.supports_end_of_response:
188203
self.end_of_response = True
189204
elif message_type == TNS_MSG_TYPE_PARAMETER:
190205
self._process_return_parameters(buf)
191206
elif message_type == TNS_MSG_TYPE_SERVER_SIDE_PIGGYBACK:
192207
self._process_server_side_piggyback(buf)
193-
elif message_type == TNS_MSG_TYPE_END_OF_REQUEST:
208+
elif message_type == TNS_MSG_TYPE_END_OF_RESPONSE:
194209
self.end_of_response = True
195210
else:
196211
errors._raise_err(errors.ERR_MESSAGE_TYPE_UNKNOWN,
@@ -1936,7 +1951,7 @@ cdef class DataTypesMessage(Message):
19361951
buf.read_uint16(&conv_data_type)
19371952
if conv_data_type != 0:
19381953
buf.skip_raw_bytes(4)
1939-
if not buf._caps.supports_end_of_request:
1954+
if not buf._caps.supports_end_of_response:
19401955
self.end_of_response = True
19411956

19421957
cdef int _write_message(self, WriteBuffer buf) except -1:
@@ -2378,7 +2393,7 @@ cdef class ProtocolMessage(Message):
23782393
uint8_t message_type) except -1:
23792394
if message_type == TNS_MSG_TYPE_PROTOCOL:
23802395
self._process_protocol_info(buf)
2381-
if not buf._caps.supports_end_of_request:
2396+
if not buf._caps.supports_end_of_response:
23822397
self.end_of_response = True
23832398
else:
23842399
Message._process_message(self, buf, message_type)

src/oracledb/impl/thin/packet.pyx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ cdef class Packet:
5555
uint8_t packet_flags
5656
bytes buf
5757

58-
cdef inline bint has_end_of_request(self):
58+
cdef inline bint has_end_of_response(self):
5959
"""
6060
Returns a boolean indicating if the end of request byte is found at the
6161
end of the packet.
@@ -66,10 +66,10 @@ cdef class Packet:
6666
ptr = cpython.PyBytes_AS_STRING(self.buf)
6767
flags = unpack_uint16(<const char_type*> &ptr[PACKET_HEADER_SIZE],
6868
BYTE_ORDER_MSB)
69-
if flags & TNS_DATA_FLAGS_END_OF_REQUEST:
69+
if flags & TNS_DATA_FLAGS_END_OF_RESPONSE:
7070
return True
7171
if self.packet_size == PACKET_HEADER_SIZE + 3 \
72-
and ptr[PACKET_HEADER_SIZE + 2] == TNS_MSG_TYPE_END_OF_REQUEST:
72+
and ptr[PACKET_HEADER_SIZE + 2] == TNS_MSG_TYPE_END_OF_RESPONSE:
7373
return True
7474
return False
7575

@@ -346,7 +346,7 @@ cdef class ReadBuffer(Buffer):
346346
notify_waiter[0] = \
347347
packet.packet_type != TNS_PACKET_TYPE_DATA \
348348
or not self._check_request_boundary \
349-
or packet.has_end_of_request()
349+
or packet.has_end_of_response()
350350

351351
cdef int _read_raw_bytes_and_length(self, const char_type **ptr,
352352
ssize_t *num_bytes) except -1:
@@ -710,6 +710,7 @@ cdef class WriteBuffer(Buffer):
710710
cdef:
711711
uint8_t _packet_type
712712
uint8_t _packet_flags
713+
uint16_t _data_flags
713714
Capabilities _caps
714715
Transport _transport
715716
uint8_t _seq_num
@@ -735,12 +736,14 @@ cdef class WriteBuffer(Buffer):
735736
self.write_uint8(self._packet_type)
736737
self.write_uint8(self._packet_flags)
737738
self.write_uint16(0)
739+
if self._packet_type == TNS_PACKET_TYPE_DATA:
740+
self.write_uint16(self._data_flags)
738741
self._pos = size
739742
self._transport.write_packet(self)
740743
self._packet_sent = True
741744
self._pos = PACKET_HEADER_SIZE
742-
if not final_packet:
743-
self.write_uint16(0) # add data flags for next packet
745+
if not final_packet and self._packet_type == TNS_PACKET_TYPE_DATA:
746+
self._pos += sizeof(uint16_t) # allow space for data flags
744747

745748
cdef int _size_for_sdu(self) except -1:
746749
"""
@@ -786,7 +789,8 @@ cdef class WriteBuffer(Buffer):
786789
self._packet_flags = packet_flags
787790
self._pos = PACKET_HEADER_SIZE
788791
if packet_type == TNS_PACKET_TYPE_DATA:
789-
self.write_uint16(data_flags)
792+
self._data_flags = data_flags
793+
self._pos += sizeof(uint16_t)
790794

791795
cdef object write_dbobject(self, ThinDbObjectImpl obj_impl):
792796
"""

src/oracledb/impl/thin/protocol.pyx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,7 @@ cdef class Protocol(BaseProtocol):
425425
if message.retry:
426426
message.error_occurred = False
427427
return self._process_message(message)
428-
error = errors._Error(message.error_info.message,
429-
code=message.error_info.num,
430-
offset=message.error_info.pos)
431-
432-
# if a connection has received dead connection error then it is no
433-
# longer usable
434-
if error.is_session_dead:
435-
self._force_close()
436-
raise error.exc_type(error)
428+
message._check_and_raise_exception()
437429

438430
cdef int _process_single_message(self, Message message) except -1:
439431
"""
@@ -452,7 +444,7 @@ cdef class Protocol(BaseProtocol):
452444
uint16_t refuse_message_len
453445
const char_type* ptr
454446
buf._check_request_boundary = \
455-
check_request_boundary and self._caps.supports_end_of_request
447+
check_request_boundary and self._caps.supports_end_of_response
456448
buf.wait_for_packets_sync()
457449
buf._check_request_boundary = False
458450
if buf._current_packet.packet_type == TNS_PACKET_TYPE_MARKER:
@@ -779,15 +771,7 @@ cdef class BaseAsyncProtocol(BaseProtocol):
779771
if message.retry:
780772
message.error_occurred = False
781773
return await self._process_message(message)
782-
error = errors._Error(message.error_info.message,
783-
code=message.error_info.num,
784-
offset=message.error_info.pos)
785-
786-
# if a connection has received dead connection error then it is no
787-
# longer usable
788-
if error.is_session_dead:
789-
self._force_close()
790-
raise error.exc_type(error)
774+
message._check_and_raise_exception()
791775

792776
async def _process_message_helper(self, Message message):
793777
"""
@@ -830,7 +814,7 @@ cdef class BaseAsyncProtocol(BaseProtocol):
830814
uint16_t refuse_message_len
831815
const char_type* ptr
832816
buf._check_request_boundary = \
833-
check_request_boundary and self._caps.supports_end_of_request
817+
check_request_boundary and self._caps.supports_end_of_response
834818
await buf.wait_for_packets_async()
835819
buf._check_request_boundary = False
836820
if buf._current_packet.packet_type == TNS_PACKET_TYPE_MARKER:

0 commit comments

Comments
 (0)