MCPcopy Create free account
hub / github.com/Tencent/UnLua / recvline

Function recvline

Plugins/UnLuaExtensions/LuaSocket/Source/src/buffer.cpp:225–243  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Reads a line terminated by a CR LF pair or just by a LF. The CR and LF * are not returned by the function and are discarded from the buffer \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

223* are not returned by the function and are discarded from the buffer
224\*-------------------------------------------------------------------------*/
225static int recvline(p_buffer buf, luaL_Buffer *b) {
226 int err = IO_DONE;
227 while (err == IO_DONE) {
228 size_t count, pos; const char *data;
229 err = buffer_get(buf, &data, &count);
230 pos = 0;
231 while (pos < count && data[pos] != '\n') {
232 /* we ignore all \r's */
233 if (data[pos] != '\r') luaL_addchar(b, data[pos]);
234 pos++;
235 }
236 if (pos < count) { /* found '\n' */
237 buffer_skip(buf, pos+1); /* skip '\n' too */
238 break; /* we are done */
239 } else /* reached the end of the buffer */
240 buffer_skip(buf, pos);
241 }
242 return err;
243}
244
245/*-------------------------------------------------------------------------*\
246* Skips a given number of bytes from read buffer. No data is read from the

Callers 1

buffer_meth_receiveFunction · 0.85

Calls 2

buffer_getFunction · 0.85
buffer_skipFunction · 0.85

Tested by

no test coverage detected