[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua and networking - possibly basic question
- From: Steve Kemp <steve@...>
- Date: Wed, 26 Oct 2005 16:39:42 +0100
I've been embedding Lua 5.0 into a lot of local applications
recently and find it very nice to work with.
For some software I'm working with I'm looking to add basic
networking facilities, similar to the primitives people
are used to :
connect
read
write
(I have no need for the bind() or accept() primitives.)
I'm comfortable with binding C/C++ functions to Lua and
working with the language nicely. Currently my problem
is a lack of direct mapping between Lua types and C types.
The standard network read() call, essentially, works like this:
read( socket, buffer, bufferLength );
This doesn't fit in nicely with Lua's string objects which
is the most obvious fit on the Lua side.
So I'm struggling to understand how to approach implementation
I want to allow users to be able to do:
socket = connect( "host", port );
send( socket, "GET / HTTP/1.0\n\n" );
header = read( socket );
data = read( socket );
close( socket );
Clearly there is a failure here. I can implement C/C++ reading
function as:
void readDataUntilTerminator( socket, terminator )
{
char *data = NULL
while( read ( .. ) )
{
data = realloc( new Size );
if ( data contains termintor )
return;
}
}
This would allow callers to say "read until the expected response
occurs" - however it leaves a nasty DOS condition if the expected
result fails to occur.
How do other people approach this problem? (In composing this
mail I did a few searchs and see the existance of LuaSocket - this
might help me, if I can embed it within my code. Too soon to tell,
but my natural reaction is to think that is overkill ...)
Steve
--
http://www.steve.org.uk/