Skip to content

Instantly share code, notes, and snippets.

@indutny
Created June 27, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indutny/98d4d02564094090f888 to your computer and use it in GitHub Desktop.
Save indutny/98d4d02564094090f888 to your computer and use it in GitHub Desktop.
uv_stream_t* s;
uv_pipeline_t p1 = {
.alloc_cb = int(uv_stream_t* s, uv_pipeline_t*, size_t size, uv_buf_t* buf) {
},
.read_cb = int(uv_stream_t* s, uv_pipeline_t* p, uv_buf_t* buf) {
// The point here is that you could call it in a later tick, thus
// the next pipeline couldn't be provided as an argument to this function
uv_pipeline_t* next = uv_stream_next_pipeline(s, &p);
next->alloc_cb(...);
next->read_cb(...);
},
.write_cb = int(uv_stream_t* s, uv_pipeline_t*, uv_buf_t* bufs, unsigned int buf_cnt) {
next->write_cb(...);
},
.shutdown_cb = int(uv_stream_t* s, uv_pipeline_t*) {
next->shutdown_cb(...);
},
.close_cb = int(uv_stream_t* s, uv_pipeline_t*) {
next->close_cb(...);
}
};
uv_pipeline_t p2 = {
.alloc_cb = ...,
.read_cb = ...,
.write_cb = ...,
// These could be NULL, meaning that this pipeline will affect only
// alloc/read/write
.shutdown_cb = NULL
.close_cb = NULL
};
// Append new pipeline to the
uv_stream_pipeline(s, &p1);
uv_stream_pipeline_before(s, &p1, &p2);
// uv_stream_pipeline_after(s, &p1, &p2);
@indutny
Copy link
Author

indutny commented Jun 27, 2014

@saghul: let's iterate over it a bit and post on a mailing list to gather more feedback.

@piscisaureus
Copy link

@indutny Who calls read_cb, write_cb etc? And who calls alloc_cb?

I would suggest to make a "filter" stream. The filter knows what it's upstream stream (or another filter) is.
In response to the user calling uv_read(filter) the filter calls uv_read(upstream). And vice versa for writes. Is that your intention here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment