Skip to content

Commit 19afd53

Browse files
authored
[src] tcp-server: fix bug when tcp server recieves odd number of bytes. See (kaldi-asr#4034)
discussion https://groups.google.com/forum/#!topic/kaldi-help/I3go0qKgDp8/discussion for details
1 parent 0185c4a commit 19afd53

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/online2bin/online2-tcp-nnet3-decode-faster.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ bool TcpServer::ReadChunk(size_t len) {
423423

424424
ssize_t ret;
425425
int poll_ret;
426-
size_t to_read = len;
426+
char *samp_buf_p = reinterpret_cast<char *>(samp_buf_);
427+
size_t to_read = len * sizeof(int16);
427428
has_read_ = 0;
428429
while (to_read > 0) {
429430
poll_ret = poll(client_set_, 1, read_timeout_);
@@ -435,14 +436,15 @@ bool TcpServer::ReadChunk(size_t len) {
435436
KALDI_WARN << "Socket error! Disconnecting...";
436437
break;
437438
}
438-
ret = read(client_desc_, static_cast<void *>(samp_buf_ + has_read_), to_read * sizeof(int16));
439+
ret = read(client_desc_, static_cast<void *>(samp_buf_p + has_read_), to_read);
439440
if (ret <= 0) {
440441
KALDI_WARN << "Stream over...";
441442
break;
442443
}
443-
to_read -= ret / sizeof(int16);
444-
has_read_ += ret / sizeof(int16);
444+
to_read -= ret;
445+
has_read_ += ret;
445446
}
447+
has_read_ /= sizeof(int16);
446448

447449
return has_read_ > 0;
448450
}

0 commit comments

Comments
 (0)