diff options
Diffstat (limited to 'src/pgm_sender.cpp')
-rw-r--r-- | src/pgm_sender.cpp | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/src/pgm_sender.cpp b/src/pgm_sender.cpp index d8d77b9..9c2a961 100644 --- a/src/pgm_sender.cpp +++ b/src/pgm_sender.cpp @@ -60,25 +60,6 @@ int xs::pgm_sender_t::init (bool udp_encapsulation_, const char *network_) out_buffer_size = pgm_socket.get_max_tsdu_size (); out_buffer = (unsigned char*) malloc (out_buffer_size); alloc_assert (out_buffer); - encode_buffer = out_buffer; - encode_buffer_size = out_buffer_size; - header_size = 0; - - // If not using a legacy protocol, fill in our datagram header and reserve - // space for it in the datagram. - if (!options.legacy_protocol) { - sp_get_header (out_buffer, options.sp_service, options.sp_pattern, - options.sp_version, options.sp_role); - encode_buffer += SP_HEADER_LENGTH; - encode_buffer_size -= SP_HEADER_LENGTH; - header_size += SP_HEADER_LENGTH; - } - - // Reserve space in the datagram for the offset of the first message. - offset_p = encode_buffer; - encode_buffer += sizeof (uint16_t); - encode_buffer_size -= sizeof (uint16_t); - header_size += sizeof (uint16_t); return rc; } @@ -175,25 +156,27 @@ void xs::pgm_sender_t::in_event (fd_t fd_) void xs::pgm_sender_t::out_event (fd_t fd_) { - // POLLOUT event from send socket. If write buffer is empty (which means - // that the last write succeeded), try to read new data from the encoder. + // POLLOUT event from send socket. If write buffer is empty, + // try to read new data from the encoder. if (write_size == 0) { - // Pass our own buffer to the get_data () function to prevent it from - // returning its own buffer. + // First two bytes (sizeof uint16_t) are used to store message + // offset in following steps. Note that by passing our buffer to + // the get data function we prevent it from returning its own buffer. + unsigned char *bf = out_buffer + sizeof (uint16_t); + size_t bfsz = out_buffer_size - sizeof (uint16_t); int offset = -1; - size_t data_size = encode_buffer_size; - encoder.get_data (&encode_buffer, &data_size, &offset); + encoder.get_data (&bf, &bfsz, &offset); // If there are no data to write stop polling for output. - if (!data_size) { + if (!bfsz) { reset_pollout (handle); return; } // Put offset information in the buffer. - write_size = header_size + data_size; - put_uint16 (offset_p, offset == -1 ? 0xffff : (uint16_t) offset); + write_size = bfsz + sizeof (uint16_t); + put_uint16 (out_buffer, offset == -1 ? 0xffff : (uint16_t) offset); } if (tx_timer) { |