-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTERNAL: Refactor the memcached_io_read function #341
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -539,7 +539,8 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, | |
} | ||
|
||
char *buffer_ptr= static_cast<char *>(buffer); | ||
while (length) | ||
size_t remains= length; | ||
while (remains) | ||
{ | ||
if (ptr->read_buffer_length == 0) | ||
{ | ||
|
@@ -551,27 +552,30 @@ memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr, | |
return io_fill_ret; | ||
} | ||
} | ||
if (length > 1) | ||
if (remains > 1) | ||
{ | ||
size_t difference= (length > ptr->read_buffer_length) ? ptr->read_buffer_length : length; | ||
memcpy(buffer_ptr, ptr->read_ptr, difference); | ||
|
||
length-= difference; | ||
size_t difference= (remains > ptr->read_buffer_length) ? ptr->read_buffer_length : remains; | ||
if (buffer_ptr) { | ||
memcpy(buffer_ptr, ptr->read_ptr, difference); | ||
buffer_ptr+= difference; | ||
} | ||
ptr->read_ptr+= difference; | ||
ptr->read_buffer_length-= difference; | ||
buffer_ptr+= difference; | ||
remains-= difference; | ||
} | ||
else | ||
{ | ||
*buffer_ptr= *ptr->read_ptr; | ||
if (buffer_ptr) { | ||
*buffer_ptr= *ptr->read_ptr; | ||
buffer_ptr++; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์๋์์ remains--; ์ถ๊ฐํด์ผ ํฉ๋๋ค. |
||
ptr->read_ptr++; | ||
ptr->read_buffer_length--; | ||
buffer_ptr++; | ||
break; | ||
remains--; | ||
} | ||
} | ||
ing-eoking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
*nread = (ssize_t)(buffer_ptr - (char*)buffer); | ||
ing-eoking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*nread = (ssize_t)(length - remains); | ||
|
||
return MEMCACHED_SUCCESS; | ||
} | ||
|
@@ -855,16 +859,16 @@ memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr, | |
ssize_t nread; | ||
memcached_return_t rc; | ||
|
||
while (memcached_continue(rc= memcached_io_read(ptr, data + offset, size - offset, &nread))) { }; | ||
while (memcached_continue(rc= memcached_io_read(ptr, data, size - offset, &nread))) { }; | ||
|
||
if (memcached_failed(rc)) | ||
{ | ||
return rc; | ||
} | ||
|
||
offset+= (size_t) nread; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด๋ ๊ฒ ์์ ํด์ผ ํ๋ ์ด์ ๋ ๋ฌด์์ธ๊ฐ์? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jhpark816 ๊ทธ๋ฆฌ๊ณ ์ด๋ฏธ memcached_io_read์์ while ๋ฌธ์ ํตํด ์ง์ ๋ ๊ธธ์ด๋งํผ ๋ชจ๋ ์ฝ๋ ๊ฒ์ด ๋ณด์ฅ๋๋ฏ๋ก, memcached_safe_read์์๋ while (offset < size) ๋ฌธ์ ๋ ํ์๊ฐ ์์ด ์ ๊ฑฐํ์ต๋๋ค. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
์ด๋ค ์ฝ๋ ๋๋ฌธ์ nread ๊ฐ์ด 0์ด ๋๋์? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์ ๋ด์ฉ์ด ๋ฐ์๋์ง ์์ ๋ค์ ์ฌ๋ ธ์ต๋๋ค.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nread ์ ๋ณด๋ ์ ํํ ์ ๋ฌ๋์ด์ผ ํฉ๋๋ค. nread์๋ค ๊ณ์ ๋ํ๋ ๊ฒ ๋ณด๋ค,
๋ณ์ ๋ช
์ด ์กฐ๊ธ ์ด์ํ๋ค์. ์ด์ ๋ํด ์๊ฒฌ ์ฃผ์ธ์. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
์ ๋ remain ๋๋ left๋ผ๋ ๋ณ์๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌํ๋ ๊ฒ์ด ์์ฐ์ค๋ฌ์ธ ๊ฒ ๊ฐ์ต๋๋ค. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remains ๋ณ์๋ฅผ ์ฌ์ฉํ์์ฃ . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remain์ผ๋ก ๋จผ์ ๋ฐ๊ฟ์ remains๋ก ์ฌ๋ณ๊ฒฝํ์ฌ ๋ค์ push ํ์ต๋๋ค. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nread ๊ฐ์ ๋ณ๊ฒฝํ์ผ๋, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. buffer๊ฐ NULL์ผ ๊ฒฝ์ฐ ์๋ชป๋ ๊ณ์ฐ์ด ๋ฐ์ํ๋ฏ๋ก ์ผ๋ถ๋ ์์ ํ๊ฒ ์ต๋๋ค. |
||
if (data) data+= nread; | ||
} | ||
|
||
return MEMCACHED_SUCCESS; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remains > 1 ๊ฒฝ์ฐ๊ฐ remains == 1์ธ ๊ฒฝ์ฐ๋ก ๊ตฌ๋ถ๋์ด ์๋ ๋ฐ,
remains > 1 ๊ฒฝ์ฐ์ ์ฝ๋๋ง ์์ด๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remains > 1์ธ ๊ฒฝ์ฐ์ remains == 1์ ๊ตฌ๋ถํ๊ณ ์๋ ์ด์ ๊ฐ remains > 1์ธ ๊ฒฝ์ฐ memcpy๋ฅผ ์ฐ๊ณ , remains == 1์ธ ๊ฒฝ์ฐ ๋ฑํธ ์ฐ์ฐ์(=)๋ฅผ ์ฐ๋ ค๋ ์๋๋ก ๋ณด์ ๋๋ค.
๋ชจ๋ memcpy๋ก ํต์ผํ ๊น์?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฐ์ ํด๋น ๋ถ๋ถ์ ๊ทธ๋๋ก ๋์์ต๋๋ค.
๋๋จธ์ง ์์ ๋์์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ง๋ฌธ์ ๋๋ค.
remains == 1์ธ ๊ฒฝ์ฐ๊ฐ ๋ง์ ์ ์๋์?
๋ง์ง ์๋ค๋ฉด, ์๋ ์ฝ๋๋ง์ผ๋ก ์ถฉ๋ถํ ๊ฒ ๊ฐ์ต๋๋ค.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ด๋ถ ์ฝ๋์์ length๋ฅผ 1๋ก ๋๊ณ ํธ์ถํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค.
space
,\r
,\n
์ด ๋์ฌ ๋๊น์ง ๋ฐ๋ณตํฉ๋๋ค.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฝ์ด์ผ ํ ๊ธธ์ด๋ ๋ชจ๋ฅด๊ณ ,
๋จ์ง ํน์ ๋ฌธ์(
\n
)๊ฐ ๋์ฌ ๋๊น์ง ์ฝ๊ธฐ ์ํจ์ด๊ตฐ์.๊ทธ๋ฌ๋ฉด, remains == 1 ์ธ ๊ฒฝ์ฐ์ ์ฝ๋๋ฅผ ๊ทธ๋๋ก ์ ์งํ์์ฃ .