I want to build a data publish server with libuv.

   1. It receives data from single/multiple *data source* in tcp.
   2. It publish these data to multiple endpoint in tcp.

At first , I write code like this:

   1. Start N threads, N = number or logical processor online
   2. Each thread maintains a uv_loop * use uv_loop_new, and run it's 
   uv_loop with uv_run. Then other threads can get this N uv_loop* .
   3. Write uv_listen like example of libuv. 
   4. In connection callback, create a uv_tcp_t * handle, pass this handle 
   to a *worker thread* with a thread safe queue.
   5. In *worker thread*,  use queue or other ways to acquire data from 
   data source, and pass this data to each connection handle with uv_write.

But I know it‘s not right way to use libuv, so i rewrite my codes(assume 
there is one data source only)

   1.  Create uv_loop*, uv_tcp_t*, call uv_listen, uv_run in main thread, 
   Just like what example do.
   2. In connection callback, I call  function *write_data*
   3. In *write_data*, acquire message from a ring buffer, call uv_write to 
   transfer data to endpoint. At the end of function, call *write_data *
   again.

this ring buffer hold fixed number of messages, when an connection build, 
it get latest data from ring buffer and it's seqnum.

I don't know if a describe it clearly or not. Briefly, I try to write a tcp 
data publish server .

Thanks for reading this tremble post.


On Monday, June 23, 2014 11:40:55 PM UTC+8, Saúl Ibarra Corretgé wrote:
>
> -----BEGIN PGP SIGNED MESSAGE----- 
> Hash: SHA1 
>
> On 06/23/2014 05:25 PM, ymonster . wrote: 
> > I wonder that you can't pass uv_tcp_t pointer to any other 
> > threads, cause it's not safe. 
>
> A TCP handle is attached to a loop. If you want you can 'send' a 
> handle to another loop using uv_write2. 
>
> > As describe by others, it's like an active object if i am right? 
> > Handle an income connect and receive some message, pass these 
> > messages to worker thread and process async-ly. when it's done post 
> > message to thread running uv_loop? 
>
> Can you rephrase? 
>
> > If i want build a *data publish server*, maybe i should use some 
> > data structure like ring buffer to get message for each connection 
> > and *call uv_write recursivelly*? 
> > 
>
> Not sure what you mean here either. Also, why do you need multiple 
> threads? 
>
> - -- 
> Saúl Ibarra Corretgé 
> bettercallsaghul.com 
>
> -----BEGIN PGP SIGNATURE----- 
> Version: GnuPG v1 
> Comment: Using GnuPG with Icedove - http://www.enigmail.net/ 
>
> iQIcBAEBAgAGBQJTqEpHAAoJEEEOVVOum8BZBHMP/1gqYyNbKXBGEqXbdCP2u66k 
> Gmsorot/qsd3ZpUEs4o1xKcsw9tsICZmi2/yJZFDiH7XTF0xjopk8GVzxrUA7PEE 
> 2GfOdppJpl6Lgu4tt/EZFtCRBAPzpXce8YAk83w8WzgmkKuIB9/C64QAJXL3TAXM 
> +WCYLguX+J2sZ83y4Ua2TNLcmZMNxPShFZUORq4IaeZKAWbElz5fiwZp7KF+zINP 
> Yo4F4G6h9rMy5ja9nscYiSXSkAsoZ1jR40OxTGjdT3rf39avo3haUEwbbT6K+0zx 
> Cj/auwa46QzF1qFMlVXkDuYi5xSLR0a8AYOkJ1R6+ViBlYyEuFhjSpQXsd1BKMwD 
> WkuOIXlbJYnK8LtqfSxFP4ZI0jE39IWUU6BgPV8OiBJNle82VzOfmsNmCU5EEElJ 
> 4a7fgYKMyFYYZrFDqLOMbHjBCSfFiCROaCQ0iW8RsifbvVVfIRKFITDFEGO1fXsT 
> V1VMtT4R8B4xKG9aEKpR7FjEZPMJ62KUGmptE7GD6q8IqfTKhLjQFGqssuQjRjnm 
> r09KkaTx1hat0Qz0oisUwQqGpB5uK7Y/MuuQKnpFpHhXOv0+d3cUskxMNGEYLVV0 
> R5GCJigIbk6HaymS8BWupw8UDp5IvoDml+W0AvwA5trOoB8SzyaQMJHy7yz71TR2 
> tB7ydF48vOLERWJDS8v0 
> =0Z2r 
> -----END PGP SIGNATURE----- 
>

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to