-
Notifications
You must be signed in to change notification settings - Fork 45
Add senddata(luadata) & receivedata #330
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
base: master
Are you sure you want to change the base?
Conversation
08d3ffd to
1cb07fa
Compare
256df79 to
3e45962
Compare
a0f46d6 to
4bcb6e6
Compare
90c2ea5 to
44f99db
Compare
lib/luadata.h
Outdated
| return (void *)(data->ptr + offset); | ||
| } | ||
|
|
||
| static inline void *luadata_checkrange(lua_State *L, int idata, int ioffset, int ilen, size_t *len_out) |
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.
I think we should pass just one index on the stack and assume them sequential.. like a CFunction..
| module_exit(luadata_exit); | ||
| MODULE_LICENSE("Dual MIT/GPL"); | ||
| MODULE_AUTHOR("Lourival Vieira Neto <lourival.neto@ring-0.io>"); | ||
|
|
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.
will fix
lib/luadata.h
Outdated
| return (void *)(data->ptr + offset); | ||
| } | ||
|
|
||
| static inline void *luadata_checkrange(lua_State *L, int idata, int ioffset, int ilen, size_t *len_out) |
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.
I'm not fond of calling this function checkrange because it's too similar to checkbounds.. I would call it something like checkpointer (if we can't figure a better name)
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.
getrange..How does it sound?
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.
I think it should be check* to be clear it can raise an error and validate the args..
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.
checkbuffer will do as well.. I think.. couldn't figure anything better.. heh
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.
checkbuffer works for me. Sounds good 👍
lib/luasocket.c
Outdated
| vec.iov_base = (void *)luaL_buffinitsize(L, &B, len); | ||
| } | ||
| else { | ||
| data = luadata_check(L, 2); |
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.
you don't need this line anymore, right?
lib/luadata.h
Outdated
| return (void *)(data->ptr + offset); | ||
| } | ||
|
|
||
| static inline void *luadata_checkrange(lua_State *L, int idata, int ioffset, int ilen, size_t *len_out) |
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.
I don't think we need this need to be an inline.. I would have a regular function and export its prototype here, keeping the struct and checkbounds on the .c file
lib/luasocket.c
Outdated
|
|
||
| vec.iov_base = (void *)luaL_buffinitsize(L, &B, len); | ||
| vec.iov_len = len; | ||
| if (t2 != LUA_TUSERDATA && t2 != LUA_TLIGHTUSERDATA) { |
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.
that's weird.. why that?
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.
will fix it, i thought( if not data) use string, else data. will make it similar like send function
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.
but why checking for light userdata? I would just use the same pattern you used on send() indeed..
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.
then, you can use type the type as a flag to take the decision later on to pushbuffer
lib/luasocket.c
Outdated
| flags = luaL_optinteger(L, ixopt, 0); | ||
| from = lua_toboolean(L, ixopt + 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.
as we are using C99, let's declare these vars in-here..
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.
.. removing their declaration from the beginning of the function block
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.
I thought we were following C89, so i made the early declerations. Will fix it up
93a333a to
401e160
Compare
| #define LUADATA_OPT_FREE 0x02 | ||
| #define LUADATA_OPT_KEEP 0x80 | ||
|
|
||
|
|
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.
please review your patch regarding things like this..
add senddata, receivedata methods that operate directly on luadata buffer memory without Lua string copies.