Skip to content

Commit 1ee18ed

Browse files
committed
A workaround for Bug#1182474
1 parent e888432 commit 1ee18ed

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/tarantool.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,26 @@ io_buf_recv_yaml(php_stream *stream, struct io_buf *buf)
18991899
return true;
19001900
}
19011901

1902+
/*
1903+
* php_stream_read made right
1904+
* See https://bugs.launchpad.net/tarantool/+bug/1182474
1905+
*/
1906+
static size_t
1907+
php_stream_read_real(php_stream * stream, char *buf, size_t size)
1908+
{
1909+
size_t total_size = 0;
1910+
while (total_size < size) {
1911+
size_t read_size = php_stream_read(stream, buf + total_size,
1912+
size - total_size);
1913+
assert (read_size <= size - total_size);
1914+
if (read_size == 0)
1915+
return total_size;
1916+
total_size += read_size;
1917+
}
1918+
1919+
return total_size;
1920+
}
1921+
19021922
static bool
19031923
io_buf_send_iproto(php_stream *stream, int32_t type, int32_t request_id, struct io_buf *buf)
19041924
{
@@ -1939,7 +1959,7 @@ io_buf_recv_iproto(php_stream *stream, struct io_buf *buf)
19391959
/* receiving header */
19401960
struct iproto_header header;
19411961
size_t length = sizeof(struct iproto_header);
1942-
if (php_stream_read(stream, (char *) &header, length) != length) {
1962+
if (php_stream_read_real(stream, (char *) &header, length) != length) {
19431963
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
19441964
"failed to receive response: eof when "
19451965
"reading iproto header");
@@ -1949,7 +1969,7 @@ io_buf_recv_iproto(php_stream *stream, struct io_buf *buf)
19491969
/* receiving body */
19501970
if (!io_buf_resize(buf, header.length))
19511971
return false;
1952-
if (php_stream_read(stream, buf->value, buf->size) != buf->size) {
1972+
if (php_stream_read_real(stream, buf->value, buf->size) != buf->size) {
19531973
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_DC,
19541974
"failed to receive response: eof when "
19551975
"reading response body");

0 commit comments

Comments
 (0)