[ccan] Networking: Asynchronous Server+Client socket code

Ahmed Samy f.fallen45 at gmail.com
Sun Nov 4 16:54:25 EST 2012


On Sat, Nov 3, 2012 at 7:03 AM, Ahmed Samy <f.fallen45 at gmail.com> wrote:

>
>
> On Sat, Nov 3, 2012 at 5:44 AM, Ahmed Samy <f.fallen45 at gmail.com> wrote:
>
>> Hi,
>>
>> This is a lightweight networking code that I'd like to add in The ccan
>> tree.
>> Reading the code should be straight forward, it uses epoll etc, and has
>> support for callbacks, it can be used a server or a client with 3 simple
>> calls:
>>
>>
>>
>>
>>     struct socket_t *sock = socket_create();
>>
>>
>>     if (!socket_listen(sock, NULL, 1337))
>>
>>
>>         fatal("failed to listen on port 1337.");
>>
>>
>>
>>     /*
>>      * callbacks should be setup before polling on the socket
>>
>>
>>
>>      */
>>     socket_poll(sock);
>>
>>
>>
>> For client side, replace socket_listen with socket_connect.
>> The code can be viewed at: at:
>> https://github.com/otfallen/csnippets/blob/master/src/socket.c (to view
>> the header change '.c' to '.h')
>>
>> Please leave any kind of feedback.
>>
>> Thanks
>>       asamy
>>
> Btw, the tests I used can be found at:
> https://github.com/otfallen/csnippets/blob/master/src/tests.c
> Also, I sent this message for a discussion, i.e what code can be improved
> etc etc.  So, after the code is as-wanted, I'll upload patch(es) with ccan
> coding style and so on.
>
Hi,

The code is now portable to other interfaces, I've added an optional select
interface instead of epoll.
See socket_select.c and socket_epoll.c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20121104/3dde0344/attachment.html>


More information about the ccan mailing list