mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 12:08:21 +01:00
TCP Receive without *
The TCP Receive code now uses a switch statement and allows dropping the * at the start of the string, like Lua's io library
This commit is contained in:
parent
733af884f1
commit
c27c23074c
16
src/buffer.c
16
src/buffer.c
@ -114,10 +114,18 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
||||
luaL_addlstring(&b, part, size);
|
||||
/* receive new patterns */
|
||||
if (!lua_isnumber(L, 2)) {
|
||||
const char *p= luaL_optstring(L, 2, "*l");
|
||||
if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b);
|
||||
else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b);
|
||||
else luaL_argcheck(L, 0, 2, "invalid receive pattern");
|
||||
const char *p = luaL_optstring(L, 2, "l");
|
||||
if (*p == '*') p++; /* skip optional '*' (for compatibility) */
|
||||
switch (*p) {
|
||||
case 'l': /* line */
|
||||
err = recvline(buf, &b);
|
||||
break;
|
||||
case 'a': /* all */
|
||||
err = recvall(buf, &b);
|
||||
break;
|
||||
default:
|
||||
luaL_argcheck(L, 0, 2, "invalid receive pattern");
|
||||
}
|
||||
/* get a fixed number of bytes (minus what was already partially
|
||||
* received) */
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user