intel / liblwm2m

liblwm2m is an implementation of the LWM2M protocol from the Open Mobile Alliance.
BSD 3-Clause "New" or "Revised" License
44 stars 28 forks source link

Remove all network I/O from core #11

Closed tobyjaffey closed 10 years ago

tobyjaffey commented 10 years ago

Currently, liblwm2m has the bulk of the network I/O in the application (select loop, socket creation, packet receive). But, DNS and packet transmission are still handled by the core.

These patches remove the remaining network functions from the core and remove the reliance on BSD socket headers.

The core handles three opaque variables for each connection: int socket, an identifier for the transport, never dereferenced by core uint8_t *addr + size_t addrLen, an opaque buffer used by the the application to identify a destination (this could be a struct sockaddr/socklen pair, or something entirely different like a telephone number for SMS).

Hopefully, it will now be easier to use liblwm2m on embedded targets without BSD sockets and to bind to high level languages which want to handle socket juggling themselves.

Adding DTLS between core and the network layer may be more straighforward also.

jvermillard commented 10 years ago

very nice PR! Looks good to me.

BTW do you tried to port on non linux target? no troubles with timer and mallocs?

tobyjaffey commented 10 years ago

I made these changes to help let me bind liblwm2m to Javascript (V8, node.js) but keep the socket handling and main loop in node.

It shouldn't be hard to port to non-linux, but I haven't tried yet. There's not much use of malloc, so static buffers may be an option. It'd be fun to try it out on an embedded ARM target with uIP.

dnav commented 10 years ago

Hi Toby,

Thanks for this contribution. It is indeed very nice and going in the right direction. Devil being in the details, I made some comments. Mainly on the use of coap_status_t instead of COAPNNN* error codes already defined in liblwm2m.h and on making the buffer_send_func a mandatory parameter. Ultimately, I plan to have all the networking code and the peer identification out of liblwm2m so it would be completly agnostic on the transport (SMS, UDP or DTLS).

Regards

tobyjaffey commented 10 years ago

Thanks for the comments. I'll tidy up the patch and resubmit, hopefully soon.

tobyjaffey commented 10 years ago

@dnav I think this addresses your comments. I added a COAP_NO_ERROR = 0, because a successful return code of 0 seems natural for POSIX functions.