예제 #1
0
/** Add some data to the end of the header buffer.
 *
 * \warning This function tries to acquire the lock on the header data, and
 * releases it when done.
 *
 * \param instance BufferedWriter handle
 * \param data Pointer to data to add
 * \param size size of data
 * \return 1 if success, 0 otherwise
 *
 * \see _bw_push_meta
 */
int
bw_push_meta(BufferedWriter* instance, uint8_t* data, size_t size)
{
  int result = 0;
  BufferedWriter* self = (BufferedWriter*)instance;
  if (oml_lock(&self->meta_lock, __FUNCTION__) == 0) {
    result = _bw_push_meta(instance, data, size);
    oml_unlock(&self->meta_lock, __FUNCTION__);
  }
  return result;
}
예제 #2
0
/** Function called after all items in a tuple have been sent
 * \see oml_writer_row_end
 *
 * This releases the lock on the BufferedWriter.
 *
 * \see BufferedWriter, bw_unlock_buf, marshal_finalize
 */
static int
owb_row_end(OmlWriter* writer, OmlMStream* ms) {
  (void)ms;
  OmlBinWriter* self = (OmlBinWriter*)writer;
  MBuffer* mbuf;
  if ((mbuf = self->mbuf) == NULL) {
    return 0; /* previous use of mbuf failed */
  }

  marshal_finalize(self->mbuf);
  if (marshal_get_msgtype (self->mbuf) == OMB_LDATA_P) {
    self->msgtype = OMB_LDATA_P; // Generate long packets from now on.
  }

  if (0 == ms->index) {
    /* This is schema0, also push the data into the meta_buf
     * to be replayed after a disconnection.
     *
     * At the moment, the oml_outs_write_f takes header information as a
     * whole, but does not push more once it has sent the initial block. Its
     * two last parameters are only used to resend the entirety of the headers
     * when a disconnection does occur, nothing before.
     *
     * We therefore send the extra piece of data the normal way, but also
     * record it, separately, in the meta_buf
     *
     * XXX: This logic should be in higher layer levels, but given the current
     * implementation, with some of it already spread down into the
     * OmlOutStream (oml_outs_write_f), this require a much bigger refactoring.
     * It is also duplicated with the OmlTextWriter (see #1101).
     */
    _bw_push_meta(self->bufferedWriter,
        mbuf_message(self->mbuf), mbuf_message_length(self->mbuf));
  }

  mbuf_begin_write(mbuf);

  self->mbuf = NULL;
  bw_unlock_buf(self->bufferedWriter);
  return 1;
}