On Mon, Nov 6, 2017 at 7:56 PM, Russell Haley <[email protected]> wrote: > Hello, > > I'm new to C patterns and I am experimenting with libuv to write a > simulator. The idea is to create a context struct to be passed around as a > pointer/handle to various timed and event based callback functions. I would > like this simulator to have a "heartbeat" that sends UDP every x period, as > well as respond to UDP messages received on a different port. I would like > the system to decides at runtime if there are flags in the context that > block it from sending (i.e. handle->send=0;). > > For bonus points, I would like to be able to start a TCP based module if I > receive a certain message on the UDP receive port and then stop it once the > routine completes. I am hoping I can just drop a routine on the default loop > (from within my uv_udp_recv_cb) for processing until completion which would > be signaled in a TCP callback (haven't delved into the TCP stuff yet...). > > After about 1 hour of searching I haven't found any examples of what I am > trying to do. Most of the example patterns are very simplistic. This dearth > of information leads me to one of two conclusions: 1) I am trying to do > something the wrong way or 2) nobody in the entirety of using libuv has ever > ever ever tried to do what I am attempting now. I assume the problem is the > former. ;) > > What I have so far: > > - An example udp listener from the docs. It listens faithfully on the port I > assign. > - A udp client, again from the docs. My first kick simply sends a message > and then exists . My next planned attempt was to use a timer to send the > information repeatedly. I have realized that the timer callback needs to > have my context handle, which prompted this question. I will finish my > example code and then post it here while awaiting a possible answer. > > Please let me know if I can provide some more background (context? tee hee). > > Regards, > > Russ
It's not entirely clear to me what you want to accomplish but if you want to attach state/context to a handle or request, you can use the handle->data and req->data fields. or embed them in another struct and use container_of() to look up the embedder. You can find a container_of() definition in the libuv sources. -- 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 https://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
