mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 20:38:22 +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);
|
luaL_addlstring(&b, part, size);
|
||||||
/* receive new patterns */
|
/* receive new patterns */
|
||||||
if (!lua_isnumber(L, 2)) {
|
if (!lua_isnumber(L, 2)) {
|
||||||
const char *p= luaL_optstring(L, 2, "*l");
|
const char *p = luaL_optstring(L, 2, "l");
|
||||||
if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b);
|
if (*p == '*') p++; /* skip optional '*' (for compatibility) */
|
||||||
else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b);
|
switch (*p) {
|
||||||
else luaL_argcheck(L, 0, 2, "invalid receive pattern");
|
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
|
/* get a fixed number of bytes (minus what was already partially
|
||||||
* received) */
|
* received) */
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user