| 6124 | |
| 6125 | |
| 6126 | void Blob::putSegment(CheckStatusWrapper* status, unsigned int segment_length, const void* segment) |
| 6127 | { |
| 6128 | /************************************** |
| 6129 | * |
| 6130 | * g d s _ p u t _ s e g m e n t |
| 6131 | * |
| 6132 | ************************************** |
| 6133 | * |
| 6134 | * Functional description |
| 6135 | * Emit a blob segment. If the protocol allows, |
| 6136 | * the segment is buffered locally for a later |
| 6137 | * batch put. |
| 6138 | * |
| 6139 | **************************************/ |
| 6140 | |
| 6141 | try |
| 6142 | { |
| 6143 | reset(status); |
| 6144 | |
| 6145 | const UCHAR* segmentPtr = static_cast<const UCHAR*>(segment); |
| 6146 | |
| 6147 | // Sniff out handles, etc, and find the various blocks. |
| 6148 | |
| 6149 | CHECK_HANDLE(blob, isc_bad_segstr_handle); |
| 6150 | |
| 6151 | Rdb* rdb = blob->rbl_rdb; |
| 6152 | CHECK_HANDLE(rdb, isc_bad_db_handle); |
| 6153 | rem_port* port = rdb->rdb_port; |
| 6154 | RefMutexGuard portGuard(*port->port_sync, FB_FUNCTION); |
| 6155 | |
| 6156 | // Handle a blob that has been opened rather than created (this should yield an error) |
| 6157 | |
| 6158 | if (!(blob->rbl_flags & Rbl::CREATE)) |
| 6159 | { |
| 6160 | send_blob(status, blob, segment_length, segmentPtr); |
| 6161 | fb_assert(false); |
| 6162 | } |
| 6163 | |
| 6164 | // If the buffer can't hold the complete incoming segment, flush out the |
| 6165 | // buffer. If the incoming segment is too large to fit into the blob |
| 6166 | // buffer, just send it as a single segment. |
| 6167 | |
| 6168 | UCHAR* p = blob->rbl_ptr; |
| 6169 | const unsigned int l = blob->rbl_buffer_length - (p - blob->rbl_buffer); |
| 6170 | |
| 6171 | if (segment_length + 2 > l) |
| 6172 | { |
| 6173 | if (blob->rbl_ptr > blob->rbl_buffer) |
| 6174 | { |
| 6175 | send_blob(status, blob, 0, NULL); |
| 6176 | } |
| 6177 | if ((ULONG) segment_length + 2 > blob->rbl_buffer_length) |
| 6178 | { |
| 6179 | send_blob(status, blob, segment_length, segmentPtr); |
| 6180 | return; |
| 6181 | } |
| 6182 | p = blob->rbl_buffer; |
| 6183 | } |
no test coverage detected