[ccan] ccan: the psuedo "networking" module.

Allan Ference f.fallen45 at gmail.com
Sat Dec 8 07:27:01 EST 2012


On Fri, Dec 7, 2012 at 8:25 PM, Allan Ference <f.fallen45 at gmail.com> wrote:

>
>
> On Fri, Dec 7, 2012 at 8:09 PM, Allan Ference <f.fallen45 at gmail.com>wrote:
>
>> Hey rusty,
>>
>> Sorry for yestarday's email, I was drunk and somewhat clicked send when
>> it's incomplete...
>>
>> So here's the idea:
>>
>>        struct io_service {
>>                 struct sock_events *sevents;
>>        };
>>
>>        /* ... your functions, new_listener() and so on */
>>        /* Creates a thread */
>>        void start_service(struct io_service *service);
>>        /* Blocks until all polling is done.  */
>>        void run_service(struct io_service *service);
>>
>>
>> You then would call some functions like:
>>          add_listener(&my_io_service, host, port, ...);
>>
>> Then on main():
>>         for (int i = 0; i < nthreads; i++)
>>               start_service(&my_io_service);
>>         run_service(&my_io_service);
>>
>> Or we could hide the implementation of io_service in the source file and
>> work with that.
>>
>> Lemme know what you think
>>
>> Thanks!
>> Allan
>>
>
> Well, missed something, we could also make just 1 function instead of 2
> for the service,
>
>        pthread_t threads[2];
>        for (int i = 0; i < 2; i++)
>              if (pthread_create(&threads[i], NULL, &run_service,
> &my_io_service) != 0)
>                    abort();
>         for (int i = 0; i < 2; i++)
>               pthread_join(&threads[i], NULL);
>
> Allan
>
Re-sending to list. >_>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/ccan/attachments/20121207/b7cbe935/attachment.html>


More information about the ccan mailing list