Comments (6)
I guess you can use something like this:
diff --git a/examples/echo.c b/examples/echo.c
index ed1d532..6b52647 100644
--- a/examples/echo.c
+++ b/examples/echo.c
@@ -284,15 +284,37 @@ static int run_loop(int fd, quicly_conn_t *client)
return 0;
}
+typedef struct {
+ quicly_stream_open_t stream_open;
+ void *user_ctx;
+} custom_quicly_stream_open_t;
+
+typedef struct {
+ quicly_streambuf_t sb;
+ void *user_ctx;
+} custom_quicly_streambuf_t;
+
static int on_stream_open(quicly_stream_open_t *self, quicly_stream_t *stream)
{
+ custom_quicly_stream_open_t *real_self = (custom_quicly_stream_open_t *)self;
+
static const quicly_stream_callbacks_t stream_callbacks = {
quicly_streambuf_destroy, quicly_streambuf_egress_shift, quicly_streambuf_egress_emit, on_stop_sending, on_receive,
on_receive_reset};
int ret;
- if ((ret = quicly_streambuf_create(stream, sizeof(quicly_streambuf_t))) != 0)
+ // real_self->user_ctx is your custom context.
+
+ if ((ret = quicly_streambuf_create(stream, sizeof(custom_quicly_streambuf_t))) != 0)
return ret;
+
+ custom_quicly_streambuf_t *custom_sbuf = stream->data;
+ custom_sbuf->user_ctx = real_self->user_ctx;
+
+ // In callbacks that get "stream" as an argument:
+ // custom_quicly_streambuf_t *custom_sbuf = stream->data;
+ // and use custom_sbuf->user_ctx
+
stream->callbacks = &stream_callbacks;
return 0;
}
@@ -306,7 +328,7 @@ int main(int argc, char **argv)
.key_exchanges = ptls_openssl_key_exchanges,
.cipher_suites = ptls_openssl_cipher_suites,
};
- quicly_stream_open_t stream_open = {on_stream_open};
+ custom_quicly_stream_open_t stream_open = {{on_stream_open}, NULL /* your context here */};
char *host = "127.0.0.1", *port = "4433";
struct sockaddr_storage sa;
socklen_t salen;
@@ -316,7 +338,7 @@ int main(int argc, char **argv)
ctx = quicly_default_context;
ctx.tls = &tlsctx;
quicly_amend_ptls_context(ctx.tls);
- ctx.stream_open = &stream_open;
+ ctx.stream_open = (quicly_stream_open_t *) &stream_open;
/* resolve command line options and arguments */
while ((ch = getopt(argc, argv, "c:k:p:Eh")) != -1) {
from quicly.
Like this:
--- a/examples/echo.c
+++ b/examples/echo.c
@@ -132,6 +132,9 @@ static int on_receive_reset(quicly_stream_t *stream, int err)
static int on_receive(quicly_stream_t *stream, size_t off, const void *src, size_t len)
{
+ custom_quicly_streambuf_t *custom_sbuf = stream->data;
+ // User ctx is in custom_sbuf->user_ctx
+
int ret;
/* read input to receive buffer */
@@ -284,15 +287,37 @@ static int run_loop(int fd, quicly_conn_t *client)
return 0;
}
from quicly.
Hi,
thanks for your quick reply! This was the kind of quick-fix I already cam up with. The problem is that the self-ptr you are using to get the state into the callback does not exist in the on_receive
function.. What do you suggest I do in that case?
from quicly.
But you have "stream" in on receive, don't you? Then you can use the trick with custom_quicly_streambuf_t that I showed...
from quicly.
As @stablebits says, the expected way of associating user data to a stream is by using quicly_stream_t::data
.
In on_stream_open
, you can use to quicly_stream_t::conn
to obtain a pointer to quicly_conn_t *
, then use quicly_get_data(quicly_conn_t *conn)
to access user data associated to the connection.
from quicly.
Thank you! I must have missed that, while going through the examples.
from quicly.
Related Issues (20)
- QUIC version HOT 2
- Disable encryption HOT 1
- ping-pong of STREAM_DATA_BLOCKED and MAX_STREAM_DATA
- Quicly library encapsulates Datagram
- Client generates CONNECTION_ID_LIMIT_ERROR if ACTIVE_CONNECTION_ID_LIMIT is hit HOT 4
- Store preferred_address.connection_id like any other new connection ID
- Quicly in non-http3 applications
- Warning variable 'is_late_ack' set but not used
- Assertion in 'do_send' (quicly.c) HOT 2
- BUG: Unknown Frame wrongly returned error code HOT 2
- BUG: Receipt of NEW_TOKEN by a server is not handled correctly HOT 3
- Queries regarding Encryption Offload API
- The "new unidirectional limit 0 decreases the current limit: 3" error HOT 1
- Decryption Offload: Connection ID(cid) encryption/decryption
- Generating qlog files when using quicly as a library
- Support for layer 2 Raw Sockets
- The example-echo sometimes not work when run on the same host
- datagram TP must be remembered
- Assertion `s != -1' failed
- Whether there are plans to support FEC or mutipath HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quicly.